Уведомления (пробуждение) на Samsung S10 с Android 10 не работает должным образом - PullRequest
3 голосов
/ 23 марта 2020

В моем приложении важно отображать уведомление в определенный момент времени (как сигнал тревоги для обнаружения несчастного случая, если пользователь больше не перемещается).

Этот сигнал тревоги работает на всех Android версиях <10, а также работает с большинством телефонов с android 10. Одним из исключений является Samsung S10 (Plus). С этим телефоном все уведомления задерживаются на 1-2 минуты, если телефон находится в спящем режиме (дисплей черный)! </p>

Вот некоторые фрагменты кода для отображения проблемы.

Сначала мы попробовали сделать это с помощью 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)
    }

    ...

}

Результат: всплывающее окно не открывается сразу, как ожидалось (задержка составляет 1-2 минуты)

Затем я попытался в качестве обходного пути с NotificationChannel (IMPORTANCE_HIGH) ) и 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());

        }

    }

    ...

}

Результат: уведомление не будет отображаться немедленно, как ожидалось (задержка 1-2 минуты)

Wake-Up не работает на Samsung S10

Я также пытался поместить приложение в списки, чтобы приложение не работало с Battery-Manager и Sleep-Modes. (https://www.youtube.com/watch?v=npGw_r-v25k) Но проблема все еще существует!

Может ли кто-нибудь мне помочь? Наше приложение бесполезно без уведомлений.

Чтобы воспроизвести эту проблему, я поместил проект на github: https://github.com/gatschet/androidAlarmTest.git

...