简体   繁体   English

Android蓝牙设备只扫描一次

[英]Android Bluetooth device scanned only one time

I'm working on an Android app that needs to connect to a Bluetooth Low Energy device. 我正在开发一款需要连接蓝牙低功耗设备的Android应用。

The app is working correctly on most devices but i had troubles with some devices (One plus One with Cyanogene Android 4.4.4 and Sony C5303 with Android 4.3) using BluetoothAdapter.startLeScan() . 该应用程序在大多数设备上正常工作,但我使用BluetoothAdapter.startLeScan()在一些设备(One plus One with Cyanogene Android 4.4.4和Sony C5303 with Android 4.3)上遇到了麻烦。

With the One plus, the problem seems to be the same as related in this post: Android 4.3: BLE: Filtering behaviour of startLeScan() the Bluetooth device is only scanned once. 使用One plus,问题似乎与本文中的相关问题相同: Android 4.3:BLE:过滤startLeScan()行为,蓝牙设备只扫描一次。 If I connect then disconnect from the device, it is not scan it again. 如果我连接然后从设备断开连接,则不再扫描它。

After some test I tried using: BluetoothAdapter.startDiscovery() in addition to BluetoothAdapter.startLeScan() . 经过一些测试后,我尝试使用: BluetoothAdapter.startDiscovery()以及BluetoothAdapter.startLeScan()

It appears that my device is now correctly scanned multiple times and my LeScanCallback is correctly called. 现在我的设备现在已经多次正确扫描,并且我的LeScanCallback被正确调用了。 I can then connect/disconnect from my BLE device. 然后我可以连接/断开我的BLE设备。

Question is: How BluetoothAdapter.startDiscovery() can interact with BluetoothAdapter.startLeScan() to allow my device being detected multiple times ? 问题是: BluetoothAdapter.startDiscovery()如何与BluetoothAdapter.startLeScan()交互以允许多次检测我的设备?

Thanks for you help ! 谢谢你的帮助!

You should calling 'stopLeScan()' correctly. 你应该正确地调用'stopLeScan()'。 After adding stopLeScan your device should be detected correctly. 添加stopLeScan后,应正确检测设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM