Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification

别来无恙 提交于 2019-11-27 14:16:12
Iman Akbari

For me, the problem was that I was setting a specific height for the root layout, in the custom notification view xml file.

As soon as I changed:

android:layout_height="@dimen/notification_expanded"

to

android:layout_height="match_parent"

in the root layout of notification view, the problem was solved.

Also take a look at this example to see a simple example of using custom layout for notifications.

for unknown reason you are not allowed to reference dimention in the root view of the custom remote view! so you have to hard code it like android:layout_height="64dp" but if you used android:layout_height="@dimen/notification_height_that_64" it will give you Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification . i hope this will help :)

In my case the exception was caused by a regular View in my custom notification layout. Basically, it's because you're allowed to use only certain widgets like TextView, ImageView and so on.

For me the problem was having a View item in the custom layout set for the custom notification. Removing the View item from the layout solved the problem of the Bad Notification Posted.

Here's a list of layout items which can be used, if you want to create a custom notification using RemoteView.

Neither cleaning project nor setting the layout_height as match_parent worked for me.

In my case, i was able to fix this error by reducing the icon size i was providing into .setSmallIcon();

I had the same problem. In my case:

reason -> I used for the builder.setAction(R.drawable.icon,...) function a vectordrawable and I tried also to enable them from support lib but nothing worked. In recent Android systems I do not see action icons, in the others it gives this error.

solution -> I did not find nothing, the only workaround for me is to avoid .xml files for drawables and to use the .png files in all directories hdpi mdpi ldpi..

Jeeva

I got the same error, but the problem for me was the constrain layout. I changed it to Relative Layout to fix the the problem.

@Nikolai's answer was helpful for me, indeed it was the problem. I had the same issue. There are specific controls that can be used in the notification. I had a View in my layout for notification as below.

<View
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.04"/>

This was causing the crash. Following Layouts and controls are supported:

As per this official documentation.

I removed it and it worked fine. Hope it helps someone.

Be careful when using Vector drawables. On pre-Lollipop devices setting an icon through NotificationCompat.Builder methods, like setSmallIcon, will cause this crash. You'll get same crash if using Vector drawables in your custom view.

I was facing same issue in showing custom layout in notification and what i found is:

I was using ConstraintsLayout as a root layout of my custom notification, this is the mistake i was committing. As there are some limitations with constrain layout to be used in android.

Finally i changed my root layout to RelativeLayout and my notification showing perfectly. I have attached my view in below screenshot.

In my case, the problem was an inconsistency between the call

setShowActionsInCompactView(0)

And the .addAction calls...The number of actions was different, hence the error

i see the is alot of trouble related to this topic, in my case this problem was caused by using

android:background="?attr/selectableItemBackground" 

i used that on my ImageButton and each time my app crashed but when i removed it, everything was fine, i guess the problem is you should not use any custom View type or any theme attributes on your views, i hope this will help another stuck with this problem

Generally,this error means your contentView is error,check it ! maybe you'd better replace your contentView with a layout that contain a TextView only.Ok,run it,hope help for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!