Example usage for android.app PendingIntent FLAG_UPDATE_CURRENT

List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_UPDATE_CURRENT.

Prototype

int FLAG_UPDATE_CURRENT

To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.

Click Source Link

Document

Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.

Usage

From source file:com.bhb27.isu.services.BootBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // only run if the app has run before and main has extracted asserts
    String action = intent.getAction();
    boolean run_boot = Tools.getBoolean("run_boot", false, context);
    boolean rootAccess = Tools.rootAccess(context);
    if (Intent.ACTION_BOOT_COMPLETED.equals(action) && rootAccess && run_boot) {
        Log.d(TAG, " Started action " + action + " run_boot " + run_boot);

        if (Tools.getBoolean("prop_run", false, context) && Tools.getBoolean("apply_props", false, context))
            ContextCompat.startForegroundService(context, new Intent(context, PropsService.class));

        ContextCompat.startForegroundService(context, new Intent(context, BootService.class));

        if (Tools.getBoolean("apply_su", false, context) && Tools.SuVersionBool(Tools.SuVersion(context))) {

            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            Intent serviceIntent = new Intent("com.bhb27.isu.services.SuServiceReceiver.RUN");
            serviceIntent.putExtra("RUN", 100);
            serviceIntent.setClass(context, SuServiceReceiver.class);
            serviceIntent.setAction("RUN");

            PendingIntent pi = PendingIntent.getBroadcast(context, 100, serviceIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                    + Integer.valueOf(Tools.readString("apply_su_delay", "0", context)), pi);
        }/* ww  w. j  a  v a  2s  . c o m*/

    } else
        Log.d(TAG, "Not Started action " + action + " rootAccess " + rootAccess + " run_boot " + run_boot);
}

From source file:com.money.manager.ex.sync.SyncSchedulerBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = "";
    // by default, the action is ACTION_START. This is assumed on device boot.

    if (intent != null && !TextUtils.isEmpty(intent.getAction())) {
        action = intent.getAction();//from  w ww.  ja  v  a2  s.com
        Timber.d("Sync scheduler request: %s", action);
    }

    Intent syncIntent = new Intent(context, SyncBroadcastReceiver.class);
    PendingIntent pendingSyncIntent = PendingIntent.getBroadcast(context, SyncConstants.REQUEST_PERIODIC_SYNC,
            syncIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    // PendingIntent.FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT

    AlarmManager alarmManager = getAlarmManager(context);

    // Cancel existing heartbeat.
    if (action.equals(ACTION_STOP)) {
        Timber.d("Stopping synchronization alarm.");

        alarmManager.cancel(pendingSyncIntent);
        return;
    }

    startHeartbeat(context, alarmManager, pendingSyncIntent);
}

From source file:com.ce.skuniv.helpers.Notifications.java

public void displayNotification(String title, String text, boolean Sound, int Id, boolean isPresistant) {
    if (Id == 0) {
        Id = rnd.nextInt();//from w  w  w . ja v a2 s  .  c o  m
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_icon).setContentTitle(title).setContentText(text);
    if (Sound)
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // mBuilder.setOnlyAlertOnce(false);
    mBuilder.setTicker(title + ":" + text);
    mBuilder.setOngoing(isPresistant);
    mBuilder.setAutoCancel(true);

    // Intent notificationIntent = new Intent(context,
    // MainMultiWiiActivity.class);

    Intent notificationIntent = new Intent(context, MainMultiWiiActivity.class);
    // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You
    // need this if starting
    // the activity from a service
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);

    //      mNotificationManager.notify(Id, mBuilder.build());
}

From source file:br.com.virtz.www.cfcmob.MyMessagingService.java

private void sendNotification(int conversationId, String message, String participant, long timestamp) {
    // A pending Intent for reads
    PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId,
            createIntent(conversationId, READ_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);

    // Build a RemoteInput for receiving voice input in a Car Notification
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("Reply by voice").build();

    // Building a Pending Intent for the reply action to trigger
    PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId,
            createIntent(conversationId, REPLY_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the UnreadConversation and populate it with the participant name,
    // read and reply intents.
    UnreadConversation.Builder unreadConvBuilder = new UnreadConversation.Builder(participant)
            .setLatestTimestamp(timestamp).setReadPendingIntent(readPendingIntent)
            .setReplyAction(replyIntent, remoteInput);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
            // Set the application notification icon:
            //.setSmallIcon(R.drawable.notification_icon)

            // Set the large icon, for example a picture of the other recipient of the message
            //.setLargeIcon(personBitmap)

            .setContentText(message).setWhen(timestamp).setContentTitle(participant)
            .setContentIntent(readPendingIntent)
            .extend(new CarExtender().setUnreadConversation(unreadConvBuilder.build()));

    mNotificationManager.notify(conversationId, builder.build());
}

From source file:de.grobox.blitzmail.SendActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // before doing anything show notification about sending process
    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setContentTitle(getString(R.string.sending_mail)).setContentText(getString(R.string.please_wait))
            .setSmallIcon(R.drawable.notification_icon).setOngoing(true);
    // Sets an activity indicator for an operation of indeterminate length
    mBuilder.setProgress(0, 0, true);// www .j  a  v  a 2s.co m
    // Create Pending Intent
    notifyIntent = new Intent(this, NotificationHandlerActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pendingIntent);
    // Issues the notification
    mNotifyManager.notify(0, mBuilder.build());

    Properties prefs;
    try {
        prefs = getPrefs();
    } catch (Exception e) {
        String msg = e.getMessage();

        Log.i("SendActivity", "ERROR: " + msg, e);

        if (e.getClass().getCanonicalName().equals("java.lang.RuntimeException") && e.getCause() != null
                && e.getCause().getClass().getCanonicalName().equals("javax.crypto.BadPaddingException")) {
            msg = getString(R.string.error_decrypt);
        }

        showError(msg);
        return;
    }

    // get and handle Intent
    Intent intent = getIntent();
    String action = intent.getAction();

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (action.equals(Intent.ACTION_SEND)) {
        String text = intent.getStringExtra(Intent.EXTRA_TEXT);
        //String email   = intent.getStringExtra(Intent.EXTRA_EMAIL);
        String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        String cc = intent.getStringExtra(Intent.EXTRA_CC);
        String bcc = intent.getStringExtra(Intent.EXTRA_BCC);

        // Check for empty content
        if (subject == null && text != null) {
            // cut all characters from subject after the 128th
            subject = text.substring(0, (text.length() < 128) ? text.length() : 128);
            // remove line breaks from subject
            subject = subject.replace("\n", " ").replace("\r", " ");
        } else if (subject != null && text == null) {
            text = subject;
        } else if (subject == null && text == null) {
            Log.e("Instant Mail", "Did not send mail, because subject and body empty.");
            showError(getString(R.string.error_no_body_no_subject));
            return;
        }

        // create JSON object with mail information
        mMail = new JSONObject();
        try {
            mMail.put("id", String.valueOf(new Date().getTime()));
            mMail.put("body", text);
            mMail.put("subject", subject);
            mMail.put("cc", cc);
            mMail.put("bcc", bcc);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        // remember mail for later
        MailStorage.saveMail(this, mMail);

        // pass mail on to notification dialog class
        notifyIntent.putExtra("mail", mMail.toString());

        // Start Mail Task
        AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail);
        mail.execute();
    } else if (action.equals("BlitzMailReSend")) {
        try {
            mMail = new JSONObject(intent.getStringExtra("mail"));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        // pass mail on to notification dialog class
        notifyIntent.putExtra("mail", mMail.toString());

        // Start Mail Task
        AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail);
        mail.execute();
    }
    finish();
}

From source file:com.attiqrao.systemsltd.list_to_do.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));

    // Get notification title from Reminder Database
    ReminderDatabase rb = new ReminderDatabase(context);
    Reminder reminder = rb.getReminder(mReceivedID);
    String mTitle = reminder.getTitle();

    // Create intent to open ReminderEditActivity on notification click
    Intent editIntent = new Intent(context, ReminderEditActivity.class);
    editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
    PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Create Notification
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_icon))
            .setSmallIcon(R.mipmap.ic_icon).setContentTitle(context.getResources().getString(R.string.app_name))
            .setTicker(mTitle).setContentText(mTitle)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).setContentIntent(mClick)
            .setAutoCancel(true).setOnlyAlertOnce(true);

    NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nManager.notify(mReceivedID, mBuilder.build());
}

From source file:MainActivity.java

private PendingIntent getGeofencePendingIntent() {
    if (mGeofencePendingIntent != null) {
        return mGeofencePendingIntent;
    }/*from  w  ww  .j  a v  a  2s  .  c  om*/
    Intent intent = new Intent(this, GeofenceIntentService.class);
    return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.andremion.heroes.ui.character.view.CharacterActivity.java

public static PendingIntent getPendingIntent(@NonNull Context context, @NonNull CharacterVO character, int id) {

    Intent intent = new Intent(context, CharacterActivity.class);
    intent.setAction(Integer.toString(id)); // Used to update all PendingIntent extras data for each widget
    intent.putExtra(EXTRA_CHARACTER, character);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntentWithParentStack(intent); // Return to MainActivity

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:cl.chihau.holaauto.MessagingService.java

private void sendNotificationForConversation(int conversationId, String sender, String message,
        long timestamp) {
    // A pending Intent for reads
    PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId,
            getMessageReadIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT);

    /// Add the code to create the UnreadConversation
    // Build a RemoteInput for receiving voice input in a Car Notification
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build();

    // Building a Pending Intent for the reply action to trigger
    PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId,
            getMessageReplyIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the UnreadConversation and populate it with the participant name,
    // read and reply intents.
    NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
            sender).setLatestTimestamp(timestamp).setReadPendingIntent(readPendingIntent)
                    .setReplyAction(replyIntent, remoteInput);

    // Note: Add messages from oldest to newest to the UnreadConversation.Builder
    // Since we are sending a single message here we simply add the message.
    // In a real world application there could be multiple messages which should be ordered
    // and added from oldest to newest.
    unreadConversationBuilder.addMessage(message);

    /// End create UnreadConversation

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.notification_icon)
            .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(),
                    R.drawable.android_contact))
            .setContentText(message).setWhen(timestamp).setContentTitle(sender)
            .setContentIntent(readPendingIntent).setContentIntent(readPendingIntent)
            /// Extend the notification with CarExtender.
            .extend(new NotificationCompat.CarExtender()
                    .setUnreadConversation(unreadConversationBuilder.build()))
    /// End//  w  w w . j  ava  2 s.  c om
    ;

    Log.d(TAG, "Sending notification " + conversationId + " conversation: " + message);

    NotificationManagerCompat.from(this).notify(conversationId, builder.build());
}

From source file:codes.simen.l50notifications.ReminderService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final String action = intent.getAction();
    if (ACTION_REMIND.equals(action)) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        final int reminderDelay = preferences.getInt("reminder_delay", 5000);

        final Bundle extras = intent.getExtras();

        reminders.put(System.currentTimeMillis() + reminderDelay, extras);

        handler.postDelayed(displayReminder, reminderDelay);

        builder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.ic_reminder)
                .setContentTitle(String.format("%d reminders", reminders.size()))
                .setContentText("Tap to cancel all reminders").setOngoing(true)
                .setPriority(NotificationCompat.PRIORITY_MIN)
                .setContentIntent(PendingIntent.getService(getApplicationContext(), 0,
                        new Intent(getApplicationContext(), ReminderService.class).setAction(ACTION_STOP),
                        PendingIntent.FLAG_UPDATE_CURRENT));

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(NOTIFICATION_ID, builder.build());

    } else if (ACTION_STOP.equals(action)) {
        stopSelf();//from   w w w . j av  a 2 s  .  co  m
        Toast.makeText(getApplicationContext(), "All reminders cancelled", Toast.LENGTH_SHORT).show();
    }
    return START_NOT_STICKY;
}