When customizing the layout of the notification bar, to copy a layout.xml file, reference, but always error
ANDROID.APP.REMOTESERVICEEXCEPTION:BAD notification posted from the package com.example.notification:Couldn ' t expand Remoteviews for:statusbarnotification (pkg=com.example.notification id=2 tag=null score=0 notn=Notification (pri=0 contentview=com.example.notification/0x7f030001 vibrate=null sound=null defaults=0x0 flags=0x10 kind=[null]) user= USERHANDLE{0})
Get Notification Manager Notificationmanager Nfmanager = (notificationmanager) getsystemservice (Notification_service); Notification mynotification = new Notification ();//reminder Alert Mynotification.tickertext = "Android: Hello";// Set notification Time Mynotification.when = System.currenttimemillis ();//Set icon Mynotification.icon = r.drawable.ic_launcher;// Set the action of the notification click intent Intent = new Intent (this, mainactivity.class);//A future (advance) action, used to click or clear the notification when the action, pendingintent Pendingintent = Pendingintent.getactivity (this, 0,intent, 0); mynotification.contentintent = pendingintent;// Set remote View remoteviews remoteviews = new Remoteviews (Getpackagename (), r.layout.notification_layout); Mynotification.contentview = Remoteviews;mynotification.flags = Notification.flag_auto_cancel;nfmanager.notify (2, Mynotification);
I've been looking for a long time. The reason is that when you set up a remote layout, the buttons inside the layout file set a static click event
<button android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:o nclick= "shownotify" android:text= "notifications"/>
Delete this android:onclick= "shownotify" to run.
Android custom notification Bar encountered problems