偶尔,在创建通知通道时,我们会在某些设备上收到带有空本地化消息的IllegalArgumentException。我找到了this答案,但是频道名称是100%确定的不是"",所以不是本例中的问题。它对几乎所有用户都有效,但有时会为某个用户抛出此异常。我们似乎也不能将它与设备类型或特定的Android版本联系起来。
创建通道的代码:
public void createNotificationChannel(String label, String description, int importance) {
// Create the NotificationChannel only on API 26+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(label, label, importance);
channel.setDescription(description);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
}异常的堆栈跟踪:
android.os.Parcel.createException(Parcel.java:2078)
android.os.Parcel.readException(Parcel.java:2042)
android.os.Parcel.readException(Parcel.java:1990)
android.app.INotificationManager$Stub$Proxy.createNotificationChannels(INotificationManager.java:3205)
android.app.NotificationManager.createNotificationChannels(NotificationManager.java:713)
android.app.NotificationManager.createNotificationChannel(NotificationManager.java:701)有谁有什么想法吗?我很乐意解决这个问题!
发布于 2021-12-03 13:26:32
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
// Configure the notification channel
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setVibrationPattern(new long[]{500, 500, 500, 500});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}试试这段频道代码。它是工作代码。
https://stackoverflow.com/questions/70213945
复制相似问题