Android RequestMultiplePermissions not prompting for permissions with certain permission combinations?

Viewed 1662

I'm updating an app that currently uses the ACCESS_FINE_LOCATION permission and with new API 30 requirements, will now require the ACCESS_BACKGROUND_LOCATION permission as well.

While updating the app to add this permission, I'm also trying to use the new ActivityResultLauncher callback method of requesting permissions (https://developer.android.com/training/permissions/requesting#allow-system-manage-request-code)

This seems to work well using launching single requests along these lines:

ActivityResultLauncher<String> launcher = registerForActivityResult(
    new ActivityResultContracts.RequestPermission(), this::processPermissionResult);

launcher.launch(somePermission);

However, since I need both ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION it requires some extra code to keep track of the results from multiple callbacks (since each request will generate its own callback) so that I can take appropriate action if one, both, or none of the permissions were granted.

To simplify this a bit, I was looking to use the RequestMultiplePermissions method instead, which would conveniently give me one callback with all the results in a map:

ActivityResultLauncher<String[]> launcher = registerForActivityResult(
    new ActivityResultContracts.RequestMultiplePermissions(), this::processPermissionResult);

launcher.launch(new String[] {
    Manifest.permission.ACCESS_FINE_LOCATION,
    Manifest.permission.ACCESS_BACKGROUND_LOCATION
});

However I found that the moment I request both ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION in the same request, I am no longer prompted with either permissions dialog and the callback comes back with false for both the permissions.

I can, however, make individual requests for these permissions using RequestMultiplePermissions by giving it an array containing a single permission, and then calling launch multiple times using the same approach as if I was using the single RequestPermission call, and that will work.

It seems that there some conflict/interaction between the ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION permissions when it comes to RequestMultiplePermissions? I was able to take out ACCESS_BACKGROUND_LOCATION and use a different permission, like WRITE_EXTERNAL_STORAGE, and I would get two separate permission dialog prompts.

Am I misunderstanding something about the ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION permissions? Should I not be requesting them simultaneously?

0 Answers
Related