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:net.eledge.android.europeana.gui.notification.receiver.UrlButtonReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    int notificationId = intent.getIntExtra(PARAM_NOTIFICATIONID, Config.NOTIFICATION_NEWBLOG);
    String url = intent.getStringExtra(PARAM_URL);

    if (StringUtils.isNoneBlank(url)) {
        try {//from w  w w  .  j  a  va 2 s  .  c o m
            PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse(url)),
                    PendingIntent.FLAG_UPDATE_CURRENT).send();
        } catch (PendingIntent.CanceledException e) {
            Log.e(UrlButtonReceiver.class.getSimpleName(), e.getMessage(), e);
        }
    }

    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(notificationId);
}

From source file:com.android.deskclock.alarms.AlarmNotifications.java

public static void showLowPriorityNotification(Context context, AlarmInstance instance) {
    LogUtils.v("Displaying low priority notification for alarm instance: " + instance.mId);

    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */))
            .setSmallIcon(R.drawable.stat_notify_alarm).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT).setCategory(NotificationCompat.CATEGORY_ALARM)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true);

    // Setup up hide notification
    Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DELETE_TAG,
            instance, AlarmInstance.HIDE_NOTIFICATION_STATE);
    notification.setDeleteIntent(PendingIntent.getService(context, instance.hashCode(), hideIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE);
    notification.addAction(R.drawable.ic_alarm_off_24dp,
            context.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getService(context,
                    instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    Intent viewAlarmIntent = createViewAlarmIntent(context, instance);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.notify(instance.hashCode(), notification.build());
}

From source file:com.achep.acdisplay.ui.activities.MainActivity.java

private static void sendTestNotification(@NonNull Context context) {
    final int id = App.ID_NOTIFY_TEST;
    final Resources res = context.getResources();

    PendingIntent pendingIntent = PendingIntent.getActivity(context, id,
            new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
            .bigText(res.getString(R.string.notification_test_message_large));
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(res.getString(R.string.app_name))
            .setContentText(res.getString(R.string.notification_test_message)).setContentIntent(pendingIntent)
            .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
            .setSmallIcon(R.drawable.stat_acdisplay).setAutoCancel(true).setStyle(bts)
            .setColor(App.ACCENT_COLOR)/*from  w w  w .  j  ava 2  s .  c o  m*/
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(id, builder.build());
}

From source file:com.android.antitheft.util.AntiTheftNotifier.java

private static NotificationCompat.Builder createBaseContentBuilder(Context context) {
    Intent installIntent = new Intent(context, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 1, installIntent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    return new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent).setLocalOnly(true).setAutoCancel(true);
}

From source file:com.bullmobi.message.ui.activities.MainActivity.java

private static void sendTestNotification(@NonNull Context context) {
    final int id = App.ID_NOTIFY_TEST;
    final Resources res = context.getResources();

    PendingIntent pendingIntent = PendingIntent.getActivity(context, id,
            new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
            .bigText(res.getString(R.string.notification_test_message_large));
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(res.getString(R.string.app_name))
            .setContentText(res.getString(R.string.notification_test_message)).setContentIntent(pendingIntent)
            .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
            .setSmallIcon(R.drawable.stat_easynotification).setAutoCancel(true).setStyle(bts)
            .setColor(App.ACCENT_COLOR)// ww  w.  j a v  a 2 s  .  c  o  m
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(id, builder.build());
}

From source file:com.parse.ParsePushUnityHelper.java

/**
 * A helper method that provides default behavior for handling ParsePushNotificationReceived.
 *///from  w  w w.  j a  v  a  2s . c om
public static void handleParsePushNotificationReceived(Context context, String pushPayloadString) {
    try {
        JSONObject pushData = new JSONObject(pushPayloadString);

        if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) {
            return;
        }

        ManifestInfo info = new ManifestInfo(context);
        String title = pushData.optString("title", info.getDisplayName());
        String alert = pushData.optString("alert", "Notification received.");
        String tickerText = title + ": " + alert;

        Random random = new Random();
        int contentIntentRequestCode = random.nextInt();

        Intent activityIntent = info.getLauncherIntent();
        PendingIntent pContentIntent = PendingIntent.getActivity(context, contentIntentRequestCode,
                activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title)
                .setContentText(alert).setTicker(tickerText).setSmallIcon(info.getPushIconId())
                .setContentIntent(pContentIntent).setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);

        Notification notification = builder.build();
        NotificationManager manager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        int notificationId = (int) System.currentTimeMillis();

        try {
            manager.notify(notificationId, notification);
        } catch (SecurityException se) {
            // Some phones throw exception for unapproved vibration.
            notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;
            manager.notify(notificationId, notification);
        }
    } catch (JSONException e) {
        // Do nothing.
    }
}

From source file:com.bluros.updater.receiver.DownloadNotifier.java

private static NotificationCompat.Builder createBaseContentBuilder(Context context, Intent updateIntent) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 1, updateIntent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    return new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent).setLocalOnly(true).setAutoCancel(true);
}

From source file:com.achep.acdisplay.notifications.NotificationHelper.java

@NonNull
public static Notification buildNotification(@NonNull Context context, final int id,
        @NonNull Object... objects) {
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.stat_acdisplay).setColor(App.ACCENT_COLOR).setAutoCancel(true);

    PendingIntent pi = null;//from w  w w  . j  ava 2s  .  c o  m
    switch (id) {
    case App.ID_NOTIFY_TEST: {
        NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
                .bigText(res.getString(R.string.notification_test_message_large));
        builder.setStyle(bts).setContentTitle(res.getString(R.string.app_name))
                .setContentText(res.getString(R.string.notification_test_message))
                .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        break;
    }
    case App.ID_NOTIFY_BATH: {
        CharSequence contentText = (CharSequence) objects[0];
        Intent contentIntent = (Intent) objects[1];
        // Build notification
        pi = PendingIntent.getActivity(context, id, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentTitle(res.getString(R.string.service_bath)).setContentText(contentText)
                .setPriority(Notification.PRIORITY_MIN);
        break;
    }
    case App.ID_NOTIFY_INIT: {
        builder.setSmallIcon(R.drawable.stat_notify).setContentTitle(res.getString(R.string.app_name))
                .setContentText(res.getString(R.string.notification_init_text))
                .setPriority(Notification.PRIORITY_MIN);
        break;
    }
    case App.ID_NOTIFY_APP_AUTO_DISABLED: {
        CharSequence summary = (CharSequence) objects[0];
        NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
                .bigText(res.getString(R.string.permissions_auto_disabled)).setSummaryText(summary);
        builder.setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
                .setContentTitle(res.getString(R.string.app_name))
                .setContentText(res.getString(R.string.permissions_auto_disabled))
                .setPriority(Notification.PRIORITY_HIGH).setStyle(bts);
        break;
    }
    default:
        throw new IllegalArgumentException();
    }
    if (pi == null) {
        pi = PendingIntent.getActivity(context, id, new Intent(context, MainActivity.class),
                PendingIntent.FLAG_UPDATE_CURRENT);
    }
    return builder.setContentIntent(pi).build();
}

From source file:com.careme.apvereda.careme.DailyAlarm.java

@Override
public void onReceive(Context context, Intent intent) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_notifications);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_notsmall).setLargeIcon(bitmap)
            .setContentTitle(context.getResources().getText(R.string.notifTittle))
            .setContentText(context.getResources().getText(R.string.notifBody))
            .setVibrate(new long[] { 100, 250, 100, 500 });
    Intent resultIntent = new Intent(context, MainActivity.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    int mNotificationId = 001;
    NotificationManager mNotifyMgr = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotifyMgr.notify(mNotificationId, mBuilder.build());
}

From source file:com.breadwallet.tools.manager.BRNotificationManager.java

public static void sendNotification(Activity ctx, int icon, String title, String message, int mId) {
    if (ctx == null)
        return;//from   ww  w. ja  v  a2 s  . c  o m
    android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(icon).setContentTitle(title).setContentText(message);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(ctx, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
}