@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(); }
@TargetApi(Build.VERSION_CODES.O) public static void deleteNotificationChannel(Context context, Account account) { if (AndroidHelper.isOreoOrGreater()) { final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.deleteNotificationChannelGroup(account.getAccountHash()); } } }
/** * 指定したNotificationGroupを削除する * @param groupId */ @SuppressLint("NewApi") protected void releaseNotificationGroup(@NonNull final String groupId) { if (!TextUtils.isEmpty(groupId) && BuildCheck.isOreo()) { final NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); try { manager.deleteNotificationChannelGroup(groupId); } catch (final Exception e) { Log.w(TAG, e); } } }