android уведомление не задерживается на 60 секунд, а срабатывает через 3 секунды - PullRequest
0 голосов
/ 02 августа 2020

Я пытаюсь подписаться на этот пост и этот пост . Однако в моем реализованном коде уведомление срабатывает в течение 3 секунд, хотя я установил задержку на 60000 мс. Мне интересно, что я не так. Вот мой код

private void displayNotifiation(Contact contact, byte[] img) {
    int notificationId = contact.hashCode();
    Log.d(TAG, "onClick 2: put info="+contact.getName()+" notifId:"+notificationId);

    Bitmap bitmap = BitmapFactory.decodeByteArray(img, 0, img.length);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, MainActivity.CHANNEL_ID)
            .setSmallIcon(R.mipmap.logo2)
            .setContentTitle("It's time to reach out to "+contact.getName())
            .setContentText("For your health")
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setLargeIcon(bitmap)
            .setAutoCancel(false);

    Intent intent = new Intent(mContext, ActivityNotificationLanding.class);
    Uri uri = Uri.parse("http://notexist.mykeepintouch.app/contactid/"+contact.getId());
    intent.setData(uri);
    //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    gson.putExtra(intent, IntentFlashStore.CONTACT_KEY, contact);
    NotificationInfo info = new NotificationInfo();
    info.setId(notificationId);
    gson.putExtra(intent, IntentFlashStore.NOTIFICATION_INFO, info);

    PendingIntent activity = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(activity);

    Notification notification = builder.build();

    Intent notificationIntent = new Intent(mContext, MyNotificationPublisher.class);
    notificationIntent.putExtra(MyNotificationPublisher.NOTIFICATION_ID, notificationId);
    notificationIntent.putExtra(MyNotificationPublisher.NOTIFICATION, notification);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, notificationId, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    long futureInMillis = SystemClock.elapsedRealtime() + 60000;
    AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, futureInMillis, pendingIntent);
}

Хмммм,

ПОБОЧНЫЙ ВОПРОС: Будет ли это работать при перезагрузке телефона? Я читал что-то о BootReceiver и не уверен, нужно ли мне это делать. Android 24 +

...