So, after a lot of head scratching, I am at my wit\'s end. I have a media player RemoteViews
in my notification and I would like to be able to access the play, paus
Based on CommonsWare
's recommendation:
rm = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notif_media_player);
Intent pauseIntent = new Intent(getApplicationContext(), MusicService.class);
Intent dismissIntent = new Intent(getApplicationContext(), MusicService.class);
pauseIntent.putExtra(REQUEST_CODE, PAUSE);
dismissIntent.putExtra(REQUEST_CODE, DISMISS);
PendingIntent pause = PendingIntent.getService(getApplicationContext(), PAUSE, pauseIntent, 0);
PendingIntent dismiss = PendingIntent.getService(getApplicationContext(), DISMISS, dismissIntent, 0);
rm.setOnClickPendingIntent(R.id.pause, pause);
rm.setOnClickPendingIntent(R.id.dismiss, dismiss);
Notification notif = new NotificationCompat.Builder(getApplicationContext())
.setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContent(rm)
.build();
NotificationManager mgr = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
mgr.notify(NOTIFICATION_ID, notif);