// Add app running notification private void addNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Notifications Example") .setContentText("This is a test notification"); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); // Add as notification NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(FM_NOTIFICATION_ID, builder.build()); } // Remove notification private void removeNotification() { NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.cancel(FM_NOTIFICATION_ID); }
private void createNotification(String text, String link){ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setAutoCancel(true) .setSmallIcon(R.drawable.app_icon) .setContentTitle(text); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // pending implicit intent to view url Intent resultIntent = new Intent(Intent.ACTION_VIEW); resultIntent.setData(Uri.parse(link)); PendingIntent pending = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(pending); // using the same tag and Id causes the new notification to replace an existing one mNotificationManager.notify(String.valueOf(System.currentTimeMillis()), PUSH, notificationBuilder.build()); }
try { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( this) .setSmallIcon(R.drawable.ic_notif_alert) .setContentTitle(getResources().getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(msg) .setStyle(bigTextStyle) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); Log.d(TAG, "---- Notification Composed ----"); } catch(SecurityException se) { se.printStackTrace(); } catch(Exception e) { e.printStackTrace(); }
private void raiseNotification(String contentType, File output, Exception e) { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()); if (e == null) { b.setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setSmallIcon(android.R.drawable.stat_sys_download_done); Intent outbound=new Intent(Intent.ACTION_VIEW); outbound.setDataAndType(Uri.fromFile(output), contentType); b.setContentIntent(PendingIntent.getActivity(this, 0, outbound, 0)); } else { b.setContentTitle(getString(R.string.exception)) .setContentText(e.getMessage()) .setSmallIcon(android.R.drawable.stat_notify_error); } mgr.notify(NOTIFY_ID, b.build()); }
private void showWearOne() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.entry)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setGroup(GROUP_SAMPLE); mgrCompat.notify(NOTIFY_ID2, b.build()); }
private void showWearTwo() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.another_entry)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setGroup(GROUP_SAMPLE); mgrCompat.notify(NOTIFY_ID3, b.build()); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setGroup(GROUP_SAMPLE) .setGroupSummary(true); return(b); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
private static NotificationCompat.Builder newNotificationBuilder( Context context, @DrawableRes int smallIcon, String channelId, @Nullable PendingIntent contentIntent, @Nullable String message, @StringRes int titleStringId) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId).setSmallIcon(smallIcon); if (titleStringId != NULL_STRING_ID) { notificationBuilder.setContentTitle(context.getResources().getString(titleStringId)); } if (contentIntent != null) { notificationBuilder.setContentIntent(contentIntent); } if (message != null) { notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } return notificationBuilder; } }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setPriority(Notification.PRIORITY_HIGH) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
private NotificationCompat.Builder buildBase(Context ctxt, String channel, int titleId) { NotificationCompat.Builder b= new NotificationCompat.Builder(ctxt, channel); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(ctxt.getString(titleId)) .setContentIntent(buildPendingIntent(ctxt, Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .addAction(android.R.drawable.ic_media_play, ctxt.getString(R.string.play), buildPendingIntent(ctxt, Settings.ACTION_SETTINGS)); return(b); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setNumber(5) .setFullScreenIntent(buildPendingIntent(Settings.ACTION_DATE_SETTINGS), true) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setTicker(getString(R.string.download_complete)) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setLocalOnly(true) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
public void showSendFailedNotification(Account account, Exception exception) { String title = resourceProvider.sendFailedTitle(); String text = ExceptionHelper.getRootCauseMessage(exception); int notificationId = NotificationIds.getSendFailedNotificationId(account); PendingIntent folderListPendingIntent = actionBuilder.createViewFolderListPendingIntent( account, notificationId); NotificationCompat.Builder builder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconWarning()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setTicker(title) .setContentTitle(title) .setContentText(text) .setContentIntent(folderListPendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_ERROR); notificationHelper.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true); getNotificationManager().notify(notificationId, builder.build()); }
private void setNotification(String notificationMessage) { //**add this line** int requestID = (int) System.currentTimeMillis(); Uri alarmSound = getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mNotificationManager = getApplication().getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(getApplicationContext(), NotificationActivity2.class); //**add this line** notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); //**edit this line to put requestID as requestCode** PendingIntent contentIntent = PendingIntent.getActivity(this, requestID,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.logo) .setContentTitle("My Notification") .setStyle(new NotificationCompat.BigTextStyle() .bigText(notificationMessage)) .setContentText(notificationMessage).setAutoCancel(true); mBuilder.setSound(alarmSound); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
public void showCertificateErrorNotification(Account account, boolean incoming) { int notificationId = NotificationIds.getCertificateErrorNotificationId(account, incoming); PendingIntent editServerSettingsPendingIntent = createContentIntent(account, incoming); String title = resourceProvider.certificateErrorTitle(account.getDescription()); String text = resourceProvider.certificateErrorBody(); NotificationCompat.Builder builder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconWarning()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setTicker(title) .setContentTitle(title) .setContentText(text) .setContentIntent(editServerSettingsPendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_ERROR); notificationHelper.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true); getNotificationManager().notify(notificationId, builder.build()); }
public void showAuthenticationErrorNotification(Account account, boolean incoming) { int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, incoming); PendingIntent editServerSettingsPendingIntent = createContentIntent(account, incoming); String title = resourceProvider.authenticationErrorTitle(); String text = resourceProvider.authenticationErrorBody(account.getDescription()); NotificationCompat.Builder builder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconWarning()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setTicker(title) .setContentTitle(title) .setContentText(text) .setContentIntent(editServerSettingsPendingIntent) .setStyle(new BigTextStyle().bigText(text)) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_ERROR); notificationHelper.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true); getNotificationManager().notify(notificationId, builder.build()); }
public void showSendingNotification(Account account) { String accountName = notificationHelper.getAccountName(account); String title = resourceProvider.sendingMailTitle(); String tickerText = resourceProvider.sendingMailBody(accountName); int notificationId = NotificationIds.getFetchingMailNotificationId(account); String outboxFolder = account.getOutboxFolder(); PendingIntent showMessageListPendingIntent = actionBuilder.createViewFolderPendingIntent( account, outboxFolder, notificationId); NotificationCompat.Builder builder = notificationHelper.createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconSendingMail()) .setWhen(System.currentTimeMillis()) .setOngoing(true) .setTicker(tickerText) .setContentTitle(title) .setContentText(accountName) .setContentIntent(showMessageListPendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); if (NOTIFICATION_LED_WHILE_SYNCING) { notificationHelper.configureNotification(builder, null, null, account.getNotificationSetting().getLedColor(), NOTIFICATION_LED_BLINK_FAST, true); } getNotificationManager().notify(notificationId, builder.build()); }
public void showFetchingMailNotification(Account account, Folder folder) { String accountName = account.getDescription(); String folderServerId = folder.getServerId(); String folderName = folder.getName(); String tickerText = resourceProvider.checkingMailTicker(accountName, folderName); String title = resourceProvider.checkingMailTitle(); //TODO: Use format string from resources String text = accountName + resourceProvider.checkingMailSeparator() + folderName; int notificationId = NotificationIds.getFetchingMailNotificationId(account); PendingIntent showMessageListPendingIntent = actionBuilder.createViewFolderPendingIntent( account, folderServerId, notificationId); NotificationCompat.Builder builder = notificationHelper.createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconCheckingMail()) .setWhen(System.currentTimeMillis()) .setOngoing(true) .setTicker(tickerText) .setContentTitle(title) .setContentText(text) .setContentIntent(showMessageListPendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_SERVICE); if (NOTIFICATION_LED_WHILE_SYNCING) { notificationHelper.configureNotification(builder, null, null, account.getNotificationSetting().getLedColor(), NOTIFICATION_LED_BLINK_FAST, true); } getNotificationManager().notify(notificationId, builder.build()); }