質問

my goal is to find nearby Bluetooth devices(LE devices and "Classic"), in order to associate between current visible nearby devices to some functionality my app doing with it. (not a specific device/devices, but all of them!!!)

what I know:

  • startLeScan() would callback only with BLE devices
  • the two methods working in different way - while startBLeScan() managed by my code with callbacks while classic scan is managed by the system process, and returns the BluetoothDevice found via broadcasts.

what I don't know for sure:

  • assuming current device API level is 18+ startScan() will find always both discoverable BLE and classic devices.
  • BluetoothDevice.connectGatt() added with the new BLE API's, but should work also with classic bluetooth(return GATT Services...).

what I would like to know:

  • if indeed startScan() returns both types (Classic and BLE), what would be better to use in terms of battery consumption, performances, good practices and other aspects?

my application will perform background scans periodically, so I would like to minimize the battery consumption impact as possible.

役に立ちましたか?

解決

You have to start a scan for Classic Bluetooth devices with startDiscovery() and a scan for Bluetooth LE devices with startLeScan(). Caution: Performing device discovery is a heavy procedure for the Bluetooth adapter and will consume a lot of its resources.

Edit: On LG Nexus 4 with Android 4.4.2 startDiscovery() finds Bluetooth LE devices. On Samsung Galaxy S3 with Android 4.3 startDiscovery() doesn't find Bluetooth LE devices.

他のヒント

I have an off-market Chinese tablet that has BLE support, however, it always return a BLE equipped device with its name as "null" when I call startLeScan. The issue was resolved by calling startDiscovery. Remember that if your app targets 23 or above, you will need to have location permissions for startDiscovery to work correctly. Hope it helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top