startLeScan返回false [英] startLeScan returns false

查看:1316
本文介绍了startLeScan返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BluetoothAdapter的方法startLeScan从棒棒糖开始扫描BLE devices.Hence,我面对我的问题application.I现在用的是较新的方法startScan(ScanCallback回调)期间有时会返回false,但需要支持API级别18和above.Any帮助AP是preciated。

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.

推荐答案

如果你看一下源$ C ​​$ C为 startLeScan 这里,你会看到,有几件事情,可能会导致返回code是错误的:

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. 提供了一个空的回调公顷

  2. 的扫描已经由一个客户端使用相同的回调开始

  3. 的设备不支持蓝牙LE

  4. 内部的RemoteException 发生。

  5. android.bluetooth.IBluetoothGatt registerClient 内部呼叫失败。

  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.

由于该作品有时,问题可能不是1或3.您可以检查,看它是否是由4如果看到一个错误在LogCat中显示出来的时候出现这种情况。

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.

第2项是一个很好的候选人。你确定code总是停止扫描正常吗?您可能希望每次登录你开始和停止扫描,并确保你永远看不到两场比赛连胜。

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.

如果问题是没有以上,留下可能性5,这表明与在ROM中的蓝牙芯片或驱动器的问题。如果是这种情况,你应该能够在不同的设备上运行相同的code和看问题消失。

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.

这篇关于startLeScan返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆