蓝牙 LE 不扫描设备

Posted

技术标签:

【中文标题】蓝牙 LE 不扫描设备【英文标题】:Bluetooth LE not scanning for devices 【发布时间】:2020-09-15 21:17:09 【问题描述】:

我一直在构建一个安卓应用。我使用我的galaxy s4和galaxy not 10进行调试。当我使用我的 Galaxy s4 时,我可以扫描和查看其他设备。当我使用我的 note 10 时,它不会显示附近的蓝牙设备。我也启用了位置设置。如果有人可以帮助我,我将不胜感激。

2020-09-15 17:09:29.953 12536-12536/? E/Zygote: accessInfo : 1
2020-09-15 17:09:29.976 12536-12536/? I/aixbluetoothap: Late-enabling -Xcheck:jni
2020-09-15 17:09:29.990 12536-12536/? E/aixbluetoothap: Unknown bits set in runtime_flags: 0x8000
2020-09-15 17:09:29.998 12536-12536/? D/ActivityThread: setConscryptValidator
2020-09-15 17:09:29.998 12536-12536/? D/ActivityThread: setConscryptValidator - put
2020-09-15 17:09:30.240 12536-12536/com.example.maixbluetoothapp D/PhoneWindow: forceLight changed to true [] from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4268 com.android.internal.policy.DecorView.updateColorViews:1494 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3246 android.view.Window.setFlags:1148 com.android.internal.policy.PhoneWindow.generateLayout:2474 
2020-09-15 17:09:30.241 12536-12536/com.example.maixbluetoothapp I/MultiWindowDecorSupport: updateCaptionType >> DecorView@218acd4[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
2020-09-15 17:09:30.241 12536-12536/com.example.maixbluetoothapp D/MultiWindowDecorSupport: setCaptionType = 0, DecorView = DecorView@218acd4[]
2020-09-15 17:09:30.286 12536-12536/com.example.maixbluetoothapp D/DeviceScanActivity: Request Location Permissions:
2020-09-15 17:09:30.330 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: startLeScan(): null
2020-09-15 17:09:30.331 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:30.332 12536-12536/com.example.maixbluetoothapp I/chatty: uid=10321(com.example.maixbluetoothapp) identical 1 line
2020-09-15 17:09:30.333 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:30.333 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: BLE support array set: 111111
2020-09-15 17:09:30.334 12536-12536/com.example.maixbluetoothapp D/BluetoothLeScanner: Start Scan with callback
2020-09-15 17:09:30.336 12536-12664/com.example.maixbluetoothapp D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=12 mScannerId=0
2020-09-15 17:09:30.732 12536-12536/com.example.maixbluetoothapp D/ViewRootImpl@680f8ff[DeviceScanActivity]: setView = com.android.internal.policy.DecorView@218acd4 TM=true MM=false
2020-09-15 17:09:30.764 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: stopLeScan()
2020-09-15 17:09:30.765 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:30.771 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:30.771 12536-12536/com.example.maixbluetoothapp D/BluetoothLeScanner: Stop Scan with callback
2020-09-15 17:09:30.824 12536-12536/com.example.maixbluetoothapp D/ViewRootImpl@680f8ff[DeviceScanActivity]: Relayout returned: old=(0,0,1440,3040) new=(0,0,1440,3040) req=(1440,3040)0 dur=20 res=0x7 s=true 491187228672 ch=true
2020-09-15 17:09:30.824 12536-12616/com.example.maixbluetoothapp D/OpenGLRenderer: createReliableSurface : 0x71c9c1b1c0(0x725d0a5000)
2020-09-15 17:09:30.824 12536-12616/com.example.maixbluetoothapp I/AdrenoGLES: QUALCOMM build                   : 128c575, I000594fe7d
    Build Date                       : 02/02/20
    OpenGL ES Shader Compiler Version: EV031.27.05.03
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.8.1.R1.10.00.00.529.103
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
2020-09-15 17:09:30.824 12536-12616/com.example.maixbluetoothapp I/AdrenoGLES: Build Config                     : S P 8.0.11 AArch64
2020-09-15 17:09:30.827 12536-12616/com.example.maixbluetoothapp I/AdrenoGLES: PFP: 0x016ee187, ME: 0x00000000
2020-09-15 17:09:30.844 12536-12536/com.example.maixbluetoothapp D/AbsListView:  in onLayout changed 
2020-09-15 17:09:30.861 12536-12616/com.example.maixbluetoothapp D/OpenGLRenderer: makeCurrent EglSurface : 0x0 -> 0x0
2020-09-15 17:09:30.888 12536-12616/com.example.maixbluetoothapp D/OpenGLRenderer: makeCurrent EglSurface : 0x0 -> 0x71c9c2bd00
2020-09-15 17:09:30.889 12536-12616/com.example.maixbluetoothapp W/Gralloc3: mapper 3.x is not supported
2020-09-15 17:09:31.015 12536-12536/com.example.maixbluetoothapp D/ViewRootImpl@680f8ff[DeviceScanActivity]: MSG_RESIZED_REPORT: frame=(0,0,1440,3040) ci=(0,114,0,53) vi=(0,114,0,53) or=1
2020-09-15 17:09:31.113 12536-12536/com.example.maixbluetoothapp D/DeviceScanActivity: coarse location permission granted
2020-09-15 17:09:31.114 12536-12536/com.example.maixbluetoothapp D/ViewRootImpl@680f8ff[DeviceScanActivity]: stopped(false) old=false
2020-09-15 17:09:31.115 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: startLeScan(): null
2020-09-15 17:09:31.115 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:31.116 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:31.116 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:31.117 12536-12536/com.example.maixbluetoothapp D/BluetoothLeScanner: Start Scan with callback
2020-09-15 17:09:31.118 12536-12568/com.example.maixbluetoothapp D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=12 mScannerId=0
2020-09-15 17:09:40.339 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: stopLeScan()
2020-09-15 17:09:40.341 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:40.342 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:40.342 12536-12536/com.example.maixbluetoothapp D/BluetoothLeScanner: Stop Scan with callback
2020-09-15 17:09:41.117 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: stopLeScan()
2020-09-15 17:09:41.119 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: STATE_ON
2020-09-15 17:09:41.119 12536-12536/com.example.maixbluetoothapp D/BluetoothAdapter: scan not started yet

以下是我的日志文件。

https://android.googlesource.com/platform/development/+/f8a92396babb6592bb8780866def23795f3dab70/samples/BluetoothLeGatt/src/com/example/bluetooth/le

以上链接用于我的项目的参考。

【问题讨论】:

最近我注意到,在 DeviceScanActivity 中,控制流不会添加到我的 Galaxy Note 10 中的 addDevice(),但它可以毫不费力地在 Galaxy s4 上运行。 // public void addDevice(BluetoothDevice device) Log.d(TAG,"contains mLeDevices"+device); if(!mLeDevices.contains(device)) mLeDevices.add(device); Log.d(TAG,"添加设备")​​; 【参考方案1】:

我在使用搭载 Android 10 操作系统的三星设备时遇到的问题最多。您是否尝试过按照this 发行说明中的​​说明更改位置权限?

尽管我这样做了,但他们仍然根本没有列出附近的设备。所以我尝试格式化这些设备之一:Samsung Galaxy Tab A8。在制造重置后,我得到了它的工作。在格式化设备之前,我看到了 BluetoothAdaptor API 的控制台日志:

D/BluetoothAdapter: BLE support array set: 010011

但是这个日志在我格式化之后就消失了。这可能是新 Android 10 系统的错误。因为我在Android 10以下的系统上没有遇到过这个问题。

更新:

您还必须确保设备的位置信息已打开。

【讨论】:

我能够解决这个问题。 github.com/android/connectivity-samples/issues/210该解决方案在链接中提供

以上是关于蓝牙 LE 不扫描设备的主要内容,如果未能解决你的问题,请参考以下文章

扫描蓝牙 LE 设备时出现问题(无回调)

如何从蓝牙 LE 设备获取数据

蓝牙 LE iOS 无法在后台扫描

蓝牙低能耗清单

Android 4.4:低功耗蓝牙;无需扫描 BLE 设备即可连接

锁定 iOS 设备扫描 BTLE 设备