我们正在以固定的间隔使用位置更新,以使用前景服务提供我们的服务。使用Android 9时,该服务将完全停止,直到用户解锁屏幕为止。在Android O和pre O设备上运行正常。我转向互联网,并尝试使用所有可用的解决方案。但是似乎没有任何作用。有人面临这个问题吗?有什么解决方法吗?
根据docs,具有通知的Foreground服务可免于阻止。我试图使用唤醒锁和警报管理器。到目前为止没有任何工作。我想念什么?没有明确的文档,也没有Stack over flow可以解决此问题。
在26及更高版本中,您必须在AndroidManifest中将前台服务类型作为Location提及>
<service android:name="LocationUpdatesService" android:enabled="true" android:exported="true" android:foregroundServiceType="location" />
而且您必须调用
ContextCompat.startForegroundService(getApplicationContext(), intent);
,而不是像Pre-O OS版本那样仅调用startService()
。