0
大家好,有没有办法检查Android手机是否通过编程方式连接到任何蓝牙设备?Android:确定蓝牙是否连接到任何设备
应该存在诸如Bluetooth_state == Bluetooth_connected
或Bluetooth_state == Bluetooth_disconnected
或Bluetooth.isConnected()
的状态。目标是识别手机的蓝牙是否连接到任何设备。
大家好,有没有办法检查Android手机是否通过编程方式连接到任何蓝牙设备?Android:确定蓝牙是否连接到任何设备
应该存在诸如Bluetooth_state == Bluetooth_connected
或Bluetooth_state == Bluetooth_disconnected
或Bluetooth.isConnected()
的状态。目标是识别手机的蓝牙是否连接到任何设备。
如果您只想在启动时检查设备是否已连接,请尝试mBluetoothAdapter.getProfileConnectionState()
;应该为你工作。
public static boolean isBluetoothHeadsetConnected() {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()
&& mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_CONNECTED;
}//BluetoothHeadset.A2DP can also be used for Stereo media devices.
不要忘记在manifest中要求同意。
<uses-permission android:name="android.permission.BLUETOOTH" />
至少有人建议我的东西。请。 – varun
那么,至少你可以检查蓝牙耳机'BluetoothProfile.STATE_CONNECTED == bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET)'... –