1

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>
casolorz
  • 8,486
  • 19
  • 93
  • 200
  • 1
    Can you post the layout of your `RemoteView`? – azizbekian Jul 17 '17 at 16:41
  • Added the layout, also while adding that I noticed something odd, I have `android:scaleX="-1"` and I have no idea why. – casolorz Jul 17 '17 at 17:35
  • I now know why. Because that button is the same as the other but just facing the other direction. – casolorz Jul 17 '17 at 17:38
  • Sent the user a new version without `android:scaleX="-1"` and the crash still happened. – casolorz Jul 17 '17 at 19:56
  • can you please add your android:background="@drawable/ripple" ripple and ripple_rect layout it just a guess but I would suggest remove all the background ripple and foreground ripple from the layout and send the apk and let us know. – Reyansh Mishra Jul 18 '17 at 05:51
  • Can you run with debug build and post logs from logcat? – azizbekian Jul 18 '17 at 06:42
  • Added the ripple stuff. I will try it with the user. – casolorz Jul 18 '17 at 14:25
  • I can not run a debug build as it doesn't happen to me, and the user doesn't know how to capture logs. – casolorz Jul 18 '17 at 14:25
  • @ReyanshMishra thank you for the suggestion, that worked. I guess now I need to figure out how to solve it permanently for that user without removing the ripple for everyone else. Although the ripples is so quick maybe it doesn't matter. Anyways, if you write it up as an answer I'll give you the bounty. – casolorz Jul 20 '17 at 01:55
  • Please accept n give the bounty plus try what I have mentioned to keep ripple at place. Hopefully it will work. Fingers Crossed. – Reyansh Mishra Jul 20 '17 at 04:44

1 Answers1

1

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.

Reyansh Mishra
  • 1,879
  • 1
  • 14
  • 26