Khi gửi sendOrderedBroadcast với mục đích ACTION_MEDIA_BUTTON (Tôi bắt chước người dùng đang nhấp vào nút phát trên tai nghe bluetooth), Google Play Âm nhạc sẽ mở và phát album cuối cùng thay vì ứng dụng phát nhạc nền trước.Google Play Âm nhạc có đang lưu trữ tất cả ý định ACTION_MEDIA_BUTTON không?
Nếu tôi thay đổi nó để gửiBroadcast, cả Google Play Âm nhạc VÀ ứng dụng chơi nhạc hiện tại (Pandora trong trường hợp của tôi), sẽ ban hành nút phát.
Điều này chỉ xảy ra trong Android 4.0 trở lên. Play Âm nhạc có hogging mục đích này không (một lỗi)? Bạn có nghi ngờ rằng Pandora không tự đăng ký là trình xử lý nút phương tiện hiện tại theo lời khuyên này: http://android-developers.blogspot.com/2010/06/allowing-applications-to-play-nicer.html
Có cách nào tôi có thể hướng mục đích này đến ứng dụng chơi nhạc hiện tại không?
Đây là mã của tôi:
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