public static Notification buildNotification(Context context, Notification.Builder builder) { builder.setSmallIcon(R.drawable.leak_canary_notification) .setWhen(System.currentTimeMillis()) .setOnlyAlertOnce(true); if (SDK_INT >= O) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel notificationChannel = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID); if (notificationChannel == null) { String channelName = context.getString(R.string.leak_canary_notification_channel); notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(notificationChannel); } builder.setChannelId(NOTIFICATION_CHANNEL_ID); } if (SDK_INT < JELLY_BEAN) { return builder.getNotification(); } else { return builder.build(); } }
@Override public void onCreate() { super.onCreate(); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); builder = new Notification.Builder(this); builder.setContentTitle("Uploading to Cloudinary...") .setSmallIcon(R.drawable.ic_launcher) .setContentIntent(PendingIntent.getActivity(this, 999, new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT).setAction(ACTION_STATE_IN_PROGRESS), 0)) .setOnlyAlertOnce(true) .setOngoing(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(MainApplication.NOTIFICATION_CHANNEL_ID); } HandlerThread handlerThread = new HandlerThread("CloudinaryServiceBackgroundThread"); handlerThread.start(); backgroundThreadHandler = new Handler(handlerThread.getLooper()); }
@Override protected void onPreExecute() { super.onPreExecute(); Notification.Builder builder = new Notification.Builder(SendCommentService.this) .setTicker(getString(R.string.sending_comment)) .setContentTitle(getString(R.string.sending_comment)).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(); NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService( NOTIFICATION_SERVICE); notificationManager.notify(notificationId, notification); tasksNotifications.put(WeiboSendTask.this, notificationId); }
private void createNotification() { Log.i(TAG, "Create running notification"); // Create open and pause action intents Intent openIntent = new Intent(this, MainActivity.class); Intent pauseIntent = new Intent(this, ActionReceiver.class); pauseIntent.setAction(Constants.ACTION_UPDATE_STATUS); pauseIntent.putExtra(Constants.Extra.ACTION, Constants.Action.PAUSE); pauseIntent.putExtra(Constants.Extra.BRIGHTNESS, mBrightness); Notification.Action pauseAction = new Notification.Action( R.drawable.ic_wb_incandescent_black_24dp, getString(R.string.notification_action_turn_off), PendingIntent.getBroadcast(getBaseContext(), 0, pauseIntent, Intent.FILL_IN_DATA) ); // Create notification Notification.Builder builder = new Notification.Builder(getApplicationContext()) .setContentTitle(getString(R.string.notification_running_title)) .setContentText(getString(R.string.notification_running_msg)) .setSmallIcon(R.drawable.ic_brightness_2_white_36dp) .addAction(pauseAction) .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT)) .setAutoCancel(false) .setOngoing(true) .setOnlyAlertOnce(true) .setShowWhen(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(Constants.NOTIFICATION_CHANNEL_ID_RS); } mNotification = builder.build(); }
static Notification add(Context context, Notification n, CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, RemoteViews tickerView, int number, PendingIntent contentIntent, PendingIntent fullScreenIntent, Bitmap largeIcon) { Notification.Builder b = new Notification.Builder(context) .setWhen(n.when) .setSmallIcon(n.icon, n.iconLevel) .setContent(n.contentView) .setTicker(n.tickerText, tickerView) .setSound(n.sound, n.audioStreamType) .setVibrate(n.vibrate) .setLights(n.ledARGB, n.ledOnMS, n.ledOffMS) .setOngoing((n.flags & Notification.FLAG_ONGOING_EVENT) != 0) .setOnlyAlertOnce((n.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0) .setAutoCancel((n.flags & Notification.FLAG_AUTO_CANCEL) != 0) .setDefaults(n.defaults) .setContentTitle(contentTitle) .setContentText(contentText) .setContentInfo(contentInfo) .setContentIntent(contentIntent) .setDeleteIntent(n.deleteIntent) .setFullScreenIntent(fullScreenIntent, (n.flags & Notification.FLAG_HIGH_PRIORITY) != 0) .setLargeIcon(largeIcon) .setNumber(number); return b.getNotification(); } }
@Override public Notification build() { // Note: this is not a NotificationCompat builder so be mindful of the // API level of methods you call on the builder. Notification.Builder builder = new Notification.Builder(mContext); builder.setContentTitle(mTitle); builder.setContentText(mBody).setStyle(new Notification.BigTextStyle().bigText(mBody)); builder.setSubText(mOrigin); builder.setTicker(mTickerText); builder.setLargeIcon(mLargeIcon); setSmallIconOnBuilder(builder, mSmallIconId, mSmallIconBitmap); builder.setContentIntent(mContentIntent); builder.setDeleteIntent(mDeleteIntent); for (Action action : mActions) { addActionToBuilder(builder, action); } if (mSettingsAction != null) { addActionToBuilder(builder, mSettingsAction); } builder.setDefaults(mDefaults); builder.setVibrate(mVibratePattern); builder.setWhen(mTimestamp); builder.setOnlyAlertOnce(!mRenotify); return builder.build(); } }
static Notification add(Context context, Notification n, CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, RemoteViews tickerView, int number, PendingIntent contentIntent, PendingIntent fullScreenIntent, Bitmap largeIcon) { Notification.Builder b = new Notification.Builder(context) .setWhen(n.when) .setSmallIcon(n.icon, n.iconLevel) .setContent(n.contentView) .setTicker(n.tickerText, tickerView) .setSound(n.sound, n.audioStreamType) .setVibrate(n.vibrate) .setLights(n.ledARGB, n.ledOnMS, n.ledOffMS) .setOngoing((n.flags & Notification.FLAG_ONGOING_EVENT) != 0) .setOnlyAlertOnce((n.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0) .setAutoCancel((n.flags & Notification.FLAG_AUTO_CANCEL) != 0) .setDefaults(n.defaults) .setContentTitle(contentTitle) .setContentText(contentText) .setContentInfo(contentInfo) .setContentIntent(contentIntent) .setDeleteIntent(n.deleteIntent) .setFullScreenIntent(fullScreenIntent, (n.flags & Notification.FLAG_HIGH_PRIORITY) != 0) .setLargeIcon(largeIcon); return b.getNotification(); } }
static Notification.Builder createBuilder(NotificationCompat2.Builder b) { final Notification n = b.mNotification; return new Notification.Builder(b.mContext) .setWhen(n.when) .setSmallIcon(n.icon, n.iconLevel) .setContent(n.contentView) .setTicker(n.tickerText, b.mTickerView) .setSound(n.sound, n.audioStreamType) .setVibrate(n.vibrate) .setLights(n.ledARGB, n.ledOnMS, n.ledOffMS) .setOngoing((n.flags & FLAG_ONGOING_EVENT) != 0) .setOnlyAlertOnce((n.flags & FLAG_ONLY_ALERT_ONCE) != 0) .setAutoCancel((n.flags & FLAG_AUTO_CANCEL) != 0) .setDefaults(n.defaults) .setContentTitle(b.mContentTitle) .setContentText(b.mContentText) .setContentInfo(b.mContentInfo) .setContentIntent(b.mContentIntent) .setDeleteIntent(n.deleteIntent) .setFullScreenIntent(b.mFullScreenIntent, (n.flags & Notification.FLAG_HIGH_PRIORITY) != 0) .setLargeIcon(b.mLargeIcon) .setNumber(b.mNumber); }
private void showSuccessfulNotification(final WeiboSendTask task) { Notification.Builder builder = new Notification.Builder(SendReplyToCommentService.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(); final NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService( NOTIFICATION_SERVICE); final int id = tasksNotifications.get(task); notificationManager.notify(id, notification); handler.postDelayed(new Runnable() { @Override public void run() { notificationManager.cancel(id); stopServiceIfTasksAreEnd(task); } }, 3000); LocalBroadcastManager.getInstance(SendReplyToCommentService.this).sendBroadcast( new Intent(AppEventAction.buildSendCommentOrReplySuccessfullyAction(oriMsg.getStatus()))); }
private void showSuccessfulNotification(final WeiboSendTask task) { Notification.Builder builder = new Notification.Builder(SendCommentService.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(); final NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService( NOTIFICATION_SERVICE); final int id = tasksNotifications.get(task); notificationManager.notify(id, notification); handler.postDelayed(new Runnable() { @Override public void run() { notificationManager.cancel(id); stopServiceIfTasksAreEnd(task); } }, 3000); LocalBroadcastManager.getInstance(SendCommentService.this).sendBroadcast( new Intent(AppEventAction.buildSendCommentOrReplySuccessfullyAction(oriMsg))); }
private void showSuccessfulNotification(final WeiboSendTask task) { Notification.Builder builder = new Notification.Builder(SendRepostService.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(); final int id = tasksNotifications.get(task); NotificationUtility.show(notification, id); handler.postDelayed(new Runnable() { @Override public void run() { NotificationUtility.cancel(id); stopServiceIfTasksAreEnd(task); } }, 3000); LocalBroadcastManager.getInstance(SendRepostService.this).sendBroadcast( new Intent(AppEventAction.buildSendRepostSuccessfullyAction(oriMsg))); }
@Override protected void onPreExecute() { super.onPreExecute(); Notification.Builder builder = new Notification.Builder(SendReplyToCommentService.this) .setTicker(getString(R.string.sending_comment)) .setContentTitle(getString(R.string.sending_comment)).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(); NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService( NOTIFICATION_SERVICE); notificationManager.notify(notificationId, notification); tasksNotifications.put(WeiboSendTask.this, notificationId); }
private void showSuccessfulNotification(final WeiboSendTask task) { Notification.Builder builder = new Notification.Builder(SendWeiboService.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(); final int id = tasksNotifications.get(task); NotificationUtility.show(notification, id); handler.postDelayed(new Runnable() { @Override public void run() { NotificationUtility.cancel(id); stopServiceIfTasksAreEnd(task); } }, 3000); }
private void sendNotification(String contentText) { Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); Notification n = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_stat_kd) .setContentTitle("Possible Karma attack detected!") .setContentText(contentText) .setSound(defaultNotificationUri) .setLights(Color.RED, 500, 500) .setOnlyAlertOnce(true) .setContentIntent(intent) .setAutoCancel(true).build(); notificationManager.notify(0, n); }
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); }
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 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); }
@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 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); }