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.achep.acdisplay.services.BathService.java
/** * <p>NOT SYNCHRONIZED!</p>//from w w w . j a va2 s . c om * Builds fresh notification with all {@link ChildService children services}'s * {@link com.achep.acdisplay.services.BathService.ChildService#getLabel() labels} in. * Content intent starts {@link com.achep.acdisplay.activities.MainActivity}. */ private Notification buildNotification() { boolean empty = true; StringBuilder builder = new StringBuilder(); String divider = getString(R.string.settings_multi_list_divider); for (ChildService child : mMap.values()) { if (!empty) { builder.append(divider); } builder.append(child.getLabel()); empty = false; } String contentText = builder.toString(); if (contentText.length() > 0) { contentText = contentText.charAt(0) + contentText.substring(1).toLowerCase(); } PendingIntent pendingIntent = PendingIntent.getActivity(this, App.ID_NOTIFY_BATH, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); return new Notification.Builder(this).setContentTitle(getString(R.string.service_bath)) .setContentText(contentText).setContentIntent(pendingIntent).setSmallIcon(R.drawable.stat_acdisplay) .setPriority(Notification.PRIORITY_MIN).build(); }
From source file:name.gumartinm.weather.information.notification.NotificationIntentService.java
private void showNotification(final Current current, final WeatherLocation weatherLocation) { // 1. Update units of measurement. final UnitsConversor tempUnitsConversor = new TempUnitsConversor(this.getApplicationContext()); // 2. Formatters final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); tempFormatter.applyPattern("###.##"); // 3. Prepare data for RemoteViews. String tempMax = ""; if (current.getMain().getTemp_max() != null) { double conversion = (Double) current.getMain().getTemp_max(); conversion = tempUnitsConversor.doConversion(conversion); tempMax = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol(); }//from ww w. ja v a2 s .c om String tempMin = ""; if (current.getMain().getTemp_min() != null) { double conversion = (Double) current.getMain().getTemp_min(); conversion = tempUnitsConversor.doConversion(conversion); tempMin = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol(); } Bitmap picture; if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null) && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) { final String icon = current.getWeather().get(0).getIcon(); picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon).getResourceDrawable()); } else { picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert); } final String city = weatherLocation.getCity(); final String country = weatherLocation.getCountry(); // 4. Insert data in RemoteViews. final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.weather_notification); remoteView.setImageViewBitmap(R.id.weather_notification_image, picture); remoteView.setTextViewText(R.id.weather_notification_temperature_max, tempMax); remoteView.setTextViewText(R.id.weather_notification_temperature_min, tempMin); remoteView.setTextViewText(R.id.weather_notification_city, city); remoteView.setTextViewText(R.id.weather_notification_country, country); // 5. Activity launcher. final Intent resultIntent = new Intent(this.getApplicationContext(), MainTabsActivity.class); // The PendingIntent to launch our activity if the user selects this notification. // 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. final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainTabsActivity.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); final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(this.getApplicationContext()); // 6. Create notification. final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( this.getApplicationContext()).setContent(remoteView).setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true).setLocalOnly(true).setWhen(System.currentTimeMillis()) .setContentIntent(resultPendingIntent).setPriority(NotificationCompat.PRIORITY_DEFAULT); final Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Send the notification. // Sets an ID for the notification, so it can be updated (just in case) int notifyID = 1; notificationManager.notify(notifyID, notification); }
From source file:com.snappy.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w . j av a 2 s .c o m*/ private void generateNotification(Context context, String message, String fromName, Bundle pushExtras, String body) { db = new LocalDB(context); List<LocalMessage> myMessages = db.getAllMessages(); // Open a new activity called GCMMessageView Intent intento = new Intent(this, SplashScreenActivity.class); intento.replaceExtras(pushExtras); // Pass data to the new activity intento.putExtra(Const.PUSH_INTENT, true); intento.setAction(Long.toString(System.currentTimeMillis())); intento.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); // Starts the activity on notification click PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT); // Create the notification with a notification builder NotificationCompat.Builder notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis()) .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)) .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true) .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) .setContentText(body).setContentIntent(pIntent); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)); for (int i = 0; i < myMessages.size(); i++) { inboxStyle.addLine(myMessages.get(i).getMessage()); } notification.setStyle(inboxStyle); // Remove the notification on click //notification.flags |= Notification.FLAG_AUTO_CANCEL; //notification.defaults |= Notification.DEFAULT_VIBRATE; //notification.defaults |= Notification.DEFAULT_SOUND; //notification.defaults |= Notification.DEFAULT_LIGHTS; NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(R.string.app_name, notification.build()); { // Wake Android Device when notification received PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH"); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); } }
From source file:ca.rmen.android.poetassistant.PoemAudioExport.java
private PendingIntent getMainActivityIntent() { Intent intent = new Intent(mContext, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.chintans.venturebox.util.Utils.java
public static void showNotification(Context context, PackageInfo[] infosRom, PackageInfo[] infosGapps) { Resources resources = context.getResources(); if (infosRom != null) { sPackageInfosRom = infosRom;//from www. j a v a 2 s. c o m } else { infosRom = sPackageInfosRom; } if (infosGapps != null) { sPackageInfosGapps = infosGapps; } else { infosGapps = sPackageInfosGapps; } Intent intent = new Intent(context, MainActivity.class); NotificationInfo fileInfo = new NotificationInfo(); fileInfo.mNotificationId = Updater.NOTIFICATION_ID; fileInfo.mPackageInfosRom = infosRom; fileInfo.mPackageInfosGapps = infosGapps; intent.putExtra(FILES_INFO, fileInfo); PendingIntent pIntent = PendingIntent.getActivity(context, Updater.NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(resources.getString(R.string.new_system_update)) .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.ic_launcher)) .setContentIntent(pIntent); String contextText = ""; if (infosRom.length + infosGapps.length == 1) { String filename = infosRom.length == 1 ? infosRom[0].getFilename() : infosGapps[0].getFilename(); contextText = resources.getString(R.string.new_package_name, new Object[] { filename }); } else { contextText = resources.getString(R.string.new_packages, new Object[] { infosRom.length + infosGapps.length }); } builder.setContentText(contextText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(context.getResources().getString(R.string.new_system_update)); if (infosRom.length + infosGapps.length > 1) { inboxStyle.addLine(contextText); } for (int i = 0; i < infosRom.length; i++) { inboxStyle.addLine(infosRom[i].getFilename()); } for (int i = 0; i < infosGapps.length; i++) { inboxStyle.addLine(infosGapps[i].getFilename()); } inboxStyle.setSummaryText(resources.getString(R.string.app_name)); builder.setStyle(inboxStyle); Notification notif = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Service.NOTIFICATION_SERVICE); notif.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(Updater.NOTIFICATION_ID, notif); }
From source file:io.indy.drone.service.ScheduledService.java
public void createNotification() { // get the id of the latest strike String region = SQLDatabase.regionFromIndex(0); // worldwide String id = mDatabase.getRecentStrikeIdInRegion(region); Strike strike = mDatabase.getStrike(id); String title = getString(R.string.notification_preface) + " " + strike.getCountry(); String droneSummary = strike.getDroneSummary(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification).setContentTitle(title).setContentText(droneSummary) .setAutoCancel(true);/*from w w w . j a v a 2 s .c o m*/ // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, StrikeDetailActivity.class); resultIntent.putExtra(SQLDatabase.KEY_ID, id); resultIntent.putExtra(SQLDatabase.REGION, region); // 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(StrikeDetailActivity.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); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(title); bigTextStyle.bigText(strike.getBijSummaryShort()); bigTextStyle.setSummaryText(droneSummary); // Moves the big view style object into the notification object. mBuilder.setStyle(bigTextStyle); } mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(33, mBuilder.build()); }
From source file:com.adstrosoftware.notificationcompass.CompassService.java
/** * TODO/*from www . j a v a 2 s. c o m*/ * * @return */ private Notification buildNotification(int textResId, int iconResId, double azimuth) { Notification notification; PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent stopServiceIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_STOP_SERVICE), PendingIntent.FLAG_UPDATE_CURRENT); if (!actionAdded) { notification = notificationBuilder.setContentTitle(getString(textResId)) .setContentText(String.valueOf(azimuth)).setSmallIcon(iconResId).setOngoing(true) .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent) .addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.stop), stopServiceIntent) .build(); actionAdded = true; } else { notification = notificationBuilder.setContentTitle(getString(textResId)) .setContentText(String.valueOf(azimuth)).setSmallIcon(iconResId).setOngoing(true) .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent).build(); } return notification; }
From source file:it.gulch.linuxday.android.services.AlarmIntentService.java
private void notifyEvent(Intent intent) { long eventId = Long.parseLong(intent.getDataString()); Event event = eventManager.get(eventId); if (event == null) { return;/*from w ww . j av a 2 s .c o m*/ } // NotificationManager notificationManager = (NotificationManager) getSystemService(Context // .NOTIFICATION_SERVICE); // PendingIntent eventPendingIntent = // TaskStackBuilder.create(this).addNextIntent(new Intent(this, // MainActivity.class)).addNextIntent( // new Intent(this, EventDetailsActivity.class).setData(Uri.parse(String.valueOf(event // .getId())))) // .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent eventPendingIntent = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MainActivity.class)) .addNextIntent(new Intent(this, EventDetailsActivity.class) .setData(Uri.parse(String.valueOf(event.getId())))) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); int defaultFlags = Notification.DEFAULT_SOUND; SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_NOTIFICATIONS_VIBRATE, false)) { defaultFlags |= Notification.DEFAULT_VIBRATE; } String trackName = event.getTrack().getTitle(); CharSequence bigText; String contentText; if (CollectionUtils.isEmpty(event.getPeople())) { contentText = trackName; bigText = event.getSubtitle(); } else { String personsSummary = StringUtils.join(event.getPeople(), ", "); contentText = String.format("%1$s - %2$s", trackName, personsSummary); String subTitle = event.getSubtitle(); SpannableString spannableBigText; if (TextUtils.isEmpty(subTitle)) { spannableBigText = new SpannableString(personsSummary); } else { spannableBigText = new SpannableString(String.format("%1$s\n%2$s", subTitle, personsSummary)); } // Set the persons summary in italic spannableBigText.setSpan(new StyleSpan(Typeface.ITALIC), +spannableBigText.length() - personsSummary.length(), spannableBigText.length(), +Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); bigText = spannableBigText; } String roomName = event.getTrack().getRoom().getName(); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setWhen(event.getStartDate().getTime()) .setContentTitle(event.getTitle()).setContentText(contentText) .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(trackName)) .setContentInfo(roomName).setContentIntent(eventPendingIntent).setAutoCancel(true) .setDefaults(defaultFlags).setPriority(NotificationCompat.PRIORITY_HIGH); // Blink the LED with FOSDEM color if enabled in the options if (sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_NOTIFICATIONS_LED, false)) { notificationBuilder.setLights(getResources().getColor(R.color.maincolor), 1000, 5000); } /*// Android Wear extensions NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); // Add an optional action button to show the room map image int roomImageResId = getResources() .getIdentifier(StringUtils.roomNameToResourceName(roomName), "drawable", getPackageName()); if(roomImageResId != 0) { // The room name is the unique Id of a RoomImageDialogActivity Intent mapIntent = new Intent(this, RoomImageDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setData(Uri.parse(roomName)); mapIntent.putExtra(RoomImageDialogActivity.EXTRA_ROOM_NAME, roomName); mapIntent.putExtra(RoomImageDialogActivity.EXTRA_ROOM_IMAGE_RESOURCE_ID, roomImageResId); PendingIntent mapPendingIntent = PendingIntent.getActivity(this, 0, mapIntent, PendingIntent.FLAG_UPDATE_CURRENT); CharSequence mapTitle = getString(R.string.room_map); notificationBuilder .addAction(new NotificationCompat.Action(R.drawable.ic_action_place, mapTitle, mapPendingIntent)); // Use bigger action icon for wearable notification wearableExtender.addAction( new NotificationCompat.Action(R.drawable.ic_place_white_wear, mapTitle, mapPendingIntent)); } notificationBuilder.extend(wearableExtender);*/ NotificationManagerCompat.from(this).notify((int) eventId, notificationBuilder.build()); }
From source file:com.bullmobi.message.services.BathService.java
/** * <p>NOT SYNCHRONIZED!</p>/*ww w . java 2s . c o m*/ * Builds fresh notification with all {@link ChildService children services}'s * {@link com.bullmobi.message.services.BathService.ChildService#getLabel() labels} in. * Content intent starts {@link com.bullmobi.message.ui.activities.MainActivity}. */ private Notification buildNotification() { boolean empty = true; StringBuilder sb = new StringBuilder(); String divider = getString(R.string.settings_multi_list_divider); for (ChildService child : mMap.values()) { if (!empty) { sb.append(divider); } sb.append(child.getLabel()); empty = false; } String contentText = sb.toString(); if (contentText.length() > 0) { contentText = contentText.charAt(0) + contentText.substring(1).toLowerCase(); } PendingIntent pendingIntent = PendingIntent.getActivity(this, App.ID_NOTIFY_BATH, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.service_bath)).setContentText(contentText) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.stat_easynotification) .setPriority(Notification.PRIORITY_MIN).setColor(App.ACCENT_COLOR); return builder.build(); }
From source file:at.flack.receiver.EMailReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras();// w ww.j a va 2 s.co m try { if (bundle.getString("type").equals("mail")) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (!sharedPrefs.getBoolean("notification_mail", true)) return; notify = sharedPrefs.getBoolean("notifications", true); vibrate = sharedPrefs.getBoolean("vibration", true); headsup = sharedPrefs.getBoolean("headsup", true); led_color = sharedPrefs.getInt("notification_light", -16776961); boolean all = sharedPrefs.getBoolean("all_mail", true); if (notify == false) return; NotificationCompat.Builder mBuilder = null; boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = bundle.getString("senderName").equals("") ? bundle.getString("senderMail") : bundle.getString("senderName"); try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( ProfilePictureCache.getInstance(context).get(origin_name), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); int lastIndex = bundle.getString("subject").lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(0, lastIndex))) { mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name) .setColor(0xFFFF5722) .setContentText(res.getString(R.string.sms_receiver_new_encrypted_mail)) .setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { if (bundle.getString("subject").charAt(0) == '%' && (bundle.getString("subject").length() == 10 || bundle.getString("subject").length() == 9)) { if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFFF5722) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (bundle.getString("subject").charAt(0) == '%' && bundle.getString("subject").length() >= 120 && bundle.getString("subject").length() < 125) { if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFFF5722) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (all) { // normal message mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name) .setColor(0xFFFF5722).setContentText(bundle.getString("subject")) .setAutoCancel(true).setStyle( new NotificationCompat.BigTextStyle().bigText(bundle.getString("subject"))); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } // } Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); mBuilder.setLights(led_color, 750, 4000); if (vibrate) { mBuilder.setVibrate(new long[] { 0, 100, 200, 300 }); } Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("MAIL", bundle.getString("senderMail")); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (Build.VERSION.SDK_INT >= 16 && headsup) mBuilder.setPriority(Notification.PRIORITY_HIGH); if (Build.VERSION.SDK_INT >= 21) mBuilder.setCategory(Notification.CATEGORY_MESSAGE); final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (!MainActivity.isOnTop) mNotificationManager.notify(9, mBuilder.build()); } } catch (Exception e) { e.printStackTrace(); } }