Вам необходимо создать каналы уведомлений. Вот метод Util, который я создал для этой цели:
public void createChannel(String channelId, CharSequence channelName, int importance) {
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
channel = new NotificationChannel(channelId, channelName, importance);
channel.enableLights(true);
channel.setLightColor(Color.RED);
channel.enableVibration(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
notificationManager.createNotificationChannel(channel);
}
, где channel
и notificationManager
:
private NotificationChannel channel;
private NotificationManager notificationManager;
Просто назовите каналы с помощью channelId
и введите их описание, используя channelName
Вот Javado c для NotificationChannel
:
/**
* Creates a notification channel.
*
* @param id The id of the channel. Must be unique per package. The value may be truncated if
* it is too long.
* @param name The user visible name of the channel. You can rename this channel when the system
* locale changes by listening for the {@link Intent#ACTION_LOCALE_CHANGED}
* broadcast. The recommended maximum length is 40 characters; the value may be
* truncated if it is too long.
* @param importance The importance of the channel. This controls how interruptive notifications
* posted to this channel are.
*/
public NotificationChannel(String id, CharSequence name, @Importance int importance) {
this.mId = getTrimmedString(id);
this.mName = name != null ? getTrimmedString(name.toString()) : null;
this.mImportance = importance;
}