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

后端 未结 3 1409
闹比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

    In short,

    Yes you can. You can do this by using the UUID of the device. If you know the UUID of a device you can match them up from the reported UUID and know which paired device is what.

    Something like this:

    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    
    Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
    
    ParcelUuid[] uuids = (ParcelUuid[]) getUuidsMethod.invoke(adapter, null);
    

    Now simply compare the retrieved UUID to the devices known UUID( online or on the box).

    If they are a match you know what device it is.

    Note: most common UUID (scanners, printers, Mice) have the generic UUID 0001101-0000-1000-8000-00805F9B34FB

    Read about the getUUID() method, paracable method , Method java class and finally Java.util.UUID.

提交回复
热议问题