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(); } }
builder.setChannelId(NOTIFICATION_CHANNEL_ID);
@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); } }
NotificationManager.IMPORTANCE_LOW); notificationManager.createNotificationChannel(channel); builder.setChannelId(CHANNEL_ID_SYNCING);
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(); }
private Notification showNotification() { createNotificationChannel(); Notification.Builder builder = null; int resourceId = R.drawable.ic_notifications_black_24dp; if(Build.VERSION.SDK_INT<=19) resourceId = R.mipmap.ic_launcher;//fix for kitkat builder = new Notification.Builder(getApplicationContext()); builder.setSmallIcon(resourceId) .setContentTitle(getResources().getString(R.string.app_name)) .setContentText("Running in background") .setAutoCancel(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(CHANNEL_ID); } Notification notification = builder.getNotification(); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; Intent resultIntent = new Intent(this, BrokersListActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack stackBuilder.addParentStack(BrokersListActivity.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(resultIntent); // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notification.contentIntent = resultPendingIntent; notification.priority = getNotificationPriority(); Log.i(MyMqttService.class.getName(),"Adding notification"); return notification; }
@TargetApi(Build.VERSION_CODES.O) public static Notification build(Notification.Builder builder) { if ((Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)) { if (Pref.getBooleanDefaultFalse("use_notification_channels")) { // get dynamic channel based on contents of the builder try { final String id = NotificationChannels.getChan(builder).getId(); builder.setChannelId(id); } catch (NullPointerException e) { //noinspection ConstantConditions builder.setChannelId(null); } } else { //noinspection ConstantConditions builder.setChannelId(null); } return builder.build(); } else { return builder.build(); // standard pre-oreo behaviour } } }
@TargetApi(Build.VERSION_CODES.O) public static Notification build(Notification.Builder builder) { if ((Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)) { if (Pref.getBooleanDefaultFalse("use_notification_channels")) { // get dynamic channel based on contents of the builder try { final String id = NotificationChannels.getChan(builder).getId(); builder.setChannelId(id); } catch (NullPointerException e) { //noinspection ConstantConditions builder.setChannelId(null); } } else { //noinspection ConstantConditions builder.setChannelId(null); } return builder.build(); } else { return builder.build(); // standard pre-oreo behaviour } } }
@Override public void writeResult(PrintWriter out) { NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (!TextUtils.isEmpty(inputString)) { if (inputString.contains("\n")) { Notification.BigTextStyle style = new Notification.BigTextStyle(); style.bigText(inputString); notification.setStyle(style); } else { notification.setContentText(inputString); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_TITLE, NotificationManager.IMPORTANCE_DEFAULT); manager.createNotificationChannel(channel); notification.setChannelId(CHANNEL_ID); } manager.notify(notificationId, 0, notification.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()); }
/** * Show a notification while this service is running. */ private void showNotification(String text) { // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); // Set the info for the views that show in the notification panel. Notification.Builder noteBuilder = new Notification.Builder(this, MainActivity.id1) .setSmallIcon(R.drawable.stat_sample) // the status icon .setTicker(text) // the status text .setWhen(System.currentTimeMillis()) // the time stamp .setContentTitle("Job service is running.") // the label .setContentText(text) // the contents of the entry .setChannelId(MainActivity.id1) .setContentIntent(contentIntent); // The intent to send when the entry is clicked // We show this for as long as our service is processing a command. noteBuilder.setOngoing(true); // Send the notification. // We use a string id because it is a unique number. We use it later to cancel. mNM.notify(100, noteBuilder.build()); }
private Notification showNotification(){ createNotificationChannel(); Notification.Builder builder = null; int resourceId = R.drawable.ic_notifications_black_24dp; if(Build.VERSION.SDK_INT<=19) resourceId = R.mipmap.ic_launcher;//fix for kitkat builder = new Notification.Builder(getApplicationContext()); builder.setSmallIcon(resourceId) .setContentTitle(getResources().getString(R.string.app_name)) .setAutoCancel(false) .setContentText("Handling tasker action"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(CHANNEL_ID); } Notification notification = builder.getNotification(); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; //notification.priority = getNotificationPriority(); return notification; }
private Notification buildNotification() { final Resources res = getResources(); final String contentTitle = res.getString(R.string.notification_title); final String contentText = res.getString(mVisibleWindow ? R.string.notification_message_visible : R.string.notification_message_hidden); final String intentAction = mVisibleWindow ? ACTION_HIDE : ACTION_SHOW; Intent actionIntent = new Intent(this, TermuxFloatService.class).setAction(intentAction); Notification.Builder builder = new Notification.Builder(this).setContentTitle(contentTitle).setContentText(contentText) .setPriority(Notification.PRIORITY_MIN).setSmallIcon(R.mipmap.ic_service_notification) .setColor(0xFF000000) .setContentIntent(PendingIntent.getService(this, 0, actionIntent, 0)) .setOngoing(true) .setShowWhen(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setupNotificationChannel(); builder.setChannelId(NOTIFICATION_CHANNEL_ID); } //final int messageId = mVisibleWindow ? R.string.toggle_hide : R.string.toggle_show; //builder.addAction(android.R.drawable.ic_menu_preferences, res.getString(messageId), PendingIntent.getService(this, 0, actionIntent, 0)); return builder.build(); }
private Notification.Builder getBuilder(String requestId, Resource.UploadStatus status) { Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(this, 1234, new Intent(this, MainActivity.class) .setAction(actionFromStatus(status)) , 0)) .setLargeIcon(getBitmap(requestId)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(MainApplication.NOTIFICATION_CHANNEL_ID); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(getResources().getColor(R.color.colorPrimary)); } return builder; }
private Notification.Builder createNotificationBuilder() { Notification.Builder builder = new Notification.Builder(this) .setOngoing(true) .setSmallIcon(R.drawable.ic_stat_device_access_video) .setContentTitle(getString(R.string.recording)); Intent stopRecording = new Intent(ACTION_STOP_SCREENCAST); stopRecording.setClass(this, RecBridgeService.class); builder.addAction(R.drawable.ic_stop, getString(R.string.stop), PendingIntent.getService(this, 0, stopRecording, PendingIntent.FLAG_UPDATE_CURRENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(NOTIFICATION_CHANNEL_ID); } return builder; }
public Notification createNotificationTracking() { Intent clickIntent = new Intent(context, WorkTimeTrackerActivity.class); clickIntent.setAction(Intent.ACTION_MAIN); clickIntent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder notificationBuilder = new Notification.Builder(context) .setContentTitle("automatic clock-in by location and/or WiFi active") .setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_menu_mylocation) .setOngoing(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationBuilder.setChannelId(getServiceNotificationChannel().getId()); } Logger.debug("created service notification"); return notificationBuilder.build(); }
private void showPassword(String password) { Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_vpn_key_white_24dp) .setContentTitle("Your password is") .setContentText(password) .setVisibility(Notification.VISIBILITY_SECRET); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) builder.setChannelId(CHANNEL_ID_COPYING); builder.setContentIntent(getCopyPendingIntent(password)); notificationManager.notify(notificationId, builder.build()); }
private static void addChannel(Notification.Builder builder, String channelId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(channelId); } }
@NonNull @SuppressLint("NewApi") Notification.Builder mockNotificationBuilderChain() throws Exception { Notification.Builder notificationBuilder = mock(Notification.Builder.class); whenNew(Notification.Builder.class).withAnyArguments().thenReturn(notificationBuilder); when(notificationBuilder.setTicker(anyString())).thenReturn(notificationBuilder); when(notificationBuilder.setContentTitle(anyString())).thenReturn(notificationBuilder); when(notificationBuilder.setContentText(anyString())).thenReturn(notificationBuilder); when(notificationBuilder.setSmallIcon(anyInt())).thenReturn(notificationBuilder); when(notificationBuilder.setContentIntent(any(PendingIntent.class))).thenReturn(notificationBuilder); when(notificationBuilder.setChannelId(anyString())).thenReturn(notificationBuilder); return notificationBuilder; }
builder.setChannelId(ChatSDKMessageChannel);