2011-09-09 148 views
0

我正在開發一個Android音頻應用程序。現在,我正在捕捉 並播放成功的音頻,並且我想添加一項新功能,即通過bluetooh耳機捕獲和播放。捕獲Intent.ACTION_MEDIA_BUTTON事件

我一直在閱讀有關這一點,看來我必須管理ACTION_MEDIA_BUTTON 事件:

的Java文件:

.... 

public class audioBroadcastReceiver extends BroadcastReceiver 
{ 
    public void onReceive(Context context, Intent intent) 
    { 
     if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) 
     { 
      Log.d("","@@@@ WORKS"); 
     } 
     else 
    { 
    Log.d("","@@@@ ????");      
} 
.... 

xml文件

.... 
<receiver android:name="audioBroadcastReceiver"> 
    <intent-filter>  
     <action android:name="android.intent.action.MEDIA_BUTTON"> 
     </action> 
    </intent-filter> 
</receiver> 
<uses-permission android:name="android.permission.BLUETOOTH" /> 

但沒有任何反應,所以,有人可能會給我一個例子或ide a for:

1º知道bluetooh何時連接。

2º通過bluetooh耳機路由音頻數據包。

謝謝!

回答

0

您需要bluetoothAdapter方法。 BluetoothAdapter blueT = BluetoothAdapter.getDefaulAdapter();

// create broadcast receiver 
BroadcastReceiver blueReceiver = new BroadcastReceiver(){ 
// todo switch states to turn on or off or check is on 
// check is on is something like this: 
case (blueT.STATE_ON) : { 
// do something with it 
} 

if(blueT.isEnabled()){ 
do something 
} 
+0

謝謝,但它不工作,另外,我需要捕獲ACTION_MEDIA_BUTTON – Chris