Android: Как программно отключить канал уведомлений? - PullRequest
0 голосов
/ 20 марта 2020

У меня есть работающая реализация, чтобы проверить, включен ли канал.

Но есть ли какой-нибудь возможный способ отключить канал уведомлений программно?

Как проверить, включен ли канал:

    /**
     * Get the setting a user has applied to the notification channel.
     * If the android API level is < 26, it will return true if all notification
     * are enabled in general, false otherwise.
     *
     * @return true if the channel is enabled, false otherwise
     */
    public static boolean isChannelEnabled(String channelId) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            final NotificationManager notificationManager = App.get().getSystemService(NotificationManager.class);
            if (notificationManager == null) {
                return true;
            } else {
                final NotificationChannel c = notificationManager.getNotificationChannel(channelId);
                final boolean overallEnabled = notificationManager.areNotificationsEnabled();
                return overallEnabled && c != null && NotificationManager.IMPORTANCE_NONE != c.getImportance();
            }
        } else {
            return NotificationManagerCompat.from(App.get()).areNotificationsEnabled();
        }
    }


...