Skip to content Skip to sidebar Skip to footer

How To Check If An Paired Bluetooth Device Is A Printer Or A Scanner (android)

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 want to

Solution 1:

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:

privatestaticbooleanisAPrinter(BluetoothDevice device){
    intprinterMask=0b000001000000011010000000;
    intfullCod= device.getBluetoothClass().hashCode();
    Log.d(TAG, "FULL COD: " + fullCod);
    Log.d(TAG, "MASK RESULT " + (fullCod & printerMask));
    return (fullCod & printerMask) == printerMask;
}

Solution 2:

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

Solution 3:

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:

BluetoothAdapteradapter= BluetoothAdapter.getDefaultAdapter();

MethodgetUuidsMethod= 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.

Post a Comment for "How To Check If An Paired Bluetooth Device Is A Printer Or A Scanner (android)"