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

后端 未结 3 1368
闹比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 14:58

    Accepted answer is too generic, because UUID 0001101-0000-1000-8000-00805F9B34FB assert that device has serial port capabilites, and many not printer devices has this kind of UUID.

    You should evalute full CoD, at this link you can extract exact bit mask for serivice you need to recognize, that for a printer is :

    0b000001000000011010000000

    with this you can do a mask on full device CoD as:

    private static boolean isAPrinter(BluetoothDevice device){
        int printerMask = 0b000001000000011010000000;
        int fullCod = device.getBluetoothClass().hashCode();
        Log.d(TAG, "FULL COD: " + fullCod);
        Log.d(TAG, "MASK RESULT " + (fullCod & printerMask));
        return (fullCod & printerMask) == printerMask;
    }
    

提交回复
热议问题