Notificação RemoteView no ouvinte de clique
Então, depois de muito coçar a cabeça, estou no fim da minha inteligência. Eu tenho um media playerRemoteViews
na minha notificação e gostaria de poder acessar os botões reproduzir, pausar, anterior e próximo.
Eu sei dissosetOnClickPendingIntent()
será usado para se comunicar a partir da notificação. No entanto, fico imaginando como isso funcionará.
É possível deixar o serviço lidar com os cliques?
Eu tentei isso, mas em vão. Eu estava tentando me deixar cuidar da pausa e do resumo do player:
rm = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notif_media_player);
Intent intent = new Intent(getApplicationContext(), MusicService.class);
intent.putExtra(REQUEST_CODE, PAUSE);
PendingIntent pending = PendingIntent.getService(getApplicationContext(), PAUSE, intent, 0);
rm.setPendingIntentTemplate(R.id.pause, pending);
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);
e meuIBinder
é nulo. Se isso faz diferença.
Como faço para pausar e reproduzir músicas a partir da notificação?