Notificación RemoteView en el oyente de clics
Así que, después de un montón de rascarse la cabeza, estoy en el final de mi ingenio. Tengo un reproductor multimedia RemoteViews
en mi notificación y me gustaría poder acceder a los botones de reproducción, pausa, anterior y siguiente.
Sé que setOnClickPendingIntent()
se utilizará para comunicarse desde la notificación. Sin embargo, me quedo preguntándome cómo funcionará.
- Razones por las que la intención pasada sería NULL en onStartCommand
- Context.getApplicationContext () devuelve null en un Service
- La escritura concurrente a la base de datos android (de múltiples servicios)?
- ¿Cómo podemos evitar que un servicio muera por un sistema operativo?
- Servicio que no se está creando (o que se conecta) después de bindService ()
¿Es posible permitir que el servicio maneje los clics?
He intentado esto, pero en vano. Yo estaba tratando de dejar que el servicio de manejar la pausa y el reanudación del jugador:
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);
y mi IBinder
es nulo. Si eso hace una diferencia.
¿Cómo puedo pausar y reproducir música desde la notificación?
- Administrador de alarmas programado no funciona Android
- Creación de servicio sin consolidar en Kotlin
- Androide broadcastreceiver vs oyentes
- ¿Cómo puedo saber si mi servicio ha iniciado
- No se puede iniciar el servicio Intención: no se encuentra
- Firebase + Android - Notificaciones ChildAdded - ¿Cómo obtener sólo New Childs?
- Diferencia entre RTC y RTC_WAKEUP en android
- Pasando objeto personalizado al servicio android en diferentes procesos
Basado en la recomendación de CommonsWare
:
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);
- Utilizando Otto, el método sólo se suscribe si lo llamo directamente a otra parte
- ¿Dónde puedo comprobar la versión más reciente NUMBER del diseño de restricciones?