Reputation: 1215
Very occasionally, we're getting an IllegalArgumentException with an empty localized message on some devices while creating a notification channel. I found this answer, but the channel name is 100% certain not "", so not the issue in this case. It's working for almost all users, but sometimes this exception is thrown for a user. We cannot seem to link it to a device type or specific Android version either.
The code for creating the channel:
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);
}
}
}
The stack trace of the exception:
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)
Anyone has any ideas? I'd love to fix this issue!
Upvotes: 1
Views: 632
Reputation: 84
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);
}
Try this piece of channel code. It is working code.
Upvotes: -1