Flutterlocation: Android - requestPermission not asking for permission

Created on 13 Apr 2019  路  7Comments  路  Source: Lyokone/flutterlocation

Describe the bug
When calling location.requestPermission(), Android does not ask for permission

Expected behavior
A popup should appears, asking for permission

Tested on:

  • OnePlus 6 (Android 9)
  • Pixel XL Emulator (API 28)

Additional logs

Exception has occurred. PlatformException (PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission denied forever- please open app settings, null))

I also created this thread on Stackoverflow.

Future<LocationData> _getLocation() async {
  LocationData currentLocation;

  var test = await location.requestPermission();

  try {
    currentLocation = await location.getLocation();
  } catch (e) {
    currentLocation = null;
  }
  return currentLocation;
}

When I go to the app Settings on my OP6, the permissions is greyed out, saying "no permissions requested"

Most helpful comment

Okay it seems setup correctly. That's strange because when you add the plugin to your app, Flutter is supposed to automatically add the requested permission in your AndroidManifest.xml so it should appear in your app's settings.
Can you try to do a flutter clean to see if this is not a build problem ?

All 7 comments

Hey, if there is no permission requested in your app's settings, are you sure to TargetSDK 28 in your build.gradle ?

I have two build.gradle files, one in root of appfolder, and one in srcfolder.
I don't see this line in the first file, but I do see this in the second one :

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.mobile_app"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Okay it seems setup correctly. That's strange because when you add the plugin to your app, Flutter is supposed to automatically add the requested permission in your AndroidManifest.xml so it should appear in your app's settings.
Can you try to do a flutter clean to see if this is not a build problem ?

omg, you are a genius, I got the popup !

Thank you !

Hehe glad it worked 馃榿

I'm glad I wasn't the only having this problem

Hi @Lyokone,
I just got stuck with this same problem. Could I recommend adding the flutter clean to the READM? I'm not sure how possible it would be but can you somehow check if the permission has been added to the AndroidManifest.xml?
Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zanecidan picture zanecidan  路  6Comments

lehno picture lehno  路  5Comments

zeienko-vitalii picture zeienko-vitalii  路  7Comments

magicznyadrian picture magicznyadrian  路  3Comments

giudon010 picture giudon010  路  3Comments