如何修复:android.app.RemoteServiceException:从包中发布的错误通知*:无法创建图标:StatusBarIcon [英] How to fix: android.app.RemoteServiceException: Bad notification posted from package *: Couldn't create icon: StatusBarIcon

查看:30
本文介绍了如何修复:android.app.RemoteServiceException:从包中发布的错误通知*:无法创建图标:StatusBarIcon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在崩溃日志中看到以下异常:

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)

我正在使用以下方法通过 AlarmManager 从 PendingIntent 集的 IntentService 发布我的通知.此处传入的所有值均来自 PendingIntent/IntentService 中的 bundle extras.

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());
}

从我看到的其他答案来看 - 我看到的异常发生在 setSmallIcon() 没有正确调用时.

From what I've seen of other answers - the exception I'm seeing happens when setSmallIcon() is not called properly.

我已经检查并仔细检查了传递的资源 ID 是否全部正确.

I've checked and double checked that the Resource IDs being passed are all correct.

推荐答案

发生的事情是,我在 PendingIntent 包中包含了对图标的整数引用,并且该整数后来在发布到 NotificationManager 时被引用.

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.

在获取整数引用和挂起的 Intent 之间,应用已更新,所有可绘制引用都已更改.用于引用正确可绘制对象的整数现在引用了不正确的可绘制对象或根本没有(根本没有 - 导致此崩溃)

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)

这篇关于如何修复:android.app.RemoteServiceException:从包中发布的错误通知*:无法创建图标:StatusBarIcon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆