Постоянно сталкиваюсь с проблемами из-за постоянно устаревающих методов и прочих изменений.
В этот раз телефон отказывался показывать уведомления, перекопала лог, ошибок никаких не выдало. Оказалось проблема в версии андройда.
Для API 26+ требуется создать канал уведомлений, иначе они уходят в dev/null.
Код: Выделить всё
void sendNotif(int id, PendingIntent pIntent){
createNotificationChannel(this);
Notification builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setContentTitle("title" + id)
.setContentText("content" + id)
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setContentIntent(pIntent).build();
nm.notify(id, builder);
}
Код: Выделить всё
public static final String NOTIFICATION_CHANNEL_ID = "NOTIFICATION_CHANNEL";
public static void createNotificationChannel(final Context context) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "name";
String description = "description";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
channel.setDescription(description);
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}