Couldn't expand RemoteViews

后端 未结 5 1032
孤街浪徒
孤街浪徒 2021-02-12 14:34

I try to create a custom notification but getting the following exception:

FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification posted from         


        
相关标签:
5条回答
  • 2021-02-12 14:55

    You cannot put an EditText into a RemoteViews. RemoteViews is limited to a handful of possible widgets, specifically those documented for use on an app widget. And, for a Notification, I doubt that the AdapterView options, like ListView, will work either.

    0 讨论(0)
  • 2021-02-12 14:56

    For me, it was because I was setting the text inside the remoteViews TextViews incorrectly. I was doing this:

    remoteViews.setString(R.id.txt, "setText", "text");
    

    Using one of these methods solved it for me:

    remoteViews.setCharSequence(R.id.txt, "setText", "text");
    //Or simply:
    remoteViews.setTextViewText(R.id.txt, "text");
    
    0 讨论(0)
  • 2021-02-12 15:07

    I've found that using android:background="?attr/colorPrimaryDark" also causes a crash. When changed to android:background="@color/colorPrimaryDark" it stopped crashing.

    0 讨论(0)
  • 2021-02-12 15:15

    If you have a ScrollView amongst your RemoteViews, remove it. This worked for me.

    0 讨论(0)
  • 2021-02-12 15:17

    Not all views can be used in RemoteViews. A RemoteViews object can support the following layout classes:

    FrameLayout

    LinearLayout

    RelativeLayout

    GridLayout

    AnalogClock

    Button

    Chronometer

    ImageButton

    ImageView

    ProgressBar

    TextView

    ViewFlipper

    ListView

    GridView

    StackView

    AdapterViewFlipper

    You can't use other layout classes like EditText or CustomViews.

    0 讨论(0)
提交回复
热议问题