检查蓝牙适配器是否连接到可穿戴设备



我正在开发一个Android应用程序,我需要知道何时与可穿戴设备连接蓝牙。我尝试使用带有蓝牙适配器的方法,但没有良好的结果。我该如何编程此方法?

public static boolean btConnected() {
    if( /*Bluetooth is connected*/ )
        return true;
    else
        return false;
}

在您的清单中添加此权限。xml

<uses-permission android:name="android.permission.BLUETOOTH" />

并创建一种方法,该方法将检查是否连接蓝牙

private boolean isBluetootConnected() {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()
            && mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_CONNECTED;
} 

最新更新