Android - bad notification sent only on Android 2.3

I get crash messages in Android 2.3 when displaying notifications. Stacking I have:

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 read that Android 2.3 has some problems with AnimatedImageView, but I don’t think I use it ... Code to trigger notification:

 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 found that the problem occurs when I try to update this notification that started with startForeground (), the code that 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 does it give problems with Ginger?

+6
source share
2 answers

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

Delete

  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're using a custom notification layout, see the docs for how to use the http://developer.android.com/guide/topics/ui/notifiers/notifications.html builder

+2
source

Do you see something like android.view.InflateException? Also check where you store the SmallIcon notification? Can you make sure that the png file exists in a portable folder? Not only in drawable-mdpi, etc.

Can you publish a full log at application startup.

0
source

Source: https://habr.com/ru/post/927474/


All Articles