Example usage for android.app NotificationManager createNotificationChannelGroup

List of usage examples for android.app NotificationManager createNotificationChannelGroup

Introduction

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

Prototype

public void createNotificationChannelGroup(@NonNull NotificationChannelGroup group) 

Source Link

Document

Creates a group container for NotificationChannel objects.

Usage

From source file:com.ruesga.rview.misc.NotificationsHelper.java

@TargetApi(Build.VERSION_CODES.O)
public static void createNotificationChannel(Context context, Account account) {
    if (AndroidHelper.isApi26OrGreater()) {
        final String defaultChannelName = context.getString(R.string.notifications_default_channel_name,
                account.getRepositoryDisplayName(), account.getAccountDisplayName());
        final NotificationManager nm = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        nm.createNotificationChannelGroup(
                new NotificationChannelGroup(account.getAccountHash(), defaultChannelName));

        NotificationChannel channel = new NotificationChannel(account.getAccountHash(), defaultChannelName,
                NotificationManager.IMPORTANCE_DEFAULT);
        channel.setDescription(context.getString(R.string.notifications_default_channel_description));
        channel.enableVibration(true);/*from  w w w  .ja v a2 s .  c  o  m*/
        channel.enableLights(true);
        channel.setLightColor(ContextCompat.getColor(context, R.color.primaryDark));
        channel.setShowBadge(true);
        channel.setGroup(account.getAccountHash());
        nm.createNotificationChannel(channel);
    }
}

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

public static void createNotificationChannelsForAccount(@NonNull AccountEntity account,
        @NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

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

        String[] channelIds = new String[] { CHANNEL_MENTION + account.getIdentifier(),
                CHANNEL_FOLLOW + account.getIdentifier(), CHANNEL_BOOST + account.getIdentifier(),
                CHANNEL_FAVOURITE + account.getIdentifier() };
        int[] channelNames = { R.string.notification_channel_mention_name,
                R.string.notification_channel_follow_name, R.string.notification_channel_boost_name,
                R.string.notification_channel_favourite_name };
        int[] channelDescriptions = { R.string.notification_channel_mention_descriptions,
                R.string.notification_channel_follow_description,
                R.string.notification_channel_boost_description,
                R.string.notification_channel_favourite_description };

        List<NotificationChannel> channels = new ArrayList<>(4);

        NotificationChannelGroup channelGroup = new NotificationChannelGroup(account.getIdentifier(),
                account.getFullName());//from   w  ww .j  a v a 2s .  c  o  m

        //noinspection ConstantConditions
        notificationManager.createNotificationChannelGroup(channelGroup);

        for (int i = 0; i < channelIds.length; i++) {
            String id = channelIds[i];
            String name = context.getString(channelNames[i]);
            String description = context.getString(channelDescriptions[i]);
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel(id, name, importance);

            channel.setDescription(description);
            channel.enableLights(true);
            channel.setLightColor(0xFF2B90D9);
            channel.enableVibration(true);
            channel.setShowBadge(true);
            channel.setGroup(account.getIdentifier());
            channels.add(channel);
        }

        //noinspection ConstantConditions
        notificationManager.createNotificationChannels(channels);

    }
}