Notifications on Samsung S10 with Android 10 not working as expected

In my app it is important to display a notification at a certain point in time (as alarm for Accident detection if the user does not move anymore).

This alarm is working on all Android versions < 10 and is also working with the most Phones with android 10. One of the exceptions seams to be the Samsung S10 (Plus). With this Phone all notifications are for 1-2 minutes delayed if the Phone is in Sleep-Mode (Display is black)!

Here some code snippets to show the Problem.

First we tried to do it with an JobIntentService:

public class MyNotificationService extends JobIntentService {

    ....

    @Override
    protected void onHandleWork(@NonNull Intent intent) {

        NotificationType notificationType = NotificationType.valueOf(intent.getExtras().getInt(INTENT_EXTRA_NOTIFICATION_TYPE));
        boolean alarmingNotification = intent.getBooleanExtra(INTENT_EXTRA_NOTIFICATION_TYPE_ALARM, false);

        NotificationStorage notificationStorage = NotificationStorage.getInstance(context);
        notificationStorage.setPendingNotificationType(notificationType);

        intent.putExtra(INTENT_EXTRA_ALARM_NOTIFICATION, alarmingNotification);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.setClass(context, PopupOnLockScreenActivity.class);

        startActivity(notificationStarterIntent)
    }

    ...

}

Result: Popup does not open immediately as expected (1-2 minutes delayed)

Then i tried as workaround with Notification with a NotificationChannel (IMPORTANCE_HIGH) and NotificationCompat.Builder (PRIORITY_MAX):

public class MyNotificationService extends JobIntentService {

    ....

    @Override
    protected void onHandleWork(@NonNull Intent intent) {

        NotificationType notificationType = NotificationType.valueOf(intent.getExtras().getInt(INTENT_EXTRA_NOTIFICATION_TYPE));
        boolean alarmingNotification = intent.getBooleanExtra(INTENT_EXTRA_NOTIFICATION_TYPE_ALARM, false);

        NotificationStorage notificationStorage = NotificationStorage.getInstance(context);
        notificationStorage.setPendingNotificationType(notificationType);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            Log.d(TAG, "showPopupOnLockScreen XXX");


            String channelName = getResources().getString(R.string.safety_notification_channel_name);
            //String description = getString(R.string.channel_description);
            String description = "XXXXX";
            int importance = NotificationManager.IMPORTANCE_HIGH;
            android.app.NotificationChannel channel = new android.app.NotificationChannel(UepaaNetAndroidConstants.ANDROID_NOTIFICATION_CHANNEL_ID, channelName, importance);
            channel.setDescription(description);
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            android.app.NotificationManager notificationManager = getSystemService(android.app.NotificationManager.class);
            notificationManager.createNotificationChannel(channel);

            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channel.getId())
                    .setSmallIcon(R.drawable.notification_symptom_small)
                    .setContentTitle("My notification")
                    .setContentText("Hello World!")
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setContentIntent(pendingIntent)
                    .setAutoCancel(true);

            notificationManager.notify(123, builder.build());

        }

    }

    ...

}

Result: Notification will be not showed immediately as expected (1-2 minutes delayed)

I also tried to put the app in the lists to prevent the app from Battery-Manager and Sleep-Modes. (https://www.youtube.com/watch?v=npGw_r-v25k) But the problem still exists!

Can somebody help me? Our app is useless without notifications.

Hi,
How could you confirm that the problem is occurring due to notification manager? Are your sure the function which triggering the notification manager is working in time? You could check the issue using log in your function.

Hi. Thanks for your reply.

The intents and notification work as expected on other android devices, regardless of Android version. They also work as expected on the Samsung S10 running Android 9. It however does not work on the S10 running Android 10.

We have logged and debugged the issue for over a week with multiple developers. The intents are being delayed for some reason.

We also opened an issue directly with Samsung.

Thanks

@chiwi Any solution we got for this issue, as I am still observing this issue on my S10 Android Version 10 .

Hi

Yeah we did manage to solve the issue. For samsung devices on android 10+ we found the notifications to be delayed due to three issues:

  1. BroadcastReciever/WakefulIntents without devloper defined Wakelocks will cause the notifcation to be delayed.
  2. AlarmManager.setExactAndAllowWhileIdle is delayed on Samsung Devices. AlarmManager.setAlarmClock with the corrrect Reciever/Intents mentioned above must be used.
  3. Full screen activities or fragments can no longer be displayed on the lock screen if the App has been in the background for a period of time.

We addressed these issues by:

  1. Use the JobIntentService from AndroidX. The use of BroadcastRecievers for wakeful work has long been deprecated. Use Best practice soltuions with JobIntentService or WorkManager.
  2. There are no known solutions here, apart from the workaround to use setAlarmClock.
  3. There are two known solutions here, only one which has been proven to work.
  • Proven: Use the “advanced” permission: “android.permission.SYSTEM_ALERT_WINDOW”
  • Flakey in our tests: Use Android Notifications with a Channel PRIORITY_HIGH or PRIORITY_MAX. Start the full screen activity/fragment with a PendingIntent.

Hope this helps.

Cheers

I think the reason for the flakey one is that the notification channel’s importance cannot be changed programmatically once it is created. It is written in the Android Document:
After you create a notification channel, you cannot change the notification behaviors—the user has complete control at that point. Though you can still change a channel’s name and description.

And when a user disables the channel and enables it again, the channel importance is set to IMPORTANCE_DEFAULT, but not PRIORITY_HIGH or PRIORITY_MAX.

Therefore if there is something that can only be done with channels of importance PRIORITY_HIGH or PRIORITY_MAX, it will become not working anymore once the user changes the notification settings.