6

I'm receiving reports about crash in Android 2.3 when displaying notification. The stacktrace I have is:

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)

I've read that Android 2.3 have some issue with AnimatedImageView, but I don't think I'm using it... The code I run for displaying the notification is:

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

UPDATE:
I've discovered that the problem appears when I try to updated that notification started with startForeground(), the code I run is:

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

But it works correctly on ICS and JB, so why is it giving problems on Ginger?

dmarcato
  • 872
  • 8
  • 16

2 Answers2

2

Do not reference notification directly because you are using NotificationBuilder to create your notification object.

Remove:

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

Add:

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

Also, it looks like you are using a custom notification layout, see the docs how to use with the builder http://developer.android.com/guide/topics/ui/notifiers/notifications.html

user1159819
  • 1,549
  • 4
  • 16
  • 29
  • setProgressBar etc won't really work, since it is Android 4.x+. – Yuvi Feb 19 '13 at 05:23
  • Sorry, i meant setProgress. fixed above. basically you shouldn't mix the old way of doing notification if you are using the new way, i.e. NotificationBuilder – user1159819 Feb 20 '13 at 18:23
0

Are you seeing something like android.view.InflateException ? Also please check where you keep notificationSmallIcon? Can you ensure that the png file exists in drawable folder? Not just in drawable-mdpi etc?

Can you post a complete log when you run the application.

Durairaj Packirisamy
  • 4,635
  • 1
  • 21
  • 27