确定android中连接的蓝牙设备的类型

Ale*_*lik 3 android bluetooth

当我将蓝牙鼠标/键盘与 Android 设备配对时,我可以在设备名称附近看到鼠标/键盘图标。我如何在代码中确定这些配对设备的类型?

Ale*_*lik 5

这是获取蓝牙设备类型的方法。

    BluetoothClass cls = device.getBluetoothClass();
        switch (cls.getMajorDeviceClass()) {
            case BluetoothClass.Device.Major.PERIPHERAL:
                switch (cls.getDeviceClass() & 0x05C0) {
                    case 0x0540: // Keyboard - 1314
                        break;
                    case 0x05C0: // Keyboard + mouse combo.
                        break;
                    case 0x0580: // Mouse - 1408
                        break;
                    default: // Other.
                        break;
                }
        }
Run Code Online (Sandbox Code Playgroud)