Home » Android » How to get raw scan record (advertising packet) while scanning for classic bluetooth devices in Android?

How to get raw scan record (advertising packet) while scanning for classic bluetooth devices in Android?

Posted by: admin May 14, 2020 Leave a comment

Questions:

What I’m doing now is trying to scan for both BLE and classic bluetooth devices at the same time. As far as I could see I can discover both by using:

BluetoothAdapter.getDefaultAdapter().startDiscovery() and receiving intents via previously registered BroadcastReceiver. It works fine and I can distinguish between classic and LE devices but I have some valuable data in advertising packet and I have no idea how to get it from incoming Intent. Appreciate any ideas.

How to&Answers:

I am not sure if this will allow you to get all the information you need, but it should allow you to get at least some of it.

When you receive the ACTION_FOUND Intent, that Intent has an extra field identified by BluetoothDevice.EXTRA_DEVICE. This extra contains an instance of BluetoothDevice that represents the remote device. The BluetoothDevice instance will allow you to get some information about the device such as its name and type.

Moreover, the ACTION_FOUND Intent also has an extra field identified by BluetoothDevice.EXTRA_CLASS which contains a BluetoothClass instance that also provides some more information about the remote device such as the class of the device.

See the class documentation for BluetoothDevice and BluetoothClass.