2014-11-09 62 views
14

目前我使用尋找setMediaButtonReceiver

mAudioManager.registerMediaButtonEventReceiver(mRemoteControlResponder); 

一個全新的Android API的例子,但現在這是棄用5.0setMediaButtonReceiver取代。 Google中有5個鏈接都指向developer.android.com。

有沒有人用過這個呢?如果是的話,你能提供一個例子嗎?

回答

3

查看本頁面:http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-0/android/media/session/MediaSession.java它是完整的flow.Here最相關的部分之一的一個相當大的例子

設定等候意圖爲您的媒體接收器按鈕,允許重新播放會話具有後已停止。如果您的應用以這種方式啓動,則會通過掛起的意圖發送android.content.Intent.ACTION_MEDIA_BUTTON意圖。

參數:nullmbr將媒體按鈕事件發送到的android.app.PendingIntent。

 public void More ...setMediaButtonReceiver(@Nullable PendingIntent mbr) { 
     try { 
       mBinder.setMediaButtonReceiver(mbr); 
     } catch (RemoteException e) { 
      Log.wtf(TAG, "Failure in setMediaButtonReceiver.", e); 
     } 
    } 
+1

第一個環節是正確的,但我不知道爲什麼你作爲OP是關於不使用* MediaButtonEventReceiver包括休息。 – 2015-09-23 23:56:33

+0

對不起,我的錯。我正在睡覺,我想..鏈接是否幫助你? – 2015-09-24 06:00:27