31.10.2019, 14:49:45
//если версия андроид выше 8, то нужен канал
//также после этой версии не принято объявлять receiver от BroadcasatReceiver в манифесте, использовать JobScheduler
class Main{
private NotificationCompat.Builder getNotificationBuilder() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return new NotificationCompat.Builder(this);
else {
String channelId = "my_channel_id";
if (manager.getNotificationChannel(channelId) == null) {
NotificationChannel channel = new NotificationChannel(channelId, "Text for user", NotificationManager.IMPORTANCE_LOW);
manager.createNotificationChannel(channel);
}
return new NotificationCompat.Builder(this, channelId);
}
}
}