Answer the question
In order to leave comments, you need to log in
How to manage third-party players in Android?
Let's say there is a bluetoh headset. It has buttons "next track", "previous track, pause / play next". She communicates with the phone, giving some commands to the current (!) Playing player. But how to repeat this?
Interested in compatibility with 2.3.3 and higher.
Tried two option The first one works only with the default player and not on all phones.
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command" , key ); //key - "togglepause","next","previous"
context.sendBroadcast(i);
long eventtime = SystemClock.uptimeMillis() - 1;
//key - это KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, KeyEvent.KEYCODE_MEDIA_NEXT, KeyEvent.KEYCODE_MEDIA_PREVIOUS
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, key, 0);
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
context.sendOrderedBroadcast(downIntent, null);
eventtime++;
Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime,KeyEvent.ACTION_UP, key, 0);
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
context.sendOrderedBroadcast(upIntent, null);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question