startLeScan returns false

醉酒当歌 提交于 2019-12-12 01:28:29

问题


BluetoothAdapter's method startLeScan returns false sometimes during scanning BLE devices.Hence,I am facing issues in my application.I am using the newer method startScan(ScanCallback callback) from Lollipop onwards but needs to support API level 18 and above.Any help is appreciated.


回答1:


If you look at the source code for startLeScan here, you will see that there are several things that can cause the return code to be false:

  1. A null callback ha been provided
  2. A scan has already been started by a client using the same callback
  3. The device doesn't support Bluetooth LE
  4. An internal RemoteException occurs.
  5. An internal call to android.bluetooth.IBluetoothGatt registerClient fails.

Since this works sometimes, the problem is probably not 1 or 3. You can check to see if it is 4 by seeing if an error shows up in LogCat when this happens.

Item 2 above is a good candidate. Are you sure the code is always stopping scanning properly? You might want to log each time you start and stop scanning and make sure you never see two starts in a row.

If the problem is none of the above, that leaves possibility 5, which would indicate an issue with the bluetooth chip or driver in the ROM. If this is the case, you should be able to run the same code on a different device and see the problem go away.



来源:https://stackoverflow.com/questions/31834232/startlescan-returns-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!