Search code examples
androidandroid-notificationsremoteviewandroid-remoteview

android.app.RemoteServiceException: Bad notification posted from package


I have an app which creates notifications every so often. It is in use by a few hundred thousand users. Typically I have no issues with notifications but this one user is getting the exception I've added below.

All users with this exception have a TCL phone with Android 4.4.4

Anyone have any idea what might be causing this?

Thanks.

Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package mypackage: Couldn't expand RemoteViews for: StatusBarNotification(pkg=mypackage user=UserHandle{0} id=74219 tag=null score=10: Notification(pri=1 contentView=mypackage/0x7f0400a2 vibrate=null sound=null defaults=0x0 flags=0x62 kind=[null]))
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5095)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
       at dalvik.system.NativeStart.main(NativeStart.java)

Edit: Layouts. I have two layouts, one big and one small.

Small:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/notification"
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@color/white"
              android:orientation="horizontal"
    >
    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/notification_image_size_small"
        android:layout_height="@dimen/notification_image_size_small"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="12dp"
        android:scaleType="centerCrop"
        android:src="@drawable/drawable0"/>
    <TextView
        android:id="@+id/title"
        style="@style/title_style"
        android:text="title"></TextView>
    <ImageView
        android:id="@+id/button1"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:background="@drawable/ripple"
        android:clickable="true"
        android:scaleType="center"
        android:src="@drawable/drawable1"
        android:text="@string/text1"
        android:contentDescription="@string/test1"
        />
    <ImageView
        android:id="@+id/button2"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:background="@drawable/ripple"
        android:clickable="true"
        android:scaleType="center"
        android:src="@drawable/drawble2"
        android:text="@string/text2"
        android:contentDescription="@string/test2"
        />
    <ImageView
        android:text="@string/text3"
        android:contentDescription="@string/text3"
        android:id="@+id/button3"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_gravity="center"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:background="@drawable/ripple"
        android:clickable="true"
        android:scaleType="center"
        android:src="@drawable/drawable3"></ImageView>
</LinearLayout>

Big:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/notification"
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="110dp"
              android:background="@color/white"
              android:clickable="true"
              android:focusable="true"
              android:foreground="@drawable/ripple_rect"
              android:orientation="horizontal">
    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/notification_image_size_big"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        android:src="@drawable/drawable0_big"
        />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="32dp"
            android:layout_marginLeft="12dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="8dp"
            android:orientation="horizontal">
            <TextView
                android:id="@+id/title"
                android:text="title"
                style="@style/title_style"></TextView>
            <ImageView
                android:id="@+id/button1"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_gravity="center_vertical"
                android:background="@drawable/ripple"
                android:clickable="true"
                android:scaleType="center"
                android:src="@drawable/drawable1"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/buttons"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_marginTop="12dp"
            android:orientation="horizontal"
            >
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal"></LinearLayout>
            <ImageView
                android:id="@+id/button2"
                style="@style/buttons_style"
                android:src="@drawable/drawable2"
                android:text="@string/text2"
                android:contentDescription="@string/text2"
                />
            <LinearLayout
                android:id="@+id/spacer1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal"></LinearLayout>
            <ImageView
                android:id="@+id/button3"
                style="@style/buttons_style"
                android:src="@drawable/drawable3"
                android:text="@string/text3"
                android:contentDescription="@string/text3"
                />
            <LinearLayout
                android:id="@+id/spacer2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal"></LinearLayout>
            <ImageView
                android:id="@+id/button4"
                style="@style/buttons_style"
                android:src="@drawable/drawable4"
                android:text="@string/text4"
                android:contentDescription="@string/text4"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal"></LinearLayout>
            <ImageView
                android:id="@+id/button5"
                style="@style/buttons_style"
                android:scaleX="-1"
                android:src="@drawable/drawable5"
                android:text="@string/text5"
                android:contentDescription="@string/text5"
                />
            <LinearLayout
                android:id="@+id/spacers3"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal"></LinearLayout>
            <ImageView
                android:id="@+id/button6"
                style="@style/buttons_style"
                android:src="@drawable/drawable6"
                android:text="@string/text6"
                android:contentDescription="@string/text6"
                />
            <LinearLayout
                android:id="@+id/spacer4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal"></LinearLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

While adding that layout I noticed android:scaleX="-1" and I have no idea why I had that there so I'm going to send the user an apk without that. I have that there because it is the same image facing the other way. I'll see if I can replace it just in case that's the issue.

Edit: Sent the user a new version without android:scaleX="-1" and the crash still happened.

Edit: Adding the ripple drawables. Since the user is on 4.4 they would get these ones:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/color_primary_translucent" android:state_focused="true"/>
    <item android:drawable="@color/color_primary_light_translucent" android:state_pressed="true"/>
    <item android:drawable="@android:color/transparent"/>
</selector>

and

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/color_primary_translucent" android:state_focused="true"/>
    <item android:drawable="@color/color_primary_light_translucent" android:state_pressed="true"/>
    <item android:drawable="@android:color/transparent"/>
</selector>

Solution

  • I would suggest remove all the background ripple and foreground ripples from the layout and to keep the ripple in the notification.

    In your notifications layout.

    <ImageButton
                android:id="@+id/notification_base_previous"
                style="@style/NotificationAction.Previous"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    

    Now declare the style in the manifest.

    This is for your individual buttons.

     <style name="NotificationAction.Previous" parent="@style/NotificationAction">
            <item name="android:src">@drawable/btn_playback_previous_light</item>
        </style>
    

    This should be the parent of style.

    <style name="NotificationAction">
            <item name="android:layout_width">@dimen/notification_action_width</item>
            <item name="android:layout_height">@dimen/notification_action_height</item>
            <item name="android:gravity">center|right</item>
            <item name="android:scaleType">fitCenter</item>
            <item name="android:padding">@dimen/notification_action_padding</item>
            <item name="android:background">?android:selectableItemBackground</item>
        </style>
    

    It works this all the devices I have used so far. Please have a look.