android - Notification buttons not showing -
following this guide , other discussions online i've made pice of code should show .addaction method buttons in notification:
@suppresslint("newapi") public void generatenotificationsong() { if(android.os.build.version.sdk_int >= 11){ notification.builder builder = new notification.builder(this); builder.setsmallicon(r.drawable.ic_launcher); builder.setcontenttitle(songslist.get(currentsongindex).gettitle()); builder.setcontenttext("next: " + songslist.get(getnextsong()).gettitle()); builder.setongoing(true); //e' in corso builder.setautocancel(true); //intent con activity che devo aprire (la corrente) intent thisintent = getintent(); pendingintent pendingintent = pendingintent.getactivity(this, 0, thisintent, pendingintent.flag_update_current); //aggiungo bottoni alla notifica se android รจ > 4.1 if(android.os.build.version.sdk_int >= 16) { log.v("a", "ciao"); intent previntent = new intent(); previntent.setaction("prec"); pendingintent pendingprev = pendingintent.getbroadcast(this, 123, previntent, pendingintent.flag_update_current); intent nextintent = new intent(); nextintent.setaction("next"); pendingintent pendingnext = pendingintent.getbroadcast(this, 123, nextintent, pendingintent.flag_update_current); intent pauseintent = new intent(); pauseintent.setaction("pause"); pendingintent pendingpause = pendingintent.getbroadcast(this, 123, pauseintent, pendingintent.flag_update_current); builder.addaction(r.drawable.btn_previous, "previous", pendingprev); builder.addaction(r.drawable.btn_pause, "pause", pendingnext); builder.addaction(r.drawable.btn_next, "next", pendingpause); } //la setto alla notifica builder.setcontentintent(pendingintent); //infine la chiamo mnotify = (notificationmanager) getsystemservice(notification_service); if(android.os.build.version.sdk_int >= 16) mnotify.notify(001, builder.build()); //funziona meglio else mnotify.notify(001, builder.getnotification()); //deprecated } }
what notification without buttons i've added, think i'm missing i've not found solution yet
here possible cause. android may hide buttons when there other notifications present, when phone being charged. try tap notification 2 fingers , swipe down. should able see buttons.
Comments
Post a Comment