0

Here's my add notification method:

private void addNotification() {
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher_background)
                    .setContentTitle("Notifications Example")
                    .setContentText("This is a test notification");

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    // Add as notification
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(0, builder.build());
}

In the onCreate method, I have addNotification(); as I want to the notification to happen when the app starts.

SOLVED: Notifications fail to display in Android Oreo (API 26)

  • I suggest that you use the Android Studio debugger to step through your code. First you should verify that this method is called. – Code-Apprentice Dec 13 '17 at 16:02
  • I printed to the the log inside the method and it showed, so yes the method is called. – NiallRedmond Dec 13 '17 at 16:11
  • continue to debug the method to make sure each variable contains a reasonable value. – Code-Apprentice Dec 13 '17 at 16:13
  • It says W/Notification: Use of stream types is deprecated for operations other than volume control W/Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case Could this be causing it? – NiallRedmond Dec 13 '17 at 16:37
  • Which line causes that warning? Nothing in the code you posted here uses `AudioAttributes` nor `setSound()`. – Code-Apprentice Dec 13 '17 at 16:37
  • Hi Code apparentice, thanks for your help. Solved using this thread https://stackoverflow.com/questions/45395669/notifications-fail-to-display-in-android-oreo-api-26 – NiallRedmond Dec 13 '17 at 16:44
  • I will mark this as a duplicate then. Good luck! – Code-Apprentice Dec 13 '17 at 17:16
  • Niall, please confirm the dupe in the banner above the question – Tim Dec 13 '17 at 17:18

0 Answers0