Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 271
bgplaya Avatar asked Aug 12 '15 16:08

bgplaya


People also ask

Can you scan for Bluetooth devices?

Note: Android-powered devices are not discoverable by default. A user can make the device discoverable for a limited time through the system settings, or an app can request that the user enable discoverability without leaving the app.

How do I get permission to scan for Bluetooth?

1- If you want to search nearby Bluetooth devices, you must add BLUETOOTH_SCAN permission. 2- If you want your device to be discovered by other devices, you must add BLUETOOTH_ADVERTISE permission. 3- If you want your device to be communicable with other devices, you must add BLUETOOTH_CONNECT permission.

How do I scan my Android phone for BLE?

To find BLE devices, you use the startScan() method. This method takes a ScanCallback as a parameter. You must implement this callback, because that is how scan results are returned.

How do I get a list of Bluetooth devices?

Swipe down from the top of the screen. Touch and hold Bluetooth . If your accessory is listed under "Available media devices," next to your device's name, tap Settings . If no accessories are listed under "Previously connected devices," tap See all.


1 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.

like image 143
Janus Varmarken Avatar answered Sep 20 '22 10:09

Janus Varmarken