我希望确定配对设备是否处于活动状态。我并不需要连接它,只需确定它是否有心跳。
在尝试连接蓝牙套接字时,我遇到了一系列IO错误,但我不确定我是否真的需要连接它。
<intent-filter >
<action android:name="android.bluetooth.headset.action.AUDIO_STATE_CHANGED" />
</intent-filter>
在你的接收器中的onReceive方法中检查:
if ("android.bluetooth.headset.action.AUDIO_STATE_CHANGED".equals(intent.getAction())) {
headsetAudioState = intent.getIntExtra("android.bluetooth.headset.extra.AUDIO_STATE", -2);
}
将整数保存为静态变量。随时访问以了解是否连接BT音频(1)/断开连接(0)。这并不美观,但可以完成工作。