Уведомления Firebase не звонят на Redmi Note 8T - PullRequest
1 голос
/ 08 апреля 2020

Это тот случай использования: когда я получаю уведомление на канале «channel1», мне хотелось бы: - если приложение предварительно установлено: ActivityTest открывается автоматически - если приложение является фоновым: я получаю уведомление с указанным звуком (я также указал имя звука на бэкенде) Правильно ли указан мой код? Я протестировал его на 3 устройствах, и на двух он работает правильно, в то время как на третьем (Redmi Note 8T) нет ни звука, ни вибрации, хотя я предоставил уведомления и разрешения на звук из настроек смартфона. Как видно из прокомментированного кода, я пробовал разные комбинации, но ничего не изменилось. В чем может быть проблема?

    String CHANNEL_ID = "channel1";
CharSequence name = "channel1";
String Description = "This is my channel";
int NOTIFICATION_ID = 234;

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

    //Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    Uri defaultSoundUri = Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.soundname);

    // Since android Oreo notification channel is needed.
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_HIGH;
        AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder();
                //.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING)
                //.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
                //.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                //.setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
                //.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED);

        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, name, importance);
        notificationChannel.setDescription(Description);
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.enableVibration(true);
        notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        notificationChannel.setSound(defaultSoundUri, audioAttributesBuilder.build());
        notificationChannel.setShowBadge(true);

        if (notificationManager != null) {
            notificationManager.createNotificationChannel(notificationChannel);
        }
    }

    Intent intent = new Intent(this, ActivityTest.class);
    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(Constant.id, id);


    if(Applicazione.getInstance().isAppForegrounded()) {
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } else {
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setColor(getResources().getColor(R.color.acqua_marina))
                .setSmallIcon(R.drawable.icon_notifica)
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setContentIntent(pendingIntent)
                .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})
                //.setSound(defaultSoundUri)
                //.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setSound(defaultSoundUri, AudioManager.STREAM_RING)
                //.setSound(defaultSoundUri, AudioManager.RINGER_MODE_NORMAL)
                .setPriority(NotificationCompat.PRIORITY_HIGH);
                //.setCategory(NotificationCompat.CATEGORY_CALL);
                //.setFullScreenIntent(pendingIntent, true);

        if (notificationManager != null) {
            notificationManager.notify(NOTIFICATION_ID, builder.build());
        }
    }
...