何时在 Android 14 上使用前台服务类型

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

我有一个针对 Android 14 的应用程序,并使用相机和位置功能以及必要的清单权限。

当我运行我的应用程序并使用其中一项功能时,它不会产生任何异常,例如“android.app.ForegroundServiceStartNotAllowedException”,这将表明缺少前台服务。

尽管如此,在这种情况下我的应用程序是否需要声明相机和位置的前台服务?

android types service foreground
1个回答
0
投票

除非您打算在后台访问位置/摄像头/麦克风。

例如,如果您的应用程序跟踪位置,并且您希望在用户切换到另一个应用程序后继续跟踪。

另一个示例是,如果您使用 WorkManager 安排工作请求在您的应用程序未处于活动状态时运行。

资源:

https://developer.android.com/training/location/background https://developer.android.com/guide/background/persistent/getting-started https://developer.android.com/guide/components/foreground-services

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