一段时间后,Android Bluetooth Le扫描仪停止运行 [英] Android Bluetooth Le scanner stops after a time

查看:164
本文介绍了一段时间后,Android Bluetooth Le扫描仪停止运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用活动的Bluetooth LE扫描仪运行应用程序或服务,并在Log Console上显示扫描结果.如果我将手机锁定在桌子上并且不再触摸.一段时间后,它停止了,并且没有给我更多的扫描结果.

I am runnning an app or service with a active Bluetooth LE scanner and showing scan results on Log console. If I lock the phone in a table and not touching anymore. After a time it stops, and it doesn't give me more scan results.

如果我按下电源按钮,并且屏幕唤醒,它会为我提供更多扫描结果.如果我再次锁定屏幕或等待自动锁定,它将停止并且不会给我更多扫描结果.

If I press power button and the screen wake up it gives me more scan results. If i lock again the screen or wait to lock automatically it stops and not give me more scan results.

我通过服务和一个应用进行了测试,该应用通过Log为我提供了更多结果,并看到该应用正在运行,但扫描仪LE停止了,并且在屏幕锁定时也没有给我更多结果.

I test with service and an app that give me more results by Log and see the app is running but scanner LE stops and no give me more results while the screen is lock.

我的应用程序处于无优化电池"的休眠模式.我通过引入电话en doze模式的命令来测试强制,并且可以正常工作,从而为我提供扫描结果.

I have the app in "no optimized battery" for doze mode. I test forcing by command introducing the phone en doze mode and work fine it give me scan results.

在装有Android 7.1.1的Nexus 5中,运行APP并通过该功能时,屏幕锁定且不再触摸手机.时间是30分钟.手机仅在桌子上,只有与microusb连接才能在android studio中查看日志.

In my Nexus 5 with Android 7.1.1 pass when running APP and lock the screen and not touch anymore the phone. The time is 30 minutes. The phone is in a table alone, only connected with microusb to see the log in android studio.

在其他具有Android 7.1的Moto G2上,它的传递时间恰好在20分钟至40分钟之间,因此更加偶然.手机仅在桌子上,只有与microusb连接才能在android studio中查看日志.

In other Moto G2 with android 7.1 pass exactly but the time is between 20 minutes and 40 minutes, it is more aleatory. The phone is in a table alone, only connected with microusb to see the log in android studio.

为了再次运行良好,我需要手动关闭应用程序并重新启动,否则仅在屏幕处于活动状态时有效,而在屏幕锁定时则无法提供更多结果.

For have running well again, I need to force close the app manually and restart, otherwise only works when screen is active and no give me more results when screen is locked.

这是用于信标结果的,首先,我为此目的使用了Android Beacon库,结果是相同的.

This is used for beacon results, first I use Android Beacon Library for this purpose and the result was the same.

我认为这是android蓝牙组件的问题,因为我对Android Beacon库有相同的结果,或者如果实现自己的BLE扫描仪,但我不知道如何解决此问题.

I think it is a problem of android bluetooth component, because I have the same result with the Android Beacon Library or if I implement my own BLE Scanner, but I don't know how to solve this.

当手机处于锁定状态很多时间时,是否有任何形式的蓝牙扫描仪LE始终在Android中运行?

Are any form to use Bluetooth Scanner LE always running in Android when the phone is much time in lock state??

谢谢.

最诚挚的问候.

推荐答案

Android 7.0引入了BLE扫描超时,其中有效运行30分钟或更长时间的任何扫描都会自动停止,并且仅机会性"恢复,这实际上意味着进程进行扫描,它也可以获取结果.

Android 7.0 introduced a BLE scan timeout, where any scan running for 30 minutes or more is effectively stopped automatically and only resumed "opportunistically" which essentially means that if another process does a scan, it can get the results as well.

您可以通过设置代码以启动Bluetooth LE扫描并使它无限期运行来查看此情况.恰好30分钟后,扫描将停止,您将在LogCat中看到类似这样的条目:

You can see this by setting up code to start a Bluetooth LE scan and leave it running indefinitely. After exactly 30 minutes, the scan will stop, and you will see entries like this in LogCat:

06-11 19:00:22.848  5123  5147 D BtGatt.ScanManager: clientIf set to scan opportunisticly: 6
06-11 19:00:22.848  5123  5147 D BtGatt.ScanManager: configureRegularScanParams() - queue=1
06-11 19:00:22.848  5123  5147 D BtGatt.ScanManager: configureRegularScanParams() - ScanSetting Scan mode=-1 mLastConfiguredScanSetting=2
06-11 19:00:22.848  5123  5147 D BtGatt.ScanManager: configureRegularScanParams() - queue emtpy, scan stopped
06-11 19:00:22.849  5123  5147 D BtGatt.ScanManager: stop scan

您可以在AOSP源代码中查看执行此操作的代码:

You can see the code that does this in the AOSP source here:

https://android.googlesource.com/platform/packages/apps/Bluetooth/+/android-7.0.0_r1/src/com/android/bluetooth/gatt/ScanManager.java#72

一种解决方法是不要让扫描持续这么长时间.您只需停止它们并定期重新启动它们即可.

A workaround for this is to not keep scans going that long. You can simply stop them and restart them periodically.

这篇关于一段时间后,Android Bluetooth Le扫描仪停止运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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