@TargetApi(Build.VERSION_CODES.O) private void setupNotificationChannel() { NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, "ShortcutBadger Sample", NotificationManager.IMPORTANCE_DEFAULT); mNotificationManager.createNotificationChannel(channel); } }
@Test @Config(minSdk = Build.VERSION_CODES.O) public void deleteNotificationChannelGroup() { final String channelId = "channelId"; final String channelGroupId = "channelGroupId"; notificationManager.createNotificationChannelGroup( new NotificationChannelGroup(channelGroupId, "groupName")); NotificationChannel channel = new NotificationChannel(channelId, "channelName", 1); channel.setGroup(channelGroupId); notificationManager.createNotificationChannel(channel); assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isFalse(); notificationManager.deleteNotificationChannelGroup(channelGroupId); assertThat(shadowOf(notificationManager).getNotificationChannelGroup(channelGroupId)).isNull(); // Per documentation, deleting a channel group also deletes all associated channels. assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isTrue(); }
public NotificationHelper(Context context) { this.context = context; notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationManager.createNotificationChannel( new NotificationChannel(CHANNEL_ID, context.getString(R.string.notification_category), NotificationManager.IMPORTANCE_LOW)); try { setChannelId = NotificationCompat.Builder.class.getMethod("setChannelId", String.class); } catch (Exception ignored) {} } }
@TargetApi(Build.VERSION_CODES.O) private void initChannels() { NotificationChannel channel= new NotificationChannel(CHANNEL_MIN, getString(R.string.channel_min), NotificationManager.IMPORTANCE_MIN); mgr.createNotificationChannel(channel); channel= new NotificationChannel(CHANNEL_LOW, getString(R.string.channel_low), NotificationManager.IMPORTANCE_LOW); mgr.createNotificationChannel(channel); }
private void initContentChannel() { NotificationChannel channel= new NotificationChannel(CHANNEL_CONTENT, getString(R.string.channel_name_content), NotificationManager.IMPORTANCE_LOW); channel.setGroup(GROUP_UPDATES); mgr.createNotificationChannel(channel); }
private void createNotificationChannel() { if (TimberUtils.isOreo()) { CharSequence name = "Timber"; int importance = NotificationManager.IMPORTANCE_LOW; NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance); manager.createNotificationChannel(mChannel); } }
private void initContentChannel() { NotificationChannel channel= new NotificationChannel(CHANNEL_CONTENT, getString(R.string.channel_name_content), NotificationManager.IMPORTANCE_LOW); channel.setGroup(GROUP_UPDATES); mgr.createNotificationChannel(channel); }
private void initCoinsChannel() { NotificationChannel channel= new NotificationChannel(CHANNEL_COINS, getString(R.string.channel_name_coins), NotificationManager.IMPORTANCE_DEFAULT); channel.setGroup(GROUP_PROMO); mgr.createNotificationChannel(channel); } }
private void initCoinsChannel() { NotificationChannel channel= new NotificationChannel(CHANNEL_COINS, getString(R.string.channel_name_coins), NotificationManager.IMPORTANCE_DEFAULT); channel.setGroup(GROUP_PROMO); mgr.createNotificationChannel(channel); } }
private void setupNotificationChannel() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; String channelName = "Termux"; String channelDescription = "Notifications from Termux"; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName,importance); channel.setDescription(channelDescription); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.createNotificationChannel(channel); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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)); } mgr.notify(NOTIFY_ID, buildNormal().build()); finish(); }
private void initBattleChannel() { NotificationChannel channel= new NotificationChannel(CHANNEL_BATTLE, getString(R.string.channel_name_battle), NotificationManager.IMPORTANCE_HIGH); channel.setGroup(GROUP_UPDATES); channel.setShowBadge(true); mgr.createNotificationChannel(channel); }
private void initBattleChannel() { NotificationChannel channel= new NotificationChannel(CHANNEL_BATTLE, getString(R.string.channel_name_battle), NotificationManager.IMPORTANCE_HIGH); channel.setGroup(GROUP_UPDATES); channel.setShowBadge(true); mgr.createNotificationChannel(channel); }
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(); CHANNEL_ID = getPackageName()+".download"; mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ mNotifyManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID, getString(R.string.download_service), NotificationManager.IMPORTANCE_LOW)); } mDownloadManager = EhApplication.getDownloadManager(getApplicationContext()); mDownloadManager.setDownloadListener(this); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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)); } mgrCompat=NotificationManagerCompat.from(this); showWearOne(); showWearTwo(); showSummary(); finish(); }
public void initNotificationChannel() { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) { return; } final String id = getString(R.string.notification_channel_id); final CharSequence name = getString(R.string.notification_channel_name); final String description = getString(R.string.notification_channel_description); // Keep this below DEFAULT to avoid making noise on every notification update final int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel mChannel = new NotificationChannel(id, name, importance); mChannel.setDescription(description); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.createNotificationChannel(mChannel); setUpUpdateNotificationChannel(importance); }
@Override public void onCreate() { super.onCreate(); rxBluetooth=new RxBluetooth(getApplicationContext()); acceptConnections(); 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)); } startForeground(1338, buildForegroundNotification()); STATUS.postValue(Status.IS_RUNNING); }
@Test @Config(minSdk = Build.VERSION_CODES.O) public void createNotificationChannel() { notificationManager.createNotificationChannel(new NotificationChannel("id", "name", 1)); assertThat(shadowOf(notificationManager).getNotificationChannels()).hasSize(1); NotificationChannel channel = (NotificationChannel)shadowOf(notificationManager) .getNotificationChannel("id"); assertThat(channel.getName()).isEqualTo("name"); assertThat(channel.getImportance()).isEqualTo(1); }
@Test @Config(minSdk = Build.VERSION_CODES.O) public void deleteNotificationChannel() { final String channelId = "channelId"; assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isFalse(); notificationManager.createNotificationChannel(new NotificationChannel(channelId, "name", 1)); assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isFalse(); notificationManager.deleteNotificationChannel(channelId); assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isTrue(); assertThat(notificationManager.getNotificationChannel(channelId)).isNull(); // Per documentation, recreating a deleted channel should have the same settings as the old // deleted channel. notificationManager.createNotificationChannel( new NotificationChannel(channelId, "otherName", 2)); assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isFalse(); NotificationChannel channel = notificationManager.getNotificationChannel(channelId); assertThat(channel.getName()).isEqualTo("name"); assertThat(channel.getImportance()).isEqualTo(1); }