Quando si invia un SendOrderedBroadcast con un intento ACTION_MEDIA_BUTTON (sto imitando che l'utente fa clic sul pulsante di riproduzione su un auricolare bluetooth), Google Play Music si apre e riproduce l'ultimo album riprodotto anziché l'app di riproduzione musicale in primo piano.Google Play Music esegue il hogging di tutti gli intenti ACTION_MEDIA_BUTTON?
Se lo cambio in sendBroadcast, sia Google Play Music che l'app di riproduzione musicale corrente (Pandora nel mio caso), eseguirà il pulsante di riproduzione.
Questo si verifica solo in Android 4.0 e oltre. Play Music sta intasando questo intento (un bug)? Sospetti che Pandora non si stia registrando come gestore di pulsante multimediale corrente seguendo questo consiglio: http://android-developers.blogspot.com/2010/06/allowing-applications-to-play-nicer.html
C'è un modo per indirizzare questo intento solo all'attuale app di riproduzione musicale?
Ecco il mio codice:
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