List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT
int FLAG_UPDATE_CURRENT
To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.
Click Source Link
From source file:com.asburymotors.android.disneysocal.service.UtilityService.java
/** * Show the notification. Either the regular notification with wearable features * added to enhance, or trigger the full micro app on the wearable. * * @param cityId The city to trigger the notification for * @param microApp If the micro app should be triggered or just enhanced notifications *///from ww w . ja v a2 s .c o m private void showNotification(String cityId, boolean microApp) { List<Attraction> attractions = ATTRACTIONS.get(cityId); if (microApp) { // If micro app we first need to transfer some data over sendDataToWearable(attractions); } // The first (closest) tourist attraction Attraction attraction = attractions.get(0); // Limit attractions to send int count = attractions.size() > Constants.MAX_ATTRACTIONS ? Constants.MAX_ATTRACTIONS : attractions.size(); // Pull down the tourist attraction images from the network and store HashMap<String, Bitmap> bitmaps = new HashMap<>(); try { for (int i = 0; i < count; i++) { bitmaps.put(attractions.get(i).name, Glide.with(this).load(attractions.get(i).imageUrl).asBitmap() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(Constants.WEAR_IMAGE_SIZE, Constants.WEAR_IMAGE_SIZE).get()); } } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "Error fetching image from network: " + e); } // The intent to trigger when the notification is tapped PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, DetailActivity.getLaunchIntent(this, attraction.name), PendingIntent.FLAG_UPDATE_CURRENT); // The intent to trigger when the notification is dismissed, in this case // we want to clear remote notifications as well PendingIntent deletePendingIntent = PendingIntent.getService(this, 0, getClearRemoteNotificationsIntent(this), 0); // Construct the main notification NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmaps.get(attraction.name)) .setBigContentTitle(attraction.name).setSummaryText(getString(R.string.nearby_attraction))) .setLocalOnly(microApp).setContentTitle(attraction.name) .setContentText(getString(R.string.nearby_attraction)) .setSmallIcon(R.drawable.ic_stat_maps_pin_drop).setContentIntent(pendingIntent) .setDeleteIntent(deletePendingIntent) .setColor(getResources().getColor(R.color.colorPrimary, getTheme())) .setCategory(Notification.CATEGORY_RECOMMENDATION).setAutoCancel(true); if (!microApp) { // If not a micro app, create some wearable pages for // the other nearby tourist attractions. ArrayList<Notification> pages = new ArrayList<Notification>(); for (int i = 1; i < count; i++) { // Calculate the distance from current location to tourist attraction String distance = Utils.formatDistanceBetween(Utils.getLocation(this), attractions.get(i).location); // Construct the notification and add it as a page pages.add(new NotificationCompat.Builder(this).setContentTitle(attractions.get(i).name) .setContentText(distance).setSmallIcon(R.drawable.ic_stat_maps_pin_drop) .extend(new NotificationCompat.WearableExtender() .setBackground(bitmaps.get(attractions.get(i).name))) .build()); } builder.extend(new NotificationCompat.WearableExtender().addPages(pages)); } // Trigger the notification NotificationManagerCompat.from(this).notify(Constants.MOBILE_NOTIFICATION_ID, builder.build()); }
From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java
private RemoteViews makeErrorView(final int appWidgetId) { final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.appwidget_error);/*w w w .jav a 2 s. c o m*/ // 6. Activity launcher. final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/"), String.valueOf(appWidgetId)); resultIntent.setData(data); final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(WidgetConfigure.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent); return remoteView; }
From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java
private PendingIntent notificationIntent() { Intent intent = new Intent(this, CustomOverlayHideActivity.class); PendingIntent pending = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); return pending; }
From source file:com.bubblegum.traceratops.app.service.LoggerService.java
private void showPersistentNotification() { NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); PendingIntent pendingIntent = PendingIntent.getActivity(this, R.id.traceratops_notification_pending_intent, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); // PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, R.id.traceratops_notification_stop_pending_intent, new Intent(ACTION_STOP), PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(this).setOngoing(true) // .addAction(new NotificationCompat.Action(R.drawable.ic_notif_stop, getString(R.string.stop), stopPendingIntent)) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)) .setCategory(NotificationCompat.CATEGORY_STATUS).setPriority(NotificationCompat.PRIORITY_MIN) .setContentTitle(getString(R.string.persistent_notification_title)) .setContentText(getString(R.string.persistent_notification_text)).setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_notif_default).build(); nm.notify(R.id.traceratops_running_id, notification); }
From source file:com.abbiya.broadr.gcm.GcmIntentService.java
private void sendNotification(String msg, int notificationId) { PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name)) .setTicker(getString(R.string.messages_new_arrival)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setSound(Settings.System.DEFAULT_NOTIFICATION_URI).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(notificationId, mBuilder.build()); }
From source file:com.android.deskclock.timer.TimerReceiver.java
private void showCollapsedNotificationWithNext(final Context context, String title, String text, Long nextBroadcastTime) { LogUtils.d(TAG, "showCollapsedNotificationWithNext nextBroadcastTime: %d", nextBroadcastTime); Intent activityIntent = new Intent(context, DeskClock.class); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.TIMER_TAB_INDEX); PendingIntent pendingActivityIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); showCollapsedNotification(context, title, text, NotificationCompat.PRIORITY_HIGH, pendingActivityIntent, IN_USE_NOTIFICATION_ID, false); if (nextBroadcastTime == null) { return;//from w w w .ja v a 2 s .c o m } Intent nextBroadcast = new Intent(); nextBroadcast.setAction(Timers.NOTIF_IN_USE_SHOW); PendingIntent pendingNextBroadcast = PendingIntent.getBroadcast(context, 0, nextBroadcast, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Utils.isKitKatOrLater()) { alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } else { alarmManager.set(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast); } }
From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java
private void notifyAppWebpage() { int idGooglePlay = 12346; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.to_app_webpage)); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, ToAppWebpageActivity.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(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(ToAppWebpageActivity.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) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(idGooglePlay, mBuilder.build()); }
From source file:com.android.mail.utils.NotificationActionUtils.java
/** * Creates a {@link PendingIntent} for the specified notification action. *//*from ww w.j a va 2 s. c o m*/ private static PendingIntent getNotificationActionPendingIntent(final Context context, final Account account, final Conversation conversation, final Message message, final Folder folder, final Intent notificationIntent, final NotificationActionType action, final int notificationId, final long when) { final Uri messageUri = message.uri; final NotificationAction notificationAction = new NotificationAction(action, account, conversation, message, folder, conversation.id, message.serverId, message.id, when, NotificationAction.SOURCE_LOCAL, notificationId); switch (action) { case REPLY: { // Build a task stack that forces the conversation view on the stack before the // reply activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); final Intent intent = createReplyIntent(context, account, messageUri, false); intent.setPackage(context.getPackageName()); intent.setData(conversation.uri); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); taskStackBuilder.addNextIntent(notificationIntent).addNextIntent(intent); return taskStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); } case REPLY_ALL: { // Build a task stack that forces the conversation view on the stack before the // reply activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); final Intent intent = createReplyIntent(context, account, messageUri, true); intent.setPackage(context.getPackageName()); intent.setData(conversation.uri); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); taskStackBuilder.addNextIntent(notificationIntent).addNextIntent(intent); return taskStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); } case ARCHIVE_REMOVE_LABEL: { final String intentAction = NotificationActionIntentService.ACTION_ARCHIVE_REMOVE_LABEL; final Intent intent = new Intent(intentAction); intent.setPackage(context.getPackageName()); intent.setData(conversation.uri); putNotificationActionExtra(intent, notificationAction); return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); } case DELETE: { final String intentAction = NotificationActionIntentService.ACTION_DELETE; final Intent intent = new Intent(intentAction); intent.setPackage(context.getPackageName()); intent.setData(conversation.uri); putNotificationActionExtra(intent, notificationAction); return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); } } throw new IllegalArgumentException("Invalid NotificationActionType"); }
From source file:com.adam.aslfms.util.Util.java
public static void myNotify(Context mCtx, String title, String content, int notID) { try {// ww w . j ava 2 s . c o m Intent targetIntent = new Intent(mCtx, SettingsActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(mCtx, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(mCtx).setContentTitle(title) .setSmallIcon(R.mipmap.ic_notify).setContentText(content).setContentIntent(contentIntent); NotificationManager nManager = (NotificationManager) mCtx .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) { builder.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher)); } nManager.notify(notID, builder.build()); } catch (Exception e) { Log.d(TAG, "Phone Notification failed. " + e); } }
From source file:com.baruckis.nanodegree.spotifystreamer.PlayerService.java
private void buildNotification(NotificationCompat.Action action, boolean updateLargeIcon) { CustomTrack playSong = getCurrentTrack(); if (playSong == null) return;// ww w .j ava 2 s .co m NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle(); style.setShowActionsInCompactView(0, 1, 2); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // open last activity when tapping notification Intent openAppIntent = new Intent(this, MainArtistsListActivity.class); openAppIntent.addCategory(Intent.CATEGORY_LAUNCHER); openAppIntent.setAction(Intent.ACTION_MAIN); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); builder.setSmallIcon(android.R.drawable.ic_media_play).setLargeIcon(mLargeIconBitmap) .setContentTitle(playSong.getTrackName()).setContentText(playSong.getArtistsNamesList()) .setStyle(style).setShowWhen(false) // hide time in notification .addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS)) .addAction(action).addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT)); if (updateLargeIcon) { Picasso.Builder picassoBuilder = new Picasso.Builder(this); Picasso picasso = picassoBuilder.build(); // to avoid too many requests when user jumps on different tracks too fast, cancel latest one. picasso.cancelRequest(mTarget); mTarget = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { mLargeIconBitmap = bitmap; builder.setLargeIcon(mLargeIconBitmap); mNotification = builder.build(); if (mShowNotification) { showCancelNotification(true); } } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; String url = playSong.getCustomImageBig().getUrl(); if (url != null) { picasso.load(url).into(mTarget); } } mNotification = builder.build(); if (mShowNotification) { showCancelNotification(true); } }