Al enviar un sendOrderedBroadcast con un ACTION_MEDIA_BUTTON intento (imito que el usuario está haciendo clic en el botón Reproducir en un auricular bluetooth), Google Play Music abre y reproduce el último álbum reproducido en lugar de la aplicación de reproducción de música en primer plano.¿Google Play Music está acaparando todos los intentos de ACTION_MEDIA_BUTTON?
Si lo cambio a sendBroadcast, tanto Google Play Music como la aplicación de reproducción de música actual (Pandora en mi caso), representarán el botón de reproducción.
Esto solo ocurre en Android 4.0 y superior. ¿Play Music está acaparando este intento (un error)? ¿Sospecha que Pandora no se está registrando como el gestor de botones de medios actual siguiendo este consejo: http://android-developers.blogspot.com/2010/06/allowing-applications-to-play-nicer.html
¿Hay alguna manera de dirigir esta intención a la aplicación de reproducción de música actual solamente?
Aquí está mi código:
public void broadcastMediaIntent(MediaIntent intentType){
long eventtime = SystemClock.uptimeMillis();
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent downEvent = null;
KeyEvent upEvent = null;
switch(intentType){
case NEXT:
downEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT, 0);
upEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT, 0);
break;
case PLAY_PAUSE:
downEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
upEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
break;
case PREVIOUS:
downEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0);
upEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0);
break;
case FAST_FORWARD:
downEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, 0);
upEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, 0);
break;
case REWIND:
downEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_REWIND, 0);
upEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_REWIND, 0);
break;
default:
break;
}
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
sendOrderedBroadcast(downIntent, null);
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
sendOrderedBroadcast(upIntent, null);
}
http://code.google.com/p/android/issues/detail?id=23272 – joepetrakovich