I am sending an ordered broadcast to specific media players, so that I can play/pause/ff/rewing etc using a remote control.
private void sendbroadcast(int keyEvent) {
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
String selectedMediaPlayer = Common.get(context, SONR.APP_PACKAGE_NAME, "MEDIAPLAYERNOTFOUND");
Log.d("BROADCAST PLAYER", selectedMediaPlayer);
i.setPackage(selectedMediaPlayer);
synchronized (this) {
i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
context.sendOrderedBroadcast(i, null);
i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
context.sendOrderedBroadcast(i, null);
}
}
This works for most media players. But for some reason when I send an ordered broadcast to com.android.musicnothing happens.
Wondering how I can resolve this?
Looking at the music player in android.org, should they abort ordered broadcasts. Now I know.