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

时间:2015-04-08 11:58:56

标签: android bluetooth

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

1 个答案:

答案 0 :(得分:3)

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

    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;
                }
        }