1

I have a push notifications coming into the app. However in api 24 the notification I show only appears in the status bar, but it doesn't display (like pop up), and its doesn't makes any sound.

I can't figure out why...

Here is my code:

 NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    int notificationId = 1;
    String channelId = "channel-03";
    String channelName = "Channel Name";
    int importance = 0;

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        Log.d(TAG, "android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N");
        importance = NotificationManager.IMPORTANCE_HIGH;
    }

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        Log.d(TAG, "android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O");
        NotificationChannel mChannel = new NotificationChannel(
                channelId, channelName, importance);
        notificationManager.createNotificationChannel(mChannel);
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId)
            .setSmallIcon(icon)
            .setContentTitle(title)
            .setContentText(message)
            .setAutoCancel(true);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    Intent intent1 = new Intent(context, MainActivity.class);

    stackBuilder.addNextIntent(intent1);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
    );
    mBuilder.setContentIntent(resultPendingIntent);


    notificationManager.notify(notificationId, mBuilder.build());
RJB
  • 1,704
  • 23
  • 50

1 Answers1

2

Needed to add to the builder:

.setDefaults(Notification.DEFAULT_ALL)

RJB
  • 1,704
  • 23
  • 50