Вибрация и мелодия канала уведомлений не работают

У меня проблема с каналом уведомлений, который не работает для Vibration и Custom Ringtone. Я надеюсь, что все настроил правильно, но все же, только Push-уведомление получено без вибрации и звука. Я позвонил уведомлению до вызова notify() Нажмите здесь, чтобы узнать больше

Мой вопрос:

  1. Это какие-то дополнительные настройки, которые я должен сделать для Custome Ringtone и Vibration?

  2. Любая проблема с AudioAttributes?

Вот мой код

Uri uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + mContext.getPackageName() + "/" + R.raw.sms_ringtone);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_stat_dog) .setContentTitle(context.getString(R.string.app_name)).setContentText(message)          .setOngoing(false).setAutoCancel(true).setDefaults(Notification.DEFAULT_LIGHTS.setPriority(Notification.PRIORITY_MAX).setLights(0xff00ff00, 300, 1000).setVibrate(new long[]{
                        1000, 1000, 1000, 1000, 1000
                }).setStyle(new NotificationCompat.BigTextStyle().bigText(message));

  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel notificationChannel = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID, Constants.NOTIFICATION_CHANNEL_NAME, importance);
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.enableVibration(true);
        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .build();

        notificationChannel.setSound(uri, audioAttributes);
        notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        assert notificationManager != null;
        mBuilder.setChannelId(Constants.NOTIFICATION_CHANNEL_ID);
        notificationManager.createNotificationChannel(notificationChannel);
    }
 mBuilder.setSound(getRingtoneUri());
 mBuilder.setContentIntent(pendingIntent);
 notificationManager.notify(gcmMessageId, mBuilder.build());

0 ответов

Другие вопросы по тегам