Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission requests are not propagated when launching with flutter but are when launching with android directly

I try to request permissions to use location data with a flutter app. I am using the geolocator plugin and permission_handler. Both added to my pubspec.yaml.

I have futhermore added

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

to my android/app/src/main/AndroidManifest.xml.

The first thing I do when I launch my app, is

PermissionHandler().requestPermissions([PermissionGroup.location]).then((val) {
  ...
});

If I then run this on either an emulator or on my physical phone, it returns a PermissionStatus.unknown and subsequent calls to GeoLocator() spams the console with

No permissions found in manifest for: $permission 

If I go into app-settings it says that no special permissions were requested.

When I then open up the exact same project as an Android project (I am using Android Studio for both, there is a neat dropdown option to open Android project in Android Studio) and run it on my phone it works as expected - it asks for the permission and if I go into the app-settings I can also see the requested permission there.

Anyone have any idea why it does not get "propagated" with flutter?

like image 889
gedemagt Avatar asked Dec 04 '22 18:12

gedemagt


1 Answers

It seems like the main issue is that the AndroidManifest.xml is not updated when simply relaunching the application. If, however, one first do a flutter clean and then rebuilds it, the AndroidManifest.xml is updated.

I am not sure if this the intended behavior, but it works. Just something to remember.

like image 149
gedemagt Avatar answered Dec 06 '22 10:12

gedemagt