static Notification buildNotification(Context ctxt) { NotificationCompat.Builder b=new NotificationCompat.Builder(ctxt) .setOngoing(true) .setContentTitle(ctxt.getString(R.string.notif_title)) .setContentText(ctxt.getString(R.string.notif_text)) .setSmallIcon(android.R.drawable.stat_sys_warning); return(b.build()); }
private Notification buildForegroundNotification(String filename) { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setOngoing(true) .setContentTitle(getString(R.string.downloading)) .setContentText(filename) .setSmallIcon(android.R.drawable.stat_sys_download); return(b.build()); } }
private Notification buildForegroundNotification(String channel) { NotificationCompat.Builder b=new NotificationCompat.Builder(this, channel); b.setOngoing(true) .setContentTitle(getString(R.string.notify_working)) .setSmallIcon(android.R.drawable.stat_sys_download); return(b.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()); }
@Override public void taskEnd(@NonNull final DownloadTask task, @NonNull EndCause cause, @android.support.annotation.Nullable Exception realCause, @NonNull SpeedCalculator taskSpeed) { Log.d("NotificationActivity", "taskEnd " + cause + " " + realCause); builder.setOngoing(false); builder.setAutoCancel(true); builder.setTicker("taskEnd " + cause); builder.setContentText( "task end " + cause + " average speed: " + taskSpeed.averageSpeed()); if (cause == EndCause.COMPLETED) { builder.setProgress(1, 1, false); } new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { if (taskEndRunnable != null) taskEndRunnable.run(); manager.notify(task.getId(), builder.build()); } // because of on some android phone too frequency notify for same id would be // ignored. }, 100); } }
public void initNotification() { manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final String channelId = "okdownload"; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { final NotificationChannel channel = new NotificationChannel( channelId, "OkDownloadSample", NotificationManager.IMPORTANCE_MIN); manager.createNotificationChannel(channel); } builder = new NotificationCompat.Builder(context, channelId); builder.setDefaults(Notification.DEFAULT_LIGHTS) .setOngoing(true) .setOnlyAlertOnce(true) .setPriority(NotificationCompat.PRIORITY_MIN) .setContentTitle("OkDownloadSample") .setContentText("Download a task showing on notification sample") .setSmallIcon(R.mipmap.ic_launcher); if (action != null) { builder.addAction(action); } }
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()); }
private NotificationCompat.Builder createNotification() { notRemoteView = new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.player_popup_notification); notRemoteView.setTextViewText(R.id.notificationSongName, playerImpl.getVideoTitle()); notRemoteView.setTextViewText(R.id.notificationArtist, playerImpl.getUploaderName()); notRemoteView.setImageViewBitmap(R.id.notificationCover, playerImpl.getThumbnail()); notRemoteView.setOnClickPendingIntent(R.id.notificationPlayPause, PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT)); notRemoteView.setOnClickPendingIntent(R.id.notificationStop, PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT)); notRemoteView.setOnClickPendingIntent(R.id.notificationRepeat, PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_REPEAT), PendingIntent.FLAG_UPDATE_CURRENT)); // Starts popup player activity -- attempts to unlock lockscreen final Intent intent = NavigationHelper.getPopupPlayerActivityIntent(this); notRemoteView.setOnClickPendingIntent(R.id.notificationContent, PendingIntent.getActivity(this, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT)); setRepeatModeRemote(notRemoteView, playerImpl.getRepeatMode()); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) .setSmallIcon(R.drawable.ic_newpipe_triangle_white) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContent(notRemoteView); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { builder.setPriority(NotificationCompat.PRIORITY_MAX); } return builder; }
@SuppressWarnings("deprecation") private void ensureDownloadingBuilder() { if (mDownloadingBuilder != null) { return; } Intent stopAllIntent = new Intent(this, DownloadService.class); stopAllIntent.setAction(ACTION_STOP_ALL); PendingIntent piStopAll = PendingIntent.getService(this, 0, stopAllIntent, 0); mDownloadingBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_download) .setOngoing(true) .setAutoCancel(false) .setCategory(NotificationCompat.CATEGORY_PROGRESS) .setColor(getResources().getColor(R.color.colorPrimary)) .addAction(R.drawable.ic_pause_x24, getString(R.string.stat_download_action_stop_all), piStopAll) .setShowWhen(false) .setChannelId(CHANNEL_ID); mDownloadingDelay = new NotificationDelay(this, mNotifyManager, mDownloadingBuilder, ID_DOWNLOADING); }
private void showNotification() { NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER) .setOngoing(true) .setContentTitle("Presentation!") .setSmallIcon(android.R.drawable.stat_notify_more) .addAction(android.R.drawable.ic_media_previous, getString(R.string.action_previous), buildPreviousPendingIntent()) .addAction(android.R.drawable.ic_media_next, getString(R.string.action_next), buildNextPendingIntent()) .addAction(android.R.drawable.ic_media_pause, getString(R.string.action_stop), buildStopPendingIntent()); mgr.notify(1337, b.build()); }
private void ensure509Builder() { if (m509dBuilder != null) { return; } m509dBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) .setSmallIcon(R.drawable.ic_stat_alert) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setContentText(getString(R.string.stat_509_alert_title)) .setContentText(getString(R.string.stat_509_alert_text)) .setAutoCancel(true) .setOngoing(false) .setCategory(NotificationCompat.CATEGORY_ERROR) .setChannelId(CHANNEL_ID); m509Delay = new NotificationDelay(this, mNotifyManager, m509dBuilder, ID_509); }
private NotificationCompat.Builder createNotification() { notRemoteView = new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.player_notification); bigNotRemoteView = new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.player_notification_expanded); setupNotification(notRemoteView); setupNotification(bigNotRemoteView); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) .setSmallIcon(R.drawable.ic_newpipe_triangle_white) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCustomContentView(notRemoteView) .setCustomBigContentView(bigNotRemoteView); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { builder.setPriority(NotificationCompat.PRIORITY_MAX); } return builder; }
private NotificationItem(int id, String title, String desc) { super(id, title, desc); Intent[] intents = new Intent[2]; intents[0] = Intent.makeMainActivity(new ComponentName(DemoApplication.CONTEXT, MainActivity.class)); intents[1] = new Intent(DemoApplication.CONTEXT, NotificationSampleActivity.class); this.pendingIntent = PendingIntent.getActivities(DemoApplication.CONTEXT, 0, intents, PendingIntent.FLAG_UPDATE_CURRENT); builder = new NotificationCompat. Builder(FileDownloadHelper.getAppContext()); builder.setDefaults(Notification.DEFAULT_LIGHTS) .setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MIN) .setContentTitle(getTitle()) .setContentText(desc) .setContentIntent(pendingIntent) .setSmallIcon(R.mipmap.ic_launcher); }
private NotificationItem(int id, String title, String desc) { super(id, title, desc); Intent[] intents = new Intent[2]; intents[0] = Intent.makeMainActivity(new ComponentName(DemoApplication.CONTEXT, MainActivity.class)); intents[1] = new Intent(DemoApplication.CONTEXT, NotificationSampleActivity.class); this.pendingIntent = PendingIntent.getActivities(DemoApplication.CONTEXT, 0, intents, PendingIntent.FLAG_UPDATE_CURRENT); builder = new NotificationCompat. Builder(FileDownloadHelper.getAppContext()); builder.setDefaults(Notification.DEFAULT_LIGHTS) .setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MIN) .setContentTitle(getTitle()) .setContentText(desc) .setContentIntent(pendingIntent) .setSmallIcon(R.mipmap.ic_launcher); }
@Override public void taskStart(@NonNull DownloadTask task) { Log.d("NotificationActivity", "taskStart"); builder.setTicker("taskStart"); builder.setOngoing(true); builder.setAutoCancel(false); builder.setContentText("The task is started"); builder.setProgress(0, 0, true); manager.notify(task.getId(), builder.build()); }
private NotificationCompat.Builder buildForeground( String filename) { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); RemoteViews content=new RemoteViews(getPackageName(), R.layout.notif_content); content.setTextViewText(android.R.id.title, "Downloading: "+filename); b.setOngoing(true) .setContent(content) .setSmallIcon(android.R.drawable.stat_sys_download); return(b); } }
private Notification buildForegroundNotification() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setOngoing(true) .setContentTitle(getString(R.string.msg_foreground)) .setSmallIcon(R.drawable.ic_stat_ping) .addAction(android.R.drawable.ic_media_pause, getString(R.string.msg_stop), buildStopPendingIntent()); return(b.build()); }
private NotificationCompat.Builder createNotification() { return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) .setSmallIcon(R.drawable.ic_newpipe_triangle_white) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentTitle(getString(R.string.preferred_player_fetcher_notification_title)) .setContentText(getString(R.string.preferred_player_fetcher_notification_message)); } }
private NotificationCompat.Builder buildForeground( String filename) { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setContentTitle(getString(R.string.downloading)) .setContentText(filename) .setSmallIcon(android.R.drawable.stat_sys_download) .setOnlyAlertOnce(true) .setOngoing(true); return(b); } }
protected NotificationCompat.Builder createNotification() { return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) .setProgress(-1, -1, true) .setSmallIcon(R.drawable.ic_newpipe_triangle_white) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentTitle(getString(getTitle())); }