How to Check if an Paired Bluetooth device is a Printer or a Scanner (Android)

后端 未结 3 1367
闹比i
闹比i 2021-01-14 14:35

I hope can help me, I am developing an Android App, that require to connect with Bluetooth devices, like Scanner and Printer, currently I can list all Paired devices, but i

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 15:17

    I have one idea, it may help you.

    for (BluetoothDevice device : pairedDevices)
    {
        String deviceBTMajorClass = getBTMajorDeviceClass(device.getBluetoothClass().getMajorDeviceClass());
        if (D) Log.d(TAG, "deviceBTMajorClass"+deviceBTMajorClass);
        //btArrayAdapter.add(deviceBTName + "\n"+ deviceBTMajorClass);
        data.add(device.getName() + "\n" + device.getAddress());
    }
    
    private String getBTMajorDeviceClass(int major) {
        switch (major) {
            case BluetoothClass.Device.Major.AUDIO_VIDEO:
                return "AUDIO_VIDEO";
            case BluetoothClass.Device.Major.COMPUTER:
                return "COMPUTER";
            case BluetoothClass.Device.Major.HEALTH:
                return "HEALTH";
            case BluetoothClass.Device.Major.IMAGING:
                return "IMAGING";
            case BluetoothClass.Device.Major.MISC:
                return "MISC";
            case BluetoothClass.Device.Major.NETWORKING:
                return "NETWORKING";
            case BluetoothClass.Device.Major.PERIPHERAL:
                return "PERIPHERAL";
            case BluetoothClass.Device.Major.PHONE:
                return "PHONE";
            case BluetoothClass.Device.Major.TOY:
                return "TOY";
            case BluetoothClass.Device.Major.UNCATEGORIZED:
                return "UNCATEGORIZED";
            case BluetoothClass.Device.Major.WEARABLE:
                return "AUDIO_VIDEO";`enter code here`
            default:
                return "unknown!";
        }
    }
    

提交回复
热议问题