Solve the problem of android.app.RemoteServiceException Bad notification posted exception when using Notification custom layout

When using Notification to customize the layout, the code is implemented as:

notification.contentView = new RemoteViews(mContext.getPackageName(), R.layout.content_view);

If the app runs to this line of code, the following error occurs:
android.app.RemoteServiceException Bad notification posted from package com.mypackage.test: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.mypackage.test user=UserHandle{0} id=-1314 tag=null score=0 key=0|com.haier.uhome.uplus|-1314|null|10471|0: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags= 0x62 color=0xff607d8b vis=PRIVATE)) TestRes=null

It is very likely that there are unsupported layouts or controls in the custom layout R.layout.content_view. The official custom notification bar RemoteViews only supports the following layouts and controls:
Layout container Layout:
FrameLayout, LinearLayout, RelativeLayout, GridLayout
control Component:
AnalogClock, Button, Chronometer, ImageButton, ImageView, ProgressBar,
TextView, ViewFlipper, ListView, GridView, StackView, AdapterViewFlipper

Modify the layout file to make it meet the above conditions.
 

Guess you like

Origin blog.csdn.net/chenzhengfeng/article/details/108729750