Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad notification posted from package Couldn't expand RemoteViews

I have a problem. Some times my service is forcefully closed with this logcat:

03-26 20:44:44.849: E/AndroidRuntime(12080): FATAL EXCEPTION: main
03-26 20:44:44.849: E/AndroidRuntime(12080): android.app.RemoteServiceException: Bad notification posted from package by.flipdev.vkspy: Couldn't expand RemoteViews for: StatusBarNotification(pkg=by.flipdev.vkspy id=1 tag=null score=0 notn=Notification(pri=0 contentView=by.flipdev.vkspy/0x1090071 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null]))
03-26 20:44:44.849: E/AndroidRuntime(12080):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374)
03-26 20:44:44.849: E/AndroidRuntime(12080):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 20:44:44.849: E/AndroidRuntime(12080):    at android.os.Looper.loop(Looper.java:137)
03-26 20:44:44.849: E/AndroidRuntime(12080):    at android.app.ActivityThread.main(ActivityThread.java:4931)
03-26 20:44:44.849: E/AndroidRuntime(12080):    at java.lang.reflect.Method.invokeNative(Native Method)
03-26 20:44:44.849: E/AndroidRuntime(12080):    at java.lang.reflect.Method.invoke(Method.java:511)
03-26 20:44:44.849: E/AndroidRuntime(12080):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-26 20:44:44.849: E/AndroidRuntime(12080):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
03-26 20:44:44.849: E/AndroidRuntime(12080):    at dalvik.system.NativeStart.main(Native Method)

This is my code to add add notifications:

protected void addNotification(final Bitmap Avatar,
        final int small_Image_ID, final int notify_id, final String text,
        final String title, final Boolean ongoing, final Boolean ticker,
        final String tickerText, final Boolean autoCancel,
        final String notificationCategory, final int notificationValue) {

    try {

        final Intent notificationIntent = new Intent(
                getApplicationContext(), CheckerActivity.class);

        notificationIntent
                .putExtra(notificationCategory, notificationValue);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        final PendingIntent contentIntent = PendingIntent.getActivity(
                getApplicationContext(), notify_id, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        final NotificationManager nm = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);


        final NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);
        if (Ticker) {
            builder.setContentIntent(contentIntent)
                    .setSmallIcon(small_Image_ID)
                    .setOngoing(ongoing)                    
                    .setLargeIcon(Avatar).setTicker(tickerText)                     
                    .setWhen(System.currentTimeMillis())
                    .setAutoCancel(AutoCancel).setContentTitle(title)
                    .setContentText(text); // Текст уведомления
        } else {
            builder.setContentIntent(contentIntent)
                    .setSmallIcon(small_Image_ID)
                    .setLargeIcon(avatar)                       
                    .setOngoing(ongoing)
                    .setWhen(System.currentTimeMillis())
                    .setAutoCancel(AutoCancel).setContentTitle(title) 
                    .setContentText(text); // Текст уведомления
        }

        final Notification n = builder.getNotification();

        nm.notify(notify_id, n);

    } catch (final Exception e) {
                    // TODO: add exception handling code
    }
}

Why is my service killed?

like image 317
user2212515 Avatar asked Mar 26 '13 16:03

user2212515


3 Answers

I noticed this happening on 3.0 emulators, when I set the Large Icon.

So, since the Large Icon is only used by 4.0+ devices, I solved this issue by checking if the Build version is > 13. If so (and only if so), I set the Large icon.

The problem has gone.

like image 141
Phantômaxx Avatar answered Nov 04 '22 16:11

Phantômaxx


This issue is a result of missing or null resources. Looking at your code, I infer that, possible error seems to be on Ticker (always false) and setLargeIcon(avatar)( avatar is always null).

Could you post all your service implementations?

P.S. Please try to respect java's naming convention; Ticker,Avatar,AutoCancel and other objects should start with lower case.

like image 20
Anis BEN NSIR Avatar answered Nov 04 '22 16:11

Anis BEN NSIR


Well, in my case, I was getting this exact same error because I referred to a style definition for a TextView in my custom notification layout that had an entry for an onClick target method. Specifically:

<item name="android:onClick">onClick</item>

Once I removed that line, the problem went away. An oversight on my part, but a good reminder not to blindly reuse styles.

like image 2
jkincali Avatar answered Nov 04 '22 17:11

jkincali