在某些设备上,我遇到一个奇怪的问题: 我无法确定确切的时间,但几天后或可能在收到大量通知后,这些人变得沉默了。
通知照常显示,设备振动但完全没有声音。
还原声音的唯一方法是卸载并重新安装该应用程序。
当应用程序处于“静默”状态时,更改notification_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());