java - Couldn't Expand RemoteViews - Bad notification -
lately i've been receiving more , more reports of users getting remoteserviceexception error. stack trace i'm given every time follows:
android.app.remoteserviceexception: bad notification posted package com.smithyproductions.fasttracks: couldn't expand remoteviews for: statusbarnotification(pkg=com.smithyproductions.fasttracks id=311095 tag=null score=0 notn=notification(pri=0 contentview=com.smithyproductions.fasttracks/0x7f03007d vibrate=null sound=null defaults=0x0 flags=0x62 kind=[null]) user=userhandle{0}) @ android.app.activitythread$h.handlemessage(activitythread.java:1523) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:153) @ android.app.activitythread.main(activitythread.java:5341) @ java.lang.reflect.method.invokenative(method.java) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:929) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:696) @ dalvik.system.nativestart.main(nativestart.java)
i can never seem reproduce issue myself on htc sensation or htc 1 x leads me believe may device specific. i've received reports of error following devices:
- huawei g610 u15
- bq aquaris 5 hd
- enspert stairway
- jyt jy-g5
...and they're running android 4.2.1 - maybe there's bug version of android?
i've scoured internet , stackoverflow people similar issues , although there lot of people issue of time reason wasn't working them because of incorrect resource ids or using unsupported views in remoteviews. don't understand how i'm doing wrong if works on 98% of devices don't want tell these people issue there's nothing can either.
in terms of way create notification, use notificationcompat.builder class along custom remoteviews - it's music player notification has imagebuttons on too.
here's code setup notification:
pendingintent pi = pendingintent.getactivity( getapplicationcontext(), 0, new intent(getapplicationcontext(), showcase.class), pendingintent.flag_update_current); remoteviews smallcontentview = new remoteviews(getpackagename(), r.layout.notif_layout); nowplayingnotification = new notificationcompat.builder(this) .setsmallicon(r.drawable.notification_icon) .setcontenttitle( "playing: " + playbackmanager.getcurrenttrack() .getname()).setcontentintent(pi) .setongoing(true) .setwhen(system.currenttimemillis()) .setcontent(smallcontentview).build();
and set callbacks remoteviews buttons:
intent playintent = new intent(this, remotecontrolreceiver.class); playintent.setaction(action_toggle_playback); pendingintent playpausependingintent = pendingintent.getbroadcast(this, 0, playintent, 0); intent nextintent = new intent(this, remotecontrolreceiver.class); nextintent.setaction(action_skip); pendingintent nextpendingintent = pendingintent.getbroadcast(this, 0, nextintent, 0); intent stopintent = new intent(this, remotecontrolreceiver.class); stopintent.setaction(action_stop); pendingintent stoppendingintent = pendingintent.getbroadcast(this, 0, stopintent, 0); nowplayingnotification.contentview.settextviewtext(r.id.title, playbackmanager.getcurrenttrack().getname()); nowplayingnotification.contentview.setprogressbar( android.r.id.progress, 100, mediaprogress, false); if (notificationiconmixbitmap != null) nowplayingnotification.contentview.setimageviewbitmap(r.id.icon, notificationiconmixbitmap); else { nowplayingnotification.contentview.setimageviewresource(r.id.icon, r.drawable.notification_icon); } nowplayingnotification.contentview.setonclickpendingintent( r.id.playpause, playpausependingintent); if (playbackmanager.getcurrentplaybackstate() == state.paused) { nowplayingnotification.contentview.setimageviewresource( r.id.playpause, r.drawable.play_icon_solid); } else { nowplayingnotification.contentview.setimageviewresource( r.id.playpause, r.drawable.pause_icon_solid); } if (!playbackmanager.isskipallowed()) { nowplayingnotification.contentview.setimageviewresource(r.id.next, r.drawable.next_icon_disabled); } else { nowplayingnotification.contentview.setimageviewresource(r.id.next, r.drawable.next_icon_solid); } if (playbackmanager.getcurrentplaybackstate() == state.preparing) { nowplayingnotification.contentview.setprogressbar( android.r.id.progress, 100, mediaprogress, true); } nowplayingnotification.contentview.setonclickpendingintent(r.id.next, nextpendingintent); nowplayingnotification.contentview.setonclickpendingintent(r.id.close, stoppendingintent);
followed by
mnotificationmanager.notify(notification_id, nowplayingnotification);
if knows help, maybe recognised bug in 4.2.1, appreciated! thanks
i had same issue phone.
you create notification below code :
nowplayingnotification = new notificationcompat.builder(this) .setsmallicon(r.drawable.notification_icon) .setcontenttitle( "playing: " + playbackmanager.getcurrenttrack() .getname()).setcontentintent(pi)
app crashes if pending intent -> pi specifying intent launched set null below :
pendingintent pi= pendingintent.getactivity( getapplicationcontext(), 0, ***null***, 0 );
replace null new intent() , test if solves issue.
on gingerbread .setcontentintent(intent) mandatory otherwise illegalargumentexception thrown. in jellybean no exception thrown if remove .setcontentintent(intent)
Comments
Post a Comment