Intent intent = new Intent(this, MyBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, 0); Builder builder = new Notification.Builder(this): ..... code for your notification builder.setDeleteIntent(pendingIntent);
// prepare intent which is triggered if the // notification is selected Intent intent = new Intent(this, NotificationReceiver.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); // build notification // the addAction re-use the same intent to keep the example short Notification n = new Notification.Builder(this) .setContentTitle("New mail from " + "test@gmail.com") .setContentText("Subject") .setSmallIcon(R.drawable.icon) .setContentIntent(pIntent) .setAutoCancel(true) .addAction(R.drawable.icon, "Call", pIntent) .addAction(R.drawable.icon, "More", pIntent) .addAction(R.drawable.icon, "And more", pIntent).build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, n);
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void tryNewMiuiBadge(Context context, int badgeCount) throws ShortcutBadgeException { if (resolveInfo == null) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); } if (resolveInfo != null) { NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(context) .setContentTitle("") .setContentText("") .setSmallIcon(resolveInfo.getIconResource()); Notification notification = builder.build(); try { Field field = notification.getClass().getDeclaredField("extraNotification"); Object extraNotification = field.get(notification); Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); method.invoke(extraNotification, badgeCount); mNotificationManager.notify(0, notification); } catch (Exception e) { throw new ShortcutBadgeException("not able to set badge", e); } } }
Notification notification = new Notification.Builder(this) .setContentTitle("Background Video Recorder") .setContentText("")
Intent deleteIntent = new Intent(this, DeleteNotificationService.class); deleteIntent.putExtra(TODOUUID, mTodoUUID); Notification notification = new Notification.Builder(this) .setContentTitle(mTodoText) .setSmallIcon(R.drawable.ic_done_white_24dp)
if (wakeLockHeld) contentText += " (wake lock held)"; Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(getText(R.string.application_name)); builder.setContentText(contentText);
Notification.Builder builder = new Notification.Builder(context) .setSmallIcon(R.drawable.block_canary_notification) .setWhen(System.currentTimeMillis())
0, new Intent(this, MyActivity.class), 0); return new Notification.Builder(this) .setContentTitle(title) .setContentText(text)
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { int badgeCount = intent.getIntExtra("badgeCount", 0); mNotificationManager.cancel(notificationId); notificationId++; Notification.Builder builder = new Notification.Builder(getApplicationContext()) .setContentTitle("") .setContentText("") .setSmallIcon(R.drawable.ic_launcher); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setupNotificationChannel(); builder.setChannelId(NOTIFICATION_CHANNEL); } Notification notification = builder.build(); ShortcutBadger.applyNotification(getApplicationContext(), notification, badgeCount); mNotificationManager.notify(notificationId, notification); } }
Notification.Builder builder = new Notification.Builder(context) .setContentTitle(context.getString(R.string.leak_canary_notification_dumping)); Notification notification = LeakCanaryInternals.buildNotification(context, builder);
Notification noti = new Notification.Builder() .setContentTitle("New mail from " + sender.toString()) .setContentText(subject) .setSmallIcon(R.drawable.new_mail) .setLargeIcon(aBitmap) .setStyle(new NotificationCompat.BigTextStyle() .bigText(aVeryLongString)) .build();
Notification noti = new Notification.Builder() .setContentTitle("New mail from " + sender.toString()) .setContentText(subject) .setSmallIcon(R.drawable.new_mail) .setLargeIcon(aBitmap) .setStyle(new Notification.BigTextStyle() .bigText(aVeryLongString)) .build();
public void raiseBattle(View view) { Notification n=new Notification.Builder(MainActivity.this, CHANNEL_BATTLE) .setContentTitle(getString(R.string.notif_battle_title)) .setContentText(getString(R.string.notif_battle_text)) .setSmallIcon(android.R.drawable.stat_sys_warning) .setBadgeIconType(Notification.BADGE_ICON_SMALL) .setColor(Color.RED) .setColorized(true) .build(); mgr.notify(NOTIF_ID_BATTLE, n); }
private void addNotification() { // create the notification Notification.Builder m_notificationBuilder = new Notification.Builder(this) .setContentTitle(getText(R.string.service_name)) .setContentText(getResources().getText(R.string.service_status_monitor)) .setSmallIcon(R.drawable.notification_small_icon); // create the pending intent and add to the notification Intent intent = new Intent(this, MyService.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); m_notificationBuilder.setContentIntent(pendingIntent); // send the notification m_notificationManager.notify(NOTIFICATION_ID, m_notificationBuilder.build()); }
public void raiseContent(View view) { Notification n=new Notification.Builder(MainActivity.this, CHANNEL_CONTENT) .setContentTitle(getString(R.string.notif_content_title)) .setContentText(getString(R.string.notify_content_text)) .setSmallIcon(android.R.drawable.stat_sys_warning) .build(); mgr.notify(NOTIF_ID_CONTENT, n); }
public void raiseCoins(View view) { Notification n=new Notification.Builder(MainActivity.this, CHANNEL_COINS) .setContentTitle(getString(R.string.notif_coins_title)) .setContentText(getString(R.string.notif_coins_text)) .setSmallIcon(android.R.drawable.stat_sys_warning) .setTimeoutAfter(5000) .build(); mgr.notify(NOTIF_ID_COINS, n); }
private Notification buildDefaultNotification(Context context) { String title = context.getString(R.string.default_filedownloader_notification_title); String content = context.getString(R.string.default_filedownloader_notification_content); Notification.Builder builder = new Notification.Builder(context, notificationChannelId); builder.setContentTitle(title).setContentText(content) .setSmallIcon(DEFAULT_NOTIFICATION_ID); return builder.build(); }
@Before public void setup() { service = Robolectric.setupService(MyService.class); notBuilder = new Notification.Builder(service) .setSmallIcon(1) .setContentTitle("Test") .setContentText("Hi there"); }
public static void showNotification(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent pendingIntent, int notificationId) { Notification.Builder builder = new Notification.Builder(context) .setContentText(contentText) .setContentTitle(contentTitle) .setAutoCancel(true) .setContentIntent(pendingIntent); Notification notification = buildNotification(context, builder); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, notification); }
protected void showForegroundNotification(int max, int progress, boolean indeterminate, String contentText) { Notification.Builder builder = new Notification.Builder(this) .setContentTitle(getString(notificationContentTitleResId)) .setContentText(contentText) .setProgress(max, progress, indeterminate); Notification notification = LeakCanaryInternals.buildNotification(this, builder); startForeground(notificationId, notification); }