本文介绍了如何获得对应用蓝牙耳机连接状态启动时采用Android2.2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用的应用程序启动的Android API级8获得蓝牙耳机连接状态(连接/断开)?
是否有任何的粘性广播意图在Android2.2的可用?
是否有任何的API来获取初始蓝牙耳机的状态?
有任何解决方法可用?
How to get Bluetooth Headset connection state (connected/disconnected) using android api level 8 on application start-up?Is there any sticky broadcast intent available in android2.2?Is there any API to fetch initial Bluetooth Headset state?Is there any workaround available?
推荐答案
我想出解决办法:
private static final String ACTION_BT_HEADSET_STATE_CHANGED = "android.bluetooth.headset.action.STATE_CHANGED";
private static final int STATE_CONNECTED = 0x00000002;
private static final int STATE_DISCONNECTED = 0x00000000;
private static final String EXTRA_STATE = "android.bluetooth.headset.extra.STATE";
private BroadcastReceiver mBlueToothHeadSetEventReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
String action = intent.getAction();
if(action == null)
return;
if(action.equals(ACTION_BT_HEADSET_STATE_CHANGED)){
int extraData = intent.getIntExtra(EXTRA_STATE , STATE_DISCONNECTED);
if(extraData == STATE_CONNECTED ){
//TODO :
}else if(extraData == STATE_DISCONNECTED){
//TODO:
}
}
} catch (Exception e) {
//TODO:
}
}
};
这篇关于如何获得对应用蓝牙耳机连接状态启动时采用Android2.2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!