Android 9:前台服务在手机进入打ze模式后停止通知

问题描述 投票:0回答:1

我们正在以固定的间隔使用位置更新,以使用前景服务提供我们的服务。使用Android 9时,该服务将完全停止,直到用户解锁屏幕为止。在Android O和pre O设备上运行正常。我转向互联网,并尝试使用所有可用的解决方案。但是似乎没有任何作用。有人面临这个问题吗?有什么解决方法吗?

根据docs,具有通知的Foreground服务可免于阻止。我试图使用唤醒锁和警报管理器。到目前为止没有任何工作。我想念什么?没有明确的文档,也没有Stack over flow可以解决此问题。

android location android-9.0-pie doze
1个回答
0
投票

在26及更高版本中,您必须在AndroidManifest中将前台服务类型作为Location提及>

           <service
            android:name="LocationUpdatesService"
            android:enabled="true"
            android:exported="true"
            android:foregroundServiceType="location" />

而且您必须调用ContextCompat.startForegroundService(getApplicationContext(), intent);,而不是像Pre-O OS版本那样仅调用startService()

© www.soinside.com 2019 - 2024. All rights reserved.