builder.setSmallIcon(R.drawable.ic_service_notification); builder.setContentIntent(pendingIntent); builder.setOngoing(true);
builder.setSmallIcon(R.drawable.ic_launcher); builder.setContentIntent(pendingIntent); builder.setOngoing(true); builder.setSubText("This is subtext..."); //API level 16 builder.setNumber(100);
@Test public void build_whenSetOngoing_setsOngoingToTrue() { Notification notification = builder.setOngoing(true).build(); assertThat(shadowOf(notification).isOngoing()).isTrue(); }
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 1, intent, 0); Notification.Builder builder = new Notification.Builder(MainActivity.this); builder.setAutoCancel(false); builder.setTicker("this is ticker text"); builder.setContentTitle("WhatsApp Notification"); builder.setContentText("You have a new message"); builder.setSmallIcon(R.drawable.ic_launcher); builder.setContentIntent(pendingIntent); builder.setOngoing(true); builder.setSubText("This is subtext..."); //API level 16 builder.setNumber(100); builder.build(); myNotication = builder.getNotification(); manager.notify(11, myNotication);
private void showNotification() { final Intent notificationIntent = new Intent(Common.ACTION_STOP_CAST); PendingIntent notificationPendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder builder = new Notification.Builder(this); builder.setSmallIcon(R.mipmap.ic_launcher) .setDefaults(Notification.DEFAULT_ALL) .setOnlyAlertOnce(true) .setOngoing(true) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.casting_screen)) .addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.action_stop), notificationPendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NT_ID_CASTING, builder.build()); }
private void startVibrate(Context context, Intent intent) { vibrator.vibrate(VIBRATE_PATTERN, VIBRATE_REPEAT); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification.Builder(context) .setContentText(context.getString(R.string.stop_vibrate)) .setContentTitle(context.getString(R.string.app_name)) .setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setOngoing(true) .setContentIntent(PendingIntent.getBroadcast(context, 0, new Intent(context, ToggleVibratePhone.class), PendingIntent.FLAG_UPDATE_CURRENT)) .build(); notificationManager.notify(NOTIFICATION_ID, notification); vibrating=true; }
private void showSuccessfulNotification() { Notification.Builder builder = new Notification.Builder(RepostWithAppSrcServices.this) .setTicker(getString(R.string.send_successfully)) .setContentTitle(getString(R.string.send_successfully)).setOnlyAlertOnce(true).setAutoCancel(true) .setSmallIcon(R.drawable.send_successfully).setOngoing(false); Notification notification = builder.getNotification(); NotificationUtility.show(notification, R.string.send_successfully); handler.postDelayed(new Runnable() { @Override public void run() { NotificationUtility.cancel(R.string.send_successfully); } }, 3000); }
private void showSuccessfulNotification() { NotificationUtility.cancel(R.string.sending); Notification.Builder builder = new Notification.Builder(SendWithAppSrcServices.this) .setTicker(getString(R.string.send_successfully)) .setContentTitle(getString(R.string.send_successfully)).setOnlyAlertOnce(true).setAutoCancel(true) .setSmallIcon(R.drawable.send_successfully).setOngoing(false); Notification notification = builder.getNotification(); NotificationUtility.show(notification, R.string.send_successfully); handler.postDelayed(new Runnable() { @Override public void run() { NotificationUtility.cancel(R.string.send_successfully); } }, 3000); }
@Override protected void onPreExecute() { super.onPreExecute(); Notification.Builder builder = new Notification.Builder(SendRepostService.this) .setTicker(getString(R.string.sending_repost)) .setContentTitle(getString(R.string.sending_repost)).setContentText(content).setOnlyAlertOnce(true) .setOngoing(true) .setSmallIcon(R.drawable.upload_white); builder.setProgress(0, 100, true); int notificationId = new Random().nextInt(Integer.MAX_VALUE); notification = builder.getNotification(); NotificationUtility.show(notification, notificationId); tasksNotifications.put(WeiboSendTask.this, notificationId); }
private void showErrorNotification(long id) { OfflineFile offlineFile = offlineFileRepository.getFileWithDownloadId(id); if (offlineFile != null) { NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder .setContentTitle(getString(R.string.notification_offline_download_error)) .setContentText(getString(R.string.notification_upload_message, offlineFile.getName())) .setOngoing(false); Notification notification = notificationBuilder.build(); notificationManager.notify((int) offlineFile.getTimeStamp(), notification); } }
@Override public void downloadStarted(int id, String fileName) { notificationBuilder = new Notification.Builder(getApplicationContext()); notificationBuilder .setOngoing(true) .setSmallIcon(R.drawable.ic_app_logo) .setContentTitle(getString(R.string.notification_download_offline_title)) .setContentText(getString(R.string.notification_upload_message, fileName)) .setProgress(100, 0, false) .build(); Notification notification = notificationBuilder.build(); startForeground(NOTIFICATION_OFFLINE_ID, notification); }
@Override public void downloadPaused(long downloadId, int progress) { stopForeground(false); NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder .setContentTitle(getString(R.string.notification_offline_download_paused)) .setOngoing(false) .setProgress(100, progress, false); Notification notification = notificationBuilder.build(); notificationManager.notify(NOTIFICATION_OFFLINE_ID, notification); stopDownloading(); }
Notification.Builder builder = new Notification.Builder(getApplicationContext()); builder.setSmallIcon(R.drawable.notification_icon); builder.setContentTitle("Your notification text"); builder.setProgress(100, 0, true); /* 0 out of 100 progress to start */ builder.setAutoCancel(false); builder.setOngoing(true); Notification notification = builder.getNotification(); /* NOTIFICATION_ID can just be a static int to identify your service's notification */ startForeground(NOTIFICATION_ID, notification);
private void showSendingNotification() { Notification.Builder builder = new Notification.Builder(this) .setTicker(getString(R.string.repost)) .setContentTitle(getString(R.string.wait_server_response)) .setNumber(100).setProgress(100, 100, false) .setOnlyAlertOnce(true).setOngoing(true).setSmallIcon(R.drawable.upload_white); Notification notification = builder.getNotification(); NotificationUtility.show(notification, R.string.repost); }
private void showSendingNotification() { Notification.Builder builder = new Notification.Builder(this) .setTicker(getString(R.string.sending)) .setContentTitle(getString(R.string.wait_server_response)) .setNumber(100).setProgress(100, 100, false) .setOnlyAlertOnce(true).setOngoing(true).setSmallIcon(R.drawable.upload_white); Notification notification = builder.getNotification(); NotificationUtility.show(notification, R.string.sending); }
private void showDownloadedNotification(@NonNull OfflineFile offlineFile) { NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder .setContentTitle(getString(R.string.notification_offline_download_complete)) .setContentText(getString(R.string.notification_upload_message, offlineFile.getName())) .setOngoing(false); Notification notification = notificationBuilder.build(); notificationManager.cancel(NOTIFICATION_OFFLINE_ID); notificationManager.notify((int) offlineFile.getTimeStamp(), notification); }
private Notification.Builder getNotificationBuilder(final PendingIntent pIntent, final String text, final int icon) { return new Notification.Builder(this) .setContentTitle("HTTPServer") .setContentText(text) .setSmallIcon(icon) .setContentIntent(pIntent) .setOngoing(true) .addAction(R.drawable.online, "Open", pIntent); }
public class MyNotificationBuilderJellyBean { Notification.Builder mb = null; MyNotificationBuilderJellyBean(Context myContext, int icon, String ticker, String title, String info, Long timeStamp, PendingIntent pendingIntent, boolean onGoing) { mb = new Notification.Builder(myContext); mb.setSmallIcon(icon); mb.setContentIntent(pendingIntent); mb.setContentTitle(title); mb.setContentText(info); mb.setWhen(timeStamp); if (ticker != null) mb.setTicker(ticker); mb.setOngoing(onGoing); } Notification get() { return mb.build(); } }
public class MyNotificationBuilderHoneyCombToIceCreamSandwich { Notification.Builder mb = null; MyNotificationBuilderHoneyCombToIceCreamSandwich(Context myContext, int icon, String ticker, String title, String info, Long timeStamp, PendingIntent pendingIntent, boolean onGoing) { mb = new Notification.Builder(myContext); mb.setSmallIcon(icon); mb.setContentIntent(pendingIntent); mb.setContentTitle(title); mb.setContentText(info); mb.setWhen(timeStamp); if (ticker != null) mb.setTicker(ticker); mb.setOngoing(onGoing); } Notification get() { return mb.getNotification(); } }
Integer notificationID = 100; NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //Set notification information: Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext()); notificationBuilder.setOngoing(true) .setContentTitle("Notification Content Title") .setContentText("Notification Content Text") .setProgress(100, 0, false); //Send the notification: Notification notification = notificationBuilder.build(); notificationManager.notify(notificationID, notification);