List of usage examples for android.app Notification FLAG_AUTO_CANCEL
int FLAG_AUTO_CANCEL
To view the source code for android.app Notification FLAG_AUTO_CANCEL.
Click Source Link
From source file:kr.co.bettersoft.checkmileage.activities.GCMIntentService.java
/** * generateNotification/* w w w . j a v a 2s . c o m*/ * Issues a notification to inform the user that server has sent a message. * @param context * @param message * @return */ private void generateNotification(Context context, String message) { int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); // sdf String title = context.getString(R.string.app_name); String mileageUpdateStr = context.getString(R.string.mileage_noti); Intent notificationIntent; /* * MILEAGE : ? ?? ? ???. * MARKETING : ?? ? ?. * Check Mileage ?. : test .. * * <string name="gcm_new_msgkkk"> </string> */ String new_msg = " "; if (message.equals(new_msg)) { Log.d(TAG, "new msg - test"); notificationIntent = new Intent(context, DummyActivity.class); // notificationIntent.putExtra("RunMode", "TEST"); // ?? ? . ?? .. ? .. notificationIntent.putExtra("RunMode", "MILEAGE"); // // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK // | Intent.FLAG_ACTIVITY_CLEAR_TOP // | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); // }else if(message.contains("MILEAGE")){ // }else if(message.contains(mileageUpdateStr)){ // ?? ?. () } else if (message.equals(mileageUpdateStr)) { // ?? ?. (). Log.d(TAG, "update mileage"); MyMileagePageActivity.searched = false; // notificationIntent = new Intent(context, MainActivity.class); // ? ? ?.. notificationIntent = new Intent(context, DummyActivity.class); notificationIntent.putExtra("RunMode", "MILEAGE"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK // | Intent.FLAG_ACTIVITY_CLEAR_TOP // | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } else if (message.equals("MARKETING")) { Log.d(TAG, "noti event push"); // notificationIntent = new Intent(context, MainActivity.class); // ? ? ? ? .. notificationIntent = new Intent(context, DummyActivity.class); notificationIntent.putExtra("RunMode", "MARKETING"); notificationIntent.putExtra("MESSAGE", "New Event"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK // | Intent.FLAG_ACTIVITY_CLEAR_TOP // | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } else { // ?. Log.d(TAG, "noti event push"); // notificationIntent = new Intent(context, MainActivity.class); // ? ? ? ? .. notificationIntent = new Intent(context, DummyActivity.class); notificationIntent.putExtra("RunMode", "MARKETING"); notificationIntent.putExtra("MESSAGE", message); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK // | Intent.FLAG_ACTIVITY_CLEAR_TOP // | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } }
From source file:com.geecko.QuickLyric.broadcastReceiver.MusicBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { /** Google Play Music //bool streaming long position //long albumId String album //bool currentSongLoaded String track //long ListPosition long ListSize //long id bool playing //long duration int previewPlayType //bool supportsRating int domain //bool albumArtFromService String artist //int rating bool local //bool preparing bool inErrorState *//*from w w w . ja v a2 s .c o m*/ Bundle extras = intent.getExtras(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); boolean lengthFilter = sharedPref.getBoolean("pref_filter_20min", true); if (extras != null) try { extras.getInt("state"); } catch (BadParcelableException e) { return; } if (extras == null || extras.getInt("state") > 1 //Tracks longer than 20min are presumably not songs || (lengthFilter && (extras.get("duration") instanceof Long && extras.getLong("duration") > 1200000) || (extras.get("duration") instanceof Double && extras.getDouble("duration") > 1200000) || (extras.get("duration") instanceof Integer && extras.getInt("duration") > 1200)) || (lengthFilter && (extras.get("secs") instanceof Long && extras.getLong("secs") > 1200000) || (extras.get("secs") instanceof Double && extras.getDouble("secs") > 1200000) || (extras.get("secs") instanceof Integer && extras.getInt("secs") > 1200)) || (extras.containsKey("com.maxmpz.audioplayer.source") && Build.VERSION.SDK_INT >= 19)) return; String artist = extras.getString("artist"); String track = extras.getString("track"); long position = extras.containsKey("position") && extras.get("position") instanceof Long ? extras.getLong("position") : -1; if (extras.get("position") instanceof Double) position = Double.valueOf(extras.getDouble("position")).longValue(); boolean isPlaying = extras.getBoolean(extras.containsKey("playstate") ? "playstate" : "playing", true); if (intent.getAction().equals("com.amazon.mp3.metachanged")) { artist = extras.getString("com.amazon.mp3.artist"); track = extras.getString("com.amazon.mp3.track"); } else if (intent.getAction().equals("com.spotify.music.metadatachanged")) isPlaying = spotifyPlaying; else if (intent.getAction().equals("com.spotify.music.playbackstatechanged")) spotifyPlaying = isPlaying; if ((artist == null || "".equals(artist)) //Could be problematic || (track == null || "".equals(track) || track.startsWith("DTNS"))) // Ignore one of my favorite podcasts return; SharedPreferences current = context.getSharedPreferences("current_music", Context.MODE_PRIVATE); String currentArtist = current.getString("artist", ""); String currentTrack = current.getString("track", ""); SharedPreferences.Editor editor = current.edit(); editor.putString("artist", artist); editor.putString("track", track); if (!(artist.equals(currentArtist) && track.equals(currentTrack) && position == -1)) editor.putLong("position", position); editor.putBoolean("playing", isPlaying); if (isPlaying) { long currentTime = System.currentTimeMillis(); editor.putLong("startTime", currentTime); } editor.apply(); autoUpdate = autoUpdate || sharedPref.getBoolean("pref_auto_refresh", false); int notificationPref = Integer.valueOf(sharedPref.getString("pref_notifications", "0")); if (autoUpdate && App.isActivityVisible()) { Intent internalIntent = new Intent("Broadcast"); internalIntent.putExtra("artist", artist).putExtra("track", track); LyricsViewFragment.sendIntent(context, internalIntent); forceAutoUpdate(false); } boolean inDatabase = DatabaseHelper.getInstance(context) .presenceCheck(new String[] { artist, track, artist, track }); if (notificationPref != 0 && isPlaying && (inDatabase || OnlineAccessVerifier.check(context))) { Intent activityIntent = new Intent("com.geecko.QuickLyric.getLyrics").putExtra("TAGS", new String[] { artist, track }); Intent wearableIntent = new Intent("com.geecko.QuickLyric.SEND_TO_WEARABLE").putExtra("artist", artist) .putExtra("track", track); PendingIntent openAppPending = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent wearablePending = PendingIntent.getBroadcast(context, 8, wearableIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(R.drawable.ic_watch, context.getString(R.string.wearable_prompt), wearablePending).build(); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context); NotificationCompat.Builder wearableNotifBuilder = new NotificationCompat.Builder(context); int[] themes = new int[] { R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red, R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo, R.style.Theme_QuickLyric_Green, R.style.Theme_QuickLyric_Lime, R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark }; int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0")); TypedValue primaryColorValue = new TypedValue(); context.setTheme(themes[themeNum]); context.getTheme().resolveAttribute(R.attr.colorPrimary, primaryColorValue, true); notifBuilder.setSmallIcon(R.drawable.ic_notif).setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setColor(primaryColorValue.data).setGroupSummary(true); wearableNotifBuilder.setSmallIcon(R.drawable.ic_notif) .setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setOngoing(false).setColor(primaryColorValue.data) .setGroupSummary(false) .extend(new NotificationCompat.WearableExtender().addAction(wearableAction)); if (notificationPref == 2) { notifBuilder.setOngoing(true).setPriority(-2); // Notification.PRIORITY_MIN wearableNotifBuilder.setPriority(-2); } else notifBuilder.setPriority(-1); // Notification.PRIORITY_LOW Notification notif = notifBuilder.build(); Notification wearableNotif = wearableNotifBuilder.build(); if (notificationPref == 2) notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; else notif.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManagerCompat.from(context).notify(0, notif); try { context.getPackageManager().getPackageInfo("com.google.android.wearable.app", PackageManager.GET_META_DATA); NotificationManagerCompat.from(context).notify(8, wearableNotif); } catch (PackageManager.NameNotFoundException ignored) { } } else if (track.equals(current.getString("track", ""))) NotificationManagerCompat.from(context).cancel(0); }
From source file:com.getpillion.gcm.GcmIntentService.java
private void sendNotification(Intent targetIntent, String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, targetIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher_white).setContentTitle(msg) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setPriority(2) .setContentText(greetingMessages[new Random().nextInt(greetingMessages.length)]); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_ALL; //notification.defaults |= Notification.DEFAULT_VIBRATE; mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:de.azapps.mirakel.sync.taskwarrior.services.SyncAdapter.java
/** * Shows the Notification with the error message if needed * * @param showNotification/*from www . j av a 2 s. c o m*/ * @param success * @throws ClassNotFoundException */ private void handleError(final boolean showNotification, final boolean success) throws ClassNotFoundException { if (showNotification && !success) { final String title = "Mirakel: " + this.mContext.getText(R.string.finish_sync); final Intent openIntent = new Intent(this.mContext, Class.forName(DefinitionsHelper.MAINACTIVITY_CLASS)); openIntent.setAction(DefinitionsHelper.SHOW_MESSAGE); openIntent.putExtra(Intent.EXTRA_SUBJECT, title); openIntent.putExtra(Intent.EXTRA_TEXT, last_message); openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent pOpenIntent = PendingIntent.getActivity(this.mContext, 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT); final Notification notification = new NotificationCompat.Builder(this.mContext).setContentTitle(title) .setContentText(last_message).setSmallIcon(android.R.drawable.stat_notify_sync) .setPriority(NotificationCompat.PRIORITY_LOW).setContentIntent(pOpenIntent).build(); notification.flags = Notification.FLAG_AUTO_CANCEL; this.mNotificationManager.notify(SyncAdapter.NOTIFY_ID, notification); } }
From source file:org.onebusaway.android.directions.realtime.RealtimeService.java
private void showNotification(ItineraryDescription description, int title, int message, Class<? extends Activity> notificationTarget, Bundle params, List<Itinerary> itineraries) { String titleText = getResources().getString(title); String messageText = getResources().getString(message); Intent openIntent = new Intent(getApplicationContext(), notificationTarget); openIntent.putExtras(params);//from www .java 2 s .co m openIntent.putExtra(OTPConstants.INTENT_SOURCE, OTPConstants.Source.NOTIFICATION); openIntent.putExtra(OTPConstants.ITINERARIES, (ArrayList<Itinerary>) itineraries); openIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent openPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, openIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.ic_stat_notification).setContentTitle(titleText) .setStyle(new NotificationCompat.BigTextStyle().bigText(messageText)).setContentText(messageText) .setPriority(NotificationCompat.PRIORITY_MAX).setContentIntent(openPendingIntent); NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = mBuilder.build(); notification.defaults = Notification.DEFAULT_ALL; notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; Integer notificationId = description.getId(); notificationManager.notify(notificationId, notification); }
From source file:com.bluelinelabs.logansquare.typeconverters.NotificationConverter.java
@TargetApi(Build.VERSION_CODES.KITKAT) @NonNull//from w ww . j a v a 2 s . co m public static SimpleNotification toSimpleNotification(@NonNull Notification notification) { SimpleNotification simpleNotification = new SimpleNotification(); simpleNotification.autoCancel = (notification.flags & Notification.FLAG_AUTO_CANCEL) == Notification.FLAG_AUTO_CANCEL; android.util.Log.d("json2notification", "autoCancel:" + simpleNotification.autoCancel); //simpleNotification.bigPictureStyle // TODO simpleNotification.category = notification.category; simpleNotification.color = notification.color > 0 ? notification.color : null; simpleNotification.contentInfo = notification.extras.getString(Notification.EXTRA_INFO_TEXT); simpleNotification.contentIntent = notification.contentIntent; simpleNotification.contentTitle = notification.extras.getString(Notification.EXTRA_TITLE); simpleNotification.contentText = notification.extras.getString(Notification.EXTRA_TEXT); simpleNotification.defaults = notification.defaults > 0 ? notification.defaults : null; simpleNotification.deleteIntent = notification.deleteIntent; //simpleNotification.extras; simpleNotification.groupKey = notification.getGroup(); if (simpleNotification.groupKey != null) { simpleNotification.groupSummary = (notification.flags & Notification.FLAG_GROUP_SUMMARY) == Notification.FLAG_GROUP_SUMMARY; } Bitmap bitmap = notification.extras.getParcelable(Notification.EXTRA_LARGE_ICON); if (bitmap != null) simpleNotification.largeIcon = Bitmaps.base64(bitmap); if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) == Notification.FLAG_SHOW_LIGHTS) { simpleNotification.lights = Arrays.asList(notification.ledARGB, notification.ledOnMS, notification.ledOffMS); } simpleNotification.localOnly = (notification.flags & Notification.FLAG_LOCAL_ONLY) == Notification.FLAG_LOCAL_ONLY; simpleNotification.number = notification.number > 0 ? notification.number : null; simpleNotification.ongoing = (notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT; simpleNotification.onlyAlertOnce = (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) == Notification.FLAG_ONLY_ALERT_ONCE; String[] people = notification.extras.getStringArray(Notification.EXTRA_PEOPLE); if (people != null) { simpleNotification.people = Arrays.asList(people); } simpleNotification.priority = notification.priority > 0 ? notification.priority : null; //simpleNotification.progress; simpleNotification.publicVersion = notification.publicVersion; simpleNotification.showWhen = notification.extras.getBoolean(Notification.EXTRA_SHOW_WHEN); if (simpleNotification.showWhen) { simpleNotification.when = notification.when; } simpleNotification.smallIcon = String.valueOf(notification.extras.getInt(Notification.EXTRA_SMALL_ICON)); // TODO getResourceNameById() android.util.Log.d("json2notification", "simpleNotification.smallIcon" + simpleNotification.smallIcon); simpleNotification.sortKey = notification.getSortKey(); simpleNotification.sound = notification.sound; simpleNotification.subText = notification.extras.getString(Notification.EXTRA_SUB_TEXT); simpleNotification.tickerText = notification.tickerText; simpleNotification.usesChronometer = notification.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER); simpleNotification.visibility = notification.visibility > 0 ? notification.visibility : null; return simpleNotification; }
From source file:com.android.python27.ScriptService.java
@Override protected Notification createNotification() { Notification notification = new Notification(R.drawable.icon, this.getString(R.string.loading), System.currentTimeMillis()); // This contentIntent is a noop. PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0); notification.setLatestEventInfo(this, this.getString(R.string.app_name), this.getString(R.string.loading), contentIntent);/*from w w w .j a v a2 s . c o m*/ notification.flags = Notification.FLAG_AUTO_CANCEL; return notification; }
From source file:com.vendsy.bartsy.venue.GCMIntentService.java
/** * To generate a notification to inform the user that server has sent a message. * //from w w w.ja v a2s . com * @param count * @param count */ private static void generateNotification(Context context, String message, String count) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; try { int countValue = Integer.parseInt(count); notification.number = countValue; } catch (NumberFormatException e) { e.printStackTrace(); } // // Play default notification sound notification.defaults = Notification.DEFAULT_SOUND; notificationManager.notify(0, notification); }
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 w ww . j av a2 s .c om } 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:crea.wallet.lite.service.CreativeCoinService.java
private void notifyCoinsReceived(Sha256Hash hash) { if (!Configuration.getInstance().isNotificationsEnabled()) { return;//from w w w . j av a2 s . com } int notificationCount = transactionsReceived.size(); if (notificationCount == 1) { nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); } notificationAccumulatedAmount = Coin.ZERO; for (Coin c : transactionsReceived.values()) { notificationAccumulatedAmount = notificationAccumulatedAmount.add(c); } Coin coin = Coin.valueOf(notificationAccumulatedAmount.getValue()); String msg; Intent intent; msg = getString(R.string.notif_accumulated_amount, coin.toFriendlyString(), notificationCount); intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(TransactionActivity.TRANSACTION_ID, hash.toString()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); String title = getString(R.string.notif_cash_in_title, coin.toFriendlyString()); final NotificationCompat.Builder notification = new NotificationCompat.Builder(this); notification.setSmallIcon(R.mipmap.ic_notification); notification.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); notification.setColor(getResources().getColor(R.color.colorPrimary)); notification.setContentText(msg); notification.setContentTitle(title); notification.setWhen(System.currentTimeMillis()); notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notification.setContentIntent(pendingIntent); Notification notif = notification.build(); notif.flags |= Notification.FLAG_AUTO_CANCEL; nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notif); }