Одно и то же уведомление Android отображается снова и снова для двух человек - PullRequest
2 голосов
/ 17 января 2020

Два человека сообщают, что уведомления отображаются снова и снова. Один из них видел уведомление 80 раз. Есть сотни пользователей, и это только двое с этой проблемой, и я не могу воссоздать ее. Одним из устройств является Samsung A70, а другое неизвестно. Как мне диагностировать и исправить это для этих двух людей, не имеющих доступа к своим устройствам?

MyFirebaseMessagingService:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
        Bundle myExtrasBundle = new Bundle();

        Map<String, String> notificationMap = remoteMessage.getData();
        nhMessage = notificationMap.get(MESSAGE_KEY);

        myExtrasBundle.putString(MESSAGE_KEY, nhMessage);
        FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
        Job myJob = dispatcher.newJobBuilder()
                .setService(MyJobService.class)
                .setRecurring(false)
                .setLifetime(Lifetime.FOREVER)
                .setTrigger(Trigger.executionWindow(0, 0))
                .setReplaceCurrent(true)
                .setExtras(myExtrasBundle)
                .build();

        dispatcher.mustSchedule(myJob);
   }

MyJobService:

@Override
public boolean onStartJob(JobParameters job) {
    Bundle a = job.getExtras();
    String nhMessage = a.getString(MyFirebaseMessagingService.MESSAGE_KEY);
    sendNotification(nhMessage);
}


public void sendNotification(String message) {
    notificationManager = (NotificationManager)
                getSystemService(Context.NOTIFICATION_SERVICE);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.putExtra(NotificationHelper.MESSAGE, message);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationID, notificationIntent, 0);
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    String channelId = "testapp";
    CharSequence channelName = "Test App Channel";
    NotificationChannel notificationChannel = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_HIGH;
        notificationChannel = new NotificationChannel(channelId, channelName, importance);
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(getResources().getColor(R.color.colorPrimary));
        notificationChannel.enableVibration(true);
        notificationManager.createNotificationChannel(notificationChannel);
    }

    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this, channelId)
                    .setAutoCancel(true)
                    .setTicker(message)
                    .setContentTitle(getResources().getString(R.string.app_name))
                    .setContentText(message)
                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                    .setSmallIcon(R.drawable.ic_notification)
                    .setSound(defaultSoundUri)
                    .setLights(ContextCompat.getColor(this, R.color.colorPrimary), 500, 2000)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                    .setContentIntent(pendingIntent).setPriority(Notification.PRIORITY_MAX)
                    .setColor(getResources().getColor(R.color.colorPrimary));

    notificationManager.notify(notificationID, builder.build());
}

РЕДАКТИРОВАТЬ Как кто-то предложил, я начал сохранять ключ в общих настройках и проверять его, чтобы в следующий раз он не достиг этого пункта. Проблема все еще происходит.

...