Example usage for android.app NotificationManager deleteNotificationChannel

List of usage examples for android.app NotificationManager deleteNotificationChannel

Introduction

In this page you can find the example usage for android.app NotificationManager deleteNotificationChannel.

Prototype

public void deleteNotificationChannel(String channelId) 

Source Link

Document

Deletes the given notification channel.

Usage

From source file:com.keylesspalace.tusky.util.NotificationHelper.java

public static void deleteLegacyNotificationChannels(@NonNull Context context,
        @NonNull AccountManager accountManager) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        // used until Tusky 1.4
        //noinspection ConstantConditions
        notificationManager.deleteNotificationChannel(CHANNEL_MENTION);
        notificationManager.deleteNotificationChannel(CHANNEL_FAVOURITE);
        notificationManager.deleteNotificationChannel(CHANNEL_BOOST);
        notificationManager.deleteNotificationChannel(CHANNEL_FOLLOW);

        // used until Tusky 1.7
        for (AccountEntity account : accountManager.getAllAccountsOrderedByActive()) {
            notificationManager.deleteNotificationChannel(CHANNEL_FAVOURITE + " " + account.getIdentifier());
        }//from  w ww . j a  v  a  2s .com
    }
}

From source file:nu.yona.app.utils.AppUtils.java

@TargetApi(Build.VERSION_CODES.O)
public static void removeOldPersistentNotificationFromChannel(Context context) {
    android.app.NotificationManager notificationManager = context
            .getSystemService(android.app.NotificationManager.class);
    notificationManager.deleteNotificationChannel(AppConstant.OLD_YONA_SERVICE_CHANNEL_ID);
}

From source file:im.vector.notifications.NotificationUtils.java

/**
 * Add a notification groups.//from   w w  w .  j a  va 2s.  com
 *
 * @param context the context
 */
@SuppressLint("NewApi")
public static void addNotificationChannels(Context context) {
    if (Build.VERSION.SDK_INT < 26) {
        return;
    }

    if (null == NOISY_NOTIFICATION_CHANNEL_NAME) {
        NOISY_NOTIFICATION_CHANNEL_NAME = context.getString(R.string.notification_noisy_notifications);
    }

    if (null == SILENT_NOTIFICATION_CHANNEL_NAME) {
        SILENT_NOTIFICATION_CHANNEL_NAME = context.getString(R.string.notification_silent_notifications);
    }

    if (null == CALL_NOTIFICATION_CHANNEL_NAME) {
        CALL_NOTIFICATION_CHANNEL_NAME = context.getString(R.string.call);
    }

    if (null == LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_NAME) {
        LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_NAME = context
                .getString(R.string.notification_listen_for_events);
    }

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    // A notification channel cannot be updated :
    // it must be deleted and created with another channel id
    if ((null == NOISY_NOTIFICATION_CHANNEL_ID)) {
        List<NotificationChannel> channels = notificationManager.getNotificationChannels();

        for (NotificationChannel channel : channels) {
            if (channel.getId().startsWith(NOISY_NOTIFICATION_CHANNEL_ID_BASE)) {
                NOISY_NOTIFICATION_CHANNEL_ID = channel.getId();
            }
        }
    }

    if (null != NOISY_NOTIFICATION_CHANNEL_ID) {
        NotificationChannel channel = notificationManager.getNotificationChannel(NOISY_NOTIFICATION_CHANNEL_ID);
        Uri notificationSound = channel.getSound();
        Uri expectedSound = PreferencesManager.getNotificationRingTone(context);

        // the notification sound has been updated
        // need to delete it, to create a new one
        // else the sound won't be updated
        if (((null == notificationSound) ^ (null == expectedSound)) || ((null != notificationSound)
                && !TextUtils.equals(notificationSound.toString(), expectedSound.toString()))) {
            notificationManager.deleteNotificationChannel(NOISY_NOTIFICATION_CHANNEL_ID);
            NOISY_NOTIFICATION_CHANNEL_ID = null;
        }
    }

    if (null == NOISY_NOTIFICATION_CHANNEL_ID) {
        NOISY_NOTIFICATION_CHANNEL_ID = NOISY_NOTIFICATION_CHANNEL_ID_BASE + System.currentTimeMillis();

        NotificationChannel channel = new NotificationChannel(NOISY_NOTIFICATION_CHANNEL_ID,
                NOISY_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
        channel.setDescription(NOISY_NOTIFICATION_CHANNEL_NAME);
        channel.setSound(PreferencesManager.getNotificationRingTone(context), null);
        channel.enableVibration(true);
        notificationManager.createNotificationChannel(channel);
    }

    if (null == notificationManager.getNotificationChannel(SILENT_NOTIFICATION_CHANNEL_NAME)) {
        NotificationChannel channel = new NotificationChannel(SILENT_NOTIFICATION_CHANNEL_ID,
                SILENT_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
        channel.setDescription(SILENT_NOTIFICATION_CHANNEL_NAME);
        channel.setSound(null, null);
        notificationManager.createNotificationChannel(channel);
    }

    if (null == notificationManager.getNotificationChannel(LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID)) {
        NotificationChannel channel = new NotificationChannel(LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID,
                LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_MIN);
        channel.setDescription(LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_NAME);
        channel.setSound(null, null);
        notificationManager.createNotificationChannel(channel);
    }

    if (null == notificationManager.getNotificationChannel(CALL_NOTIFICATION_CHANNEL_ID)) {
        NotificationChannel channel = new NotificationChannel(CALL_NOTIFICATION_CHANNEL_ID,
                CALL_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
        channel.setDescription(CALL_NOTIFICATION_CHANNEL_NAME);
        channel.setSound(null, null);
        notificationManager.createNotificationChannel(channel);
    }
}

From source file:com.irccloud.android.data.collection.NotificationsList.java

public void pruneNotificationChannels() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager nm = ((NotificationManager) IRCCloudApplication.getInstance()
                .getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE));

        for (NotificationChannelGroup c : nm.getNotificationChannelGroups()) {
            try {
                if (ServersList.getInstance().getServer(Integer.valueOf(c.getId())) == null)
                    nm.deleteNotificationChannelGroup(c.getId());
            } catch (NumberFormatException e) {
            }//w ww .  j av a 2 s  . c o  m
        }

        for (NotificationChannel c : nm.getNotificationChannels()) {
            try {
                if (BuffersList.getInstance().getBuffer(Integer.valueOf(c.getId())) == null)
                    nm.deleteNotificationChannel(c.getId());
            } catch (NumberFormatException e) {
            }
        }
    }
}