I'm seeing the following exception in crash logs:
android.app.RemoteServiceException: Bad notification posted from package com.my.package: Couldn't create icon: StatusBarIcon(pkg=com.my.package user=0 id=0x7f02015d level=0 visible=true num=0 )
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1456)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
I'm posting my Notification from an IntentService from a PendingIntent set via the AlarmManager using the following method. All values passed in here are from the bundle extras in the PendingIntent / IntentService.
/**
* Notification
*
* @param c
* @param intent
* @param notificationId
* @param title
* @param message
* @param largeIcon
* @param smallIcon
*/
public static void showNotification(Context c, Intent intent,
int notificationId, String title, String message, int largeIcon,
int smallIcon) {
PendingIntent detailsIntent = PendingIntent.getActivity(c,
notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// BUILD
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
c);
// TITLE
mNotifyBuilder.setContentTitle(title).setContentText(message);
// ICONS
mNotifyBuilder.setSmallIcon(smallIcon);
if (Util.isAndroidOSAtLeast(Build.VERSION_CODES.HONEYCOMB)) {
Bitmap large_icon_bmp = ((BitmapDrawable) c.getResources()
.getDrawable(largeIcon)).getBitmap();
mNotifyBuilder.setLargeIcon(large_icon_bmp);
}
mNotifyBuilder.setContentIntent(detailsIntent);
mNotifyBuilder.setVibrate(new long[] { 500, 1500 });
mNotifyBuilder.setTicker(message);
mNotifyBuilder.setContentText(message);
// NOTIFY
NotificationManager nm = (NotificationManager) c
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(notificationId, mNotifyBuilder.build());
}
From what I've seen of other answers - the exception I'm seeing happens when setSmallIcon()
is not called properly.
I've checked and double checked that the Resource IDs being passed are all correct.
What was happening was, I was including the integer reference to the icon in the PendingIntent bundle, and that integer was later being referenced while being posted to the NotificationManager.
In between getting the integer reference and the pending intent going off, the app was updated and all of the drawable references changed. The integer that used to reference the correct drawable now referenced either the incorrect drawable or none at all (none at all - causing this crash)
Using VectorXml
inside your notification has been known to cause this issue. Use png's
Don't use SVG on Kitkat!
I had the same issue every time when I wanted to show a notification on Kitkat. What caused the problem for me is that I have defined every icon in xml (from svg), the small icon and the action icon also. After I have replaced them with png-s the problem solved at my side.
My problem was that the icon I was using on
.setSmallIcon(R.drawable.ic_stat_push_notif)
wasn't generated accordingly. According to the official doc:
As described in Providing Density-Specific Icon Sets and Supporting Multiple Screens, you should create separate icons for all generalized screen densities, including low-, medium-, high-, and extra-high-density screens. This ensures that your icons will display properly across the range of devices on which your application can be installed.
So the best way to fullfill the above, I used Notification Generator provided by Roman Nurik on https://romannurik.github.io/AndroidAssetStudio/index.html
In that way, you can use an image (taking into consideration that this has to have transparent background) and let the generator do the job for you generating the different sizes for notification icons.
The most important thing is that if the icon generator after you browse the image you are going to use shows you a white filled circle or square, there are problems with your image, maybe because it doesn't have any transparencies, so make sure that you has this ok.
android.app.RemoteServiceException: Bad notification posted
I had the same issue, but I was resolved. My problem is ".xml file" of Remote view.
In my xml file I was added one View
in between the LinearLayout
for divider.
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="@+id/view"
android:background="#000000" />
The above View
component creating the Bad notification exception. This Exception reason is only xml file of Remoteviews.
After removing that View component, My code executed properly, without any exception. So I felt that Notification drawer not accepting any customized views.
So you don't draw any thing like the above view in the .xml file of RemoteView
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With