1

I have the same issue as this person: NotificationManager Error Android Studio

However I already have the solution implemented a while ago but this just stopped working. I am at build API 28 on a P10 with Oreo 8.0.0 installed. My code executes the notification logic, but I get this error:

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

and even though the icon for the notification pops up in the phone's notification bar, and tapping it opens my intent, the user gets no notification that this message arrived. I tried with the app in the foreground and in the background - both cases the small icon appears in the notification bar on top of the phone's UI, but no sound and no message.

Here is my code:

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());

What am I doing wrong?

pwnell
  • 171
  • 1
  • 11

0 Answers0