easypermissions icon indicating copy to clipboard operation
easypermissions copied to clipboard

Getting location permissions, any of them

Open TWiStErRob opened this issue 4 years ago • 1 comments

Basic Information

Device type: emulator OS version: 30 EasyPermissions version: 3.0.0

Describe the problem

I have an app that needs location, doesn't matter which permission. Since we have 2 of these, it's quite tricky, and didn't even start considering the background one.... The app works with coarse or fine, but has a better experience with fine.

If I pass this to requestPermissions with a rationale

private static final String[] LOCATION_PERMISSIONS = {
	Manifest.permission.ACCESS_FINE_LOCATION,
	Manifest.permission.ACCESS_COARSE_LOCATION
};

I get 2 permission dialogs (fine/coarse selector, and upgrade from coarse to fine) and the rationale dialog, if the user selects the coarse location to begin with. I think this is because EasyPermissions thinks that not all permissions were granted. Is there a way to solve this? I guess I need or instead of and relationship between items in the list?

TWiStErRob avatar Dec 21 '21 11:12 TWiStErRob

You can implement EasyPermissions.PermissionCallbacks and then accept either location permission in onPermissionGranted() callback.

    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
        if (perms.contains(Manifest.permission.ACCESS_COARSE_LOCATION) ||
                perms.contains(Manifest.permission.ACCESS_FINE_LOCATION)) {
            // App can access device's location
        }
    }

ahaapaka avatar Jan 07 '22 10:01 ahaapaka