开发者

Capturing Intent.ACTION_MEDIA_BUTTON event

I'm developing a Android audio application. Now, I'm capturing and playing audio with sucess and I want to add a new feature, the capture and playing through bluetooh headset.

I have been reading about that, and seems that I must manage the ACTION_MEDIA_BUTTON event:

Java file:

....

public class audioBroadcastR开发者_C百科eceiver extends BroadcastReceiver 
{
    public void onReceive(Context context, Intent intent) 
    {
        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) 
        {
            Log.d("","@@@@ WORKS" );
        }
        else
    {
    Log.d("","@@@@ ????" );                      
}
....

xml file

....
<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" />

But nothing happens, so, somebody may give me a example or a idea for:

1º Know when the bluetooh has been connected.

2º Routed the audio packets through bluetooh headset.

Thanks!


You need the bluetoothAdapter method. 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜