android - How to add a notification to a MediaPlayer Service? -


i have working mediaplayer app. mainactivity (mylistactivity.java) binds service (mediaservice.java). service plays music in background.

i know way add notification user can control tracks through it. using interface pass data service activity.

i have no clue start. tried notifications tutorial on android documentation, don't know how add buttons , cannot find decent tutorial remoteviews.

this have notification.

mediaservice.java

    play(track track) {         ...         shownotification(track);     }      shownoticiation(track track){         notificationcompat.builder builder = new notificationcompat.builder(this)                 .setsmallicon(r.mipmap.dj_plink_avatar)                 .setcontenttitle(track.gettitle())                 .setcontenttext(track.getgenre());          intent resultintent = new intent(this, mylistactivity.class);         taskstackbuilder stackbuilder = taskstackbuilder.create(this);         stackbuilder.addparentstack(mylistactivity.class);         stackbuilder.addnextintent(resultintent);          pendingintent pintent = stackbuilder.getpendingintent(0, pendingintent.flag_update_current);         builder.setcontentintent(pintent);          notificationmanager = (notificationmanager) getsystemservice(context                 .notification_service);         notificationmanager.notify(notificationid, builder.build());     } 

ps: api 15 minimum please :)

notificationcompat.mediastyle, part of appcompat, of styling required , works api 7.

you'll still need build own pendingintents each action, can done way makes sense. generally, involves using pendingintent.getservice() intent pointing service , action can using in onstartcommand() distinguish button pressed.

note: make sure using v7.app.notificationcompat, not v4 version.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -