3

I am having some trouble with asking for FINE_LOCATION in my app. I have tried to read a bit about ACCESS_FINE_LOCATION and i know i should ask for it together with ACCESS_COARSE_LOCATION for android 12, but it seems to only show me the "approximate location" everytime i ask. It doesnt even ask for FINE_LOCATION.

Here is my code

Manifest:

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

Code:


//asking for permission inside a method
requestMultiplePermissions.launch(arrayOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION ))


// registering activity for result. 
activity.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->

            if(permissions.entries.all { it.value }){
                checkPermissionsAndContinue()
            }else{
                val deniedPermission = permissions.entries.find { !it.value }
                deniedPermission?.key?.let { showPermissionDeniedDialog(it) }
            }

I have tried to run on android 31 emulator and my phone on android 12. Same result. Never get the fine location, just the coarse location. It seems to work fine for all other android versions, its just the android 12 fine location stuff thats stopping me.

Does someone have a idea where i could take a look to fix this? Thank you so much!

Meyben
  • 451
  • 3
  • 15
  • No. You should not ask it together but after each other. – blackapps Jan 26 '22 at 19:32
  • 1
    Nah, I think they're correct for Android 12, you're suposed to request both. Check if something like this is occuring: https://stackoverflow.com/questions/70793162/android-12-not-showing-correct-permissions-request-screen – lasagnakid77 Jan 26 '22 at 19:35
  • Wow! thanks for answering so fast! you made my day! Just needed to add tools:remove="android:maxSdkVersion" to the FINE_LOCATION permission in the manifest. Thank you! – Meyben Jan 26 '22 at 19:54

1 Answers1

9

Thanks to lasagnakid77 i finally got it to work, thanks!

Just add tools:remove="android:maxSdkVersion" to the LOCATION_PERMISSION like so:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" tools:remove="android:maxSdkVersion" />

A good explanantion why is here:Android 12 not showing correct permissions request screen

Meyben
  • 451
  • 3
  • 15