Android NotificationManager не предупреждает пользователя

У меня та же проблема, что и у этого человека: Ошибка NotificationManager Android Studio

Однако у меня уже есть решение, реализованное некоторое время назад, но оно просто перестало работать. Я собираю API 28 на P10 с установленным Oreo 8.0.0. Мой код выполняет логику уведомления, но я получаю эту ошибку:

E/NotificationManager: notifyAsUser: tag=null, id=-1522221101, user=UserHandle{0}

и хотя значок уведомления появляется на панели уведомлений телефона, и при нажатии на него открывается мое намерение, пользователь не получает уведомления о получении этого сообщения. Я пробовал с приложением на переднем плане и в фоновом режиме - в обоих случаях маленький значок появляется на панели уведомлений в верхней части пользовательского интерфейса телефона, но нет ни звука, ни сообщения.

Вот мой код:

Intent intent = new Intent(getContext(), AuthRequestActivity.class);
intent.putExtra(getContext().getPackageName().concat(".param0"), code);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  NotificationChannel channel = new NotificationChannel("default", "My Channel", NotificationManager.IMPORTANCE_DEFAULT);
  channel.setDescription("ALP Push Notifications");
  notificationManager.createNotificationChannel(channel);
}

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext(), "default").setSmallIcon(R.drawable.app_icon)
    .setContentTitle("Authentication Request").setContentText(code)
    .setAutoCancel(true).setSound(defaultSoundUri)
    .setContentIntent(pendingIntent);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getContext());
// Below alternative makes no difference
//    NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build());

Что я делаю не так?


person pwnell    schedule 14.01.2020    source источник
comment
Вы пробовали builder.setDefault()?   -  person Ilia Kuzmin    schedule 14.01.2020