捕获Intent.ACTION_MEDIA_BUTTON事件

时间:2011-09-09 17:50:03

标签: android events audio bluetooth

我正在开发Android音频应用程序。现在,我正在捕捉 我需要添加一项新功能,通过bluetooh耳机捕捉和播放。

我一直在读这个,似乎我必须管理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" />

但没有任何事情发生,所以,有人可能会给我一个例子或想法:

1º知道bluetooh何时连接。

2º通过bluetooh耳机路由音频数据包。

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要蓝牙适配器方法。 BluetoothAdapter blueTOOTH = BluetoothAdapter.getDefaultAdapter();

// 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
}