Search code examples
androidflutterandroid-permissionsflutter-dependencies

Background location permission auto-added in Android with flutter location plugin


I recently added the Flutter location plugin to allow my app to use GPS. Everything is working as expected on iOS and App Store, but when building for Android (targetSdkVersion 29 / API level 29) and uploading to Google Play it tells me that the background location permission is present. I can verify that by looking in the build where the

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

line is added to the AndroidManifest.xml file.

However, my app doesn't use location in the background, and I just can't find out how I remove this permission that is being automatically added by the location plugin.

The only code that uses location plugin is this line I have in a method:

LocationData userLocation = await new Location().getLocation();

Solution

  • The permission is introduced by the location plugin. If you go to its manifest you'll find the following requested permissions:

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

    To remove it add

    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
                         tools:node="remove"/>
    

    to your apps Manifest.