java - Handle buttons click event in custom notification in android -


i have custom notification 3 buttons ("previous", "play/pause", "next"). can catch click event when there 1 button, 3 buttons can't know button of them clicked. question "how know button clicked?"

my notification code

private void initnotification()      {         string ns = context.notification_service;         int icon=r.drawable.tmc;         long when=system.currenttimemillis();         notification notification=new notification(icon, "the music class", when);         notificationmanager mnnotificationmanager=(notificationmanager)getsystemservice(ns);         remoteviews conviews=new remoteviews(getpackagename(),r.layout.notification);         conviews.setimageviewresource(r.id.image, r.drawable.tmc);         conviews.settextviewtext(r.id.title, song_title);         notification.contentview=conviews;         intent nintent=new intent(this,musicplayeractivity.class);         pendingintent conpendingintent=pendingintent.getactivity(getbasecontext(), 0,nintent,0);         notification.contentintent=conpendingintent;          notification.flags |= notification.flag_no_clear; //do not clear notification //        notification.defaults |= notification.default_lights; // led //        notification.defaults |= notification.default_vibrate; //vibration //        notification.defaults |= notification.default_sound;            //this intent supposed called when button clicked          intent switchintent = new intent(getbasecontext(), switchbuttonlistener.class);         pendingintent pendingswitchintent = pendingintent.getbroadcast(getbasecontext(), 0, switchintent, 0);         conviews.setonclickpendingintent(r.id.btnplay, pendingswitchintent);             mnnotificationmanager.notify(notification_id, notification);      } 

switchbuttonlistener class

public static class switchbuttonlistener extends broadcastreceiver {     @override     public void onreceive(context context, intent intent) {         log.d("here", "i here");     } } 

in manifest file

have check below code

remoteviews conviews=new remoteviews(getpackagename(),r.layout.notification); button b1=(button)conviews.findviewbyid(r.id.button1); button b2=(button)conviews.findviewbyid(r.id.button2); button b3=(button)conviews.findviewbyid(r.id.button3);  b1.setonclicklistner(new ...){  onclick(view v){   //    b1 click listner } } 

same other button click... hope you.....


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -