На некоторых устройствах у меня возникает странная проблема: я не могу точно определить, когда, но через несколько дней или, может быть, после ряда уведомлений они отключаются.
Уведомления отображаются как обычно, устройство вибрирует но звука нет вообще.
Единственный способ восстановить звуки - это удалить и переустановить приложение.
Когда приложение находится в «беззвучном» состоянии, также не стоит менять уведомление_channel_id.
Любая помощь приветствуется.
Это мой код:
NOTIFICATION_CHANNEL_ID="message01";
NOTIFICATION_CHANNEL_NAME="Orders";
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext, NOTIFICATION_CHANNEL_ID);
mBuilder.setContentTitle(title);
mBuilder.setContentText(message);
mBuilder.setAutoCancel(false);
mBuilder.setSound(uri);
mBuilder.setContentIntent(resultPendingIntent);
mBuilder.setPriority(NotificationManager.IMPORTANCE_HIGH);
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
mBuilder.setColor(Color.WHITE);
mBuilder.setLargeIcon(bigPicture);
mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build();
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.enableVibration(true);
notificationChannel.setSound(uri, audioAttributes);
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
assert mNotificationManager != null;
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
mNotificationManager.createNotificationChannel(notificationChannel);
}
assert mNotificationManager != null;
mNotificationManager.notify(0 , mBuilder.build());