安卓 - 在安卓2.3上出现的糟糕通知

6

我收到有关在 Android 2.3 显示通知时崩溃的报告。 我拥有的堆栈跟踪是:

android.app.RemoteServiceException: Bad notification posted from package com.megadevs.hubi: Couldn't expand RemoteViews for: StatusBarNotification(package=com.megadevs.hubi id=1 tag=null notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x62))
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1048)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)

我看到Android 2.3存在一些与AnimatedImageView有关的问题,但我不认为我正在使用它...

我用于显示通知的代码是:

NotificationCompat2.Builder builder = new NotificationCompat2.Builder(getApplicationContext());
notification = builder.setOngoing(true)
    .setAutoCancel(false)
    .setPriority(NotificationCompat2.PRIORITY_DEFAULT)
    .setSmallIcon(notificationSmallIcon)
    .setWhen(System.currentTimeMillis())
    .setContentIntent(notificationIntent)
    .setContentTitle(downloads.elements().nextElement().getFileName())
    .setProgress(100, (int) downloadable.getDownload().getProgress(), false)
    .build();
startForeground(DL_NOTIFICATION, notification);

更新:
我发现当我尝试更新使用startForeground()启动的通知时,出现了问题,我运行的代码是:

notification.contentView.setProgressBar(android.R.id.progress, 100, (int) download.getProgress(), false);
mNotificationManager.notify(DL_NOTIFICATION, notification);

但在ICS和JB上它可以正常工作,为什么在Ginger上会出现问题呢?

你找到解决方案了吗?我也遇到了同样的问题 :| - Yuvi
2个回答

2
不要直接引用通知,因为您正在使用NotificationBuilder创建通知对象。
删除:
 notification.contentView.setProgressBar(android.R.id.progress, 100, (int) download.getProgress(), false);

添加:

 builder.setProgress(int max, int progress, boolean indeterminate)

此外,看起来您正在使用自定义通知布局,请参阅文档以了解如何与构建器一起使用。 http://developer.android.com/guide/topics/ui/notifiers/notifications.html

setProgressBar等在Android 4.x+上并不会真正起作用。 - Yuvi
抱歉,我的意思是setProgress。已经进行了修正。基本上,如果您正在使用新的NotificationBuilder方法,则不应混合旧的通知方式。 - user1159819

0
你是否看到了类似 android.view.InflateException 的错误?同时请检查一下你保存 notificationSmallIcon 的位置。你能确保 png 文件存在于 drawable 文件夹中吗?而不仅仅是在 drawable-mdpi 等文件夹中?
当你运行应用程序时,你能否发布完整的日志记录?

我已经更新了我的问题,并在一些测试后发现了一些信息。有什么想法吗? - dmarcato

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接