我有一个实现前台服务的 Android 应用程序,使用部分唤醒锁并有权使用REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
此处说明的方法清空电池:https ://developer.android.com/training/monitoring-device-state/doze-standby
一切正常,服务永远运行而不会打瞌睡。
我的服务使用一系列信标并永久报告距离。使用 altbeacon 效果很好。但是,当屏幕关闭时,大约 1 分钟后。1 到 5 分钟,Android 电源管理以某种方式启动,并且 altbeacon 库始终使用空信标列表调用“RangeNotifier”回调。一旦发生这种情况,即使我再次唤醒手机,信标列表也始终为空。
这是我配置它的方式:
beaconManager = BeaconManager.getInstanceForApplication(this)
beaconManager.setEnableScheduledScanJobs(false)
beaconManager.isRegionStatePersistenceEnabled = false
beaconManager.foregroundBetweenScanPeriod = 0
beaconManager.foregroundScanPeriod = 1100
不知何故,我为我的服务成功逃避 DOZE 所采取的手段似乎并没有扩展到 Altbeacon 服务。我怎样才能改变这一点,让 altbeacon 永远扫描?
编辑:Manifest.xml 中的相关部分
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hollyhook.oscHook">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<!-- for beacons -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.sensor.accelerometer"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity>
... removed for brevity
</activity>
<service
android:name=".OscHookService"
android:enabled="true"
android:exported="true">
</service>
</application>
</manifest>
我正在使用 Android 10 Samsung S10 进行测试。如果有帮助,我可以提供一个 Android 日志 BeaconManager.setDebug(true)
(它又长又吵)
非常感谢您的帮助!