@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); }
@TargetApi(26) private void deleteNotificationChannel() { getNotificationManager().deleteNotificationChannel(CHANNEL_ID); }
@RequiresApi(api = Build.VERSION_CODES.O) private synchronized void deleteNotificationChannel() { if (mNotificationManager != null) { mNotificationManager.deleteNotificationChannel(MobiComKitConstants.AL_PUSH_NOTIFICATION); Utils.printLog(context, TAG, "Deleted notification channel"); } }
@RequiresApi(api = Build.VERSION_CODES.O) private synchronized void deleteSilentNotificationChannel() { if (mNotificationManager != null) { mNotificationManager.deleteNotificationChannel(MobiComKitConstants.AL_SILENT_NOTIFICATION); Utils.printLog(context, TAG, "Deleted silent notification channel"); } }
@RequiresApi(api = Build.VERSION_CODES.O) private synchronized void deleteAppNotificationChannel() { if (mNotificationManager != null) { mNotificationManager.deleteNotificationChannel(MobiComKitConstants.AL_APP_NOTIFICATION); Utils.printLog(context, TAG, "Deleted app notification channel"); } }
private void setChannel() { if (SDK_INT >= Build.VERSION_CODES.O) { notificationManager.deleteNotificationChannel(LAST_CHANNEL_ID); CHANNEL_SEQUENCE++; CHANNEL_ID = CHANNEL_ID + CHANNEL_SEQUENCE; CHANNEL_NAME = CHANNEL_NAME + CHANNEL_SEQUENCE; LAST_CHANNEL_ID = CHANNEL_ID; NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); notificationChannel.enableVibration(false); notificationChannel.setVibrationPattern(new long[]{0}); notificationManager.createNotificationChannel(notificationChannel); } }
/** * 指定したNotificationChannelを破棄する * @param channelId */ @SuppressLint("NewApi") protected void releaseNotificationChannel(@Nullable final String channelId) { if (!TextUtils.isEmpty(channelId) && BuildCheck.isOreo()) { final NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); try { manager.deleteNotificationChannel(channelId); } catch (final Exception e) { Log.w(TAG, e); } } }
@Override public void onDestroy() { log("Service onDestroy"); if (mNotificationChannel != null) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.deleteNotificationChannel(CHANNEL_ID); } }
@TargetApi(26) public static void cleanAllNotificationChannels() { // TODO this isn't right yet List<NotificationChannel> channels = getNotifManager().getNotificationChannels(); for (NotificationChannel channel : channels) { getNotifManager().deleteNotificationChannel(channel.getId()); } List<NotificationChannelGroup> groups = getNotifManager().getNotificationChannelGroups(); for (NotificationChannelGroup group : groups) { getNotifManager().deleteNotificationChannel(group.getId()); } }
@TargetApi(26) public static void cleanAllNotificationChannels() { // TODO this isn't right yet List<NotificationChannel> channels = getNotifManager().getNotificationChannels(); for (NotificationChannel channel : channels) { getNotifManager().deleteNotificationChannel(channel.getId()); } List<NotificationChannelGroup> groups = getNotifManager().getNotificationChannelGroups(); for (NotificationChannelGroup group : groups) { getNotifManager().deleteNotificationChannel(group.getId()); } }
private void createAlarmChannel(String uri) { Log.e("KCA-A", "recv: " + uri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String soundKind = getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_SOUND_KIND); boolean isVibrate = soundKind.equals(getString(R.string.sound_kind_value_mixed)) || soundKind.equals(getString(R.string.sound_kind_value_vibrate)); notificationManager.deleteNotificationChannel(ALARM_CHANNEL_ID); while (!alarmChannelList.isEmpty()) { notificationManager.deleteNotificationChannel(alarmChannelList.poll()); } AudioAttributes.Builder attrs = new AudioAttributes.Builder(); attrs.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION); attrs.setUsage(AudioAttributes.USAGE_NOTIFICATION); String channel_name = createAlarmId(uri, isVibrate); alarmChannelList.add(channel_name); NotificationChannel channel = new NotificationChannel(alarmChannelList.peek(), getStringWithLocale(R.string.notification_appinfo_title), NotificationManager.IMPORTANCE_HIGH); channel.setSound(Uri.parse(uri), attrs.build()); channel.enableVibration(isVibrate); channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); notificationManager.createNotificationChannel(channel); } }
@Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) { int position = viewHolder.getAdapterPosition(); int index = position - getUserRulesStartIndex(); NotificationRule rule = mRules.remove(index); notifyItemRemoved(position); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mgr = (NotificationManager) viewHolder.itemView.getContext() .getSystemService(Context.NOTIFICATION_SERVICE); mgr.deleteNotificationChannel(rule.settings.notificationChannelId); } if (mRules.size() == 0) notifyItemInserted(getUserRulesStartIndex() + 1); // the tip Snackbar.make(viewHolder.itemView, R.string.notification_custom_rule_deleted, Snackbar.LENGTH_SHORT) .setAction(R.string.action_undo, (View v) -> { int newIndex = Math.min(index, mRules.size()); mRules.add(newIndex, rule); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ChannelNotificationManager.createChannel( viewHolder.itemView.getContext(), rule); if (mRules.size() == 1) notifyItemRemoved(getUserRulesStartIndex() + 1); // the tip notifyItemInserted(newIndex + getUserRulesStartIndex()); mHasChanges = true; }) .show(); mHasChanges = true; }
private void createServiceChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int priority = IMPORTANCE_DEFAULT; if (getBooleanPreferences(getApplicationContext(), PREF_KCA_SET_PRIORITY)) { priority = IMPORTANCE_HIGH; } NotificationChannel channel = new NotificationChannel(getServiceChannelId(), SERVICE_CHANNEL_NAME, priority); channel.enableVibration(false); channel.setSound(null, null); channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); notifiManager.deleteNotificationChannel(SERVICE_CHANNEL_ID_OLD); notifiManager.createNotificationChannel(channel); } }
((notificationChannel.getImportance() == NotificationManager.IMPORTANCE_LOW) || (AppPreference.isVibrateEnabled(context) && (notificationChannel.getVibrationPattern() == null)))) { notificationManager.deleteNotificationChannel("yourLocalWeather"); createNotification = true;
android.app.NotificationManager mgr = (android.app.NotificationManager) getSystemService(NOTIFICATION_SERVICE); mgr.deleteNotificationChannel(mEditingRule.settings.notificationChannelId); mEditingRule.settings.notificationChannelId = null;