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á.
- Emulador de Android: ¿Cómo puedo obtener una lista de servicios que se están ejecutando
- No se puede activar la aplicación desde el fondo en dispositivos Xiaomi hasta que "Autostart" se habilite manualmente
- Establecer un Listener en una clase basada en servicio
- El servicio Android se bloquea después de que la aplicación se borre de la lista de aplicaciones recientes
- Android verificar el estado WIFI (desconectado o el usuario ha cambiado WIFI) ¿Cómo FLAG?
¿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?
- Cómo configurar el permiso WRITE_SECURE_SETTINGS en android?
- ¿Por qué otro servicio encima de IMarketBillingService?
- Varias TextViews se actualizan muy lentamente
- ¿Cuándo se llama a ServiceConnection.onServiceDisconnected ()?
- El servicio de primer plano se asesina al realizar operaciones relacionadas con Internet
- Implementación de un grupo de subprocesos dentro de un servicio
- Empleos para GCM Network Manager
- Suscripción o vinculación a un servicio de Intent existente
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?