最佳答案
我在崩溃日志中看到了以下异常:
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)
我使用以下方法通过 AlarmManager 从 PendingInent 集发布我的通知。这里传递的所有值都来自 PendingInent/InentService 中的 bundle 附加值。
/**
* 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());
}
从我看到的其他答案-我看到的异常发生时,setSmallIcon()
没有正确调用。
我已经检查并再次检查了正在传递的资源 ID 是否全部正确。