Android 10(Q)ACCESS_BACKGROUND_LOCATION权限 [英] Android 10 (Q) ACCESS_BACKGROUND_LOCATION permission

查看:3782
本文介绍了Android 10(Q)ACCESS_BACKGROUND_LOCATION权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用户检查并设置对ACCESS_BACKGROUND_LOCATION的许可(一直允许"),而无需选择仅在使用该应用程序时允许".即使将GPS跟踪应用程序最小化,我的GPS跟踪应用程序也需要继续访问该位置.

I need the user to check and set permission to ACCESS_BACKGROUND_LOCATION ("Allow all the time") without the option to "Allow only while using the app". My GPS Tracking app needs to continue accessing location even when the application is minimised.

我已经具有使用Android 9的ACCESS_FINE_LOCATION的权限.

I have already permissions working for ACCESS_FINE_LOCATION for Android 9.

AndroidManifest.xml--------------------------------------------------->

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

TrackingActivity.java (need to include ACCESS_BACKGROUND_LOCATION)---->

private void permissionCheck1() {
        int permissionCheck1 = ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION);
        if (permissionCheck1 != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                    MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
        } else {
            grantedSetupGPSandMap();
        }
}

如果可能的话,我需要唯一的权限选项为一直允许".在检查和设置权限时如何设置?

I need the only permission option to be "Allow all the time" if possible. How do I set this up when checking and setting permissions?

推荐答案

对于Android 10,如果:

For Android 10, if:

  • 您省略了ACCESS_BACKGROUND_LOCATION,并且:
  • 您使用在清单中设置了android:foregroundServiceType="location"属性的前台服务,然后:
  • You omit ACCESS_BACKGROUND_LOCATION, and:
  • You use a foreground service with the android:foregroundServiceType="location" property set in the manifest, then:

参考位置许可,系统将仅向用户提供仅在使用应用程序时允许"和拒绝"选项.

The system will supply only the "Allow only while using the app" and "Deny" options to the user, in reference to the location permission.

我意识到这与您要求的完全相反,但是要点是,在这种情况下,仅在使用应用程序时允许"的行为实际上就像一直允许",提供了上述前台服务正在运行.

I realize that's the exact opposite of what you asked for, but the point is, under this condition, "Allow only while using the app" effectively behaves like "Allow all the time", provided the aforementioned foreground service is running.

即使该应用不在屏幕上,您也将能够接收位置更新.而且,用户不能选择仅部分允许位置更新;他们必须在完全允许还是完全拒绝之间做出选择.

You will be able to receive location updates even when the app is offscreen. And the user does not have the option of only partially allowing location updates; they have to choose between fully allowing it, or fully denying it.

编辑

此答案还假设您的targetSdkVersion是29.

This answer also assumes your targetSdkVersion is 29.

这篇关于Android 10(Q)ACCESS_BACKGROUND_LOCATION权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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