如果用户已经授予ACCESS_FINE_LOCATION,是否需要ACCESS_COARSE_LOCATION?

Ant*_*427 5 android location android-permissions

我正在更新我的应用程序以使用新的Android Marshmallow权限框架,看起来它足以让用户在运行时授予ACCESS_FINE_LOCATION权限,以使应用程序正常工作.这就是我做的:

public static final String[] runtimePermissions = { permission.ACCESS_FINE_LOCATION };

public static final int LOCATION_PERMISSION_IDENTIFIER = 1;
Run Code Online (Sandbox Code Playgroud)

进一步下课:

public static boolean checkConnectionPermission(final Context context) {

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {

            if (context.checkSelfPermission(permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

                return true;
            }

            else {

                ((Activity) context).requestPermissions(runtimePermissions,
                        LOCATION_PERMISSION_IDENTIFIER);
                return false;
            }

        }

        // since in API levels below M the permission is granted on
        // installation,
        // it is considered a given that the permission has been granted since
        // the
        // app is running. So we return true by default

        else {
            return true;

        }

    }
Run Code Online (Sandbox Code Playgroud)

我只是担心我会忽略一些可能导致未来出现问题的应用程序(应用程序接近生产)和安全例外.

我想我的最终问题是:是否授予FINE_LOCATION以某种方式自动授予COARSE_LOCATION?

Der*_*ung 2

有点已经在这里回答了。

如果我已经有 ACCESS_FINE_LOCATION,我可以省略 ACCESS_COARSE_LOCATION 吗?

一些附加信息,您应该查看权限组。

https://developer.android.com/preview/features/runtime-permissions.html

他们在同一个权限组中。如果您确实想安全起见,只需将两者都包含在您的清单中,并根据需要请求它们即可。这对用户来说是透明的。