hiba
hiba

Reputation: 41

Flutter geolocator, No location permissions defined in manifest. Make sure at least ACCESS_FINE_LOCATION or.... are defined in the manifest

I am using geolocator in flutter and i have defined permissions in manifest file but it keeps telling me that i haven't.

Manifest File:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="packagename">

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

Geolocator code:

class _LoadingScreenState extends State<LoadingScreen> {

  void getLocation() async{
    bool serviceEnabled;
    LocationPermission permission;

    serviceEnabled = await Geolocator.isLocationServiceEnabled();
    if (!serviceEnabled) {
      return Future.error('Location services are disabled.');
    }

    permission = await Geolocator.checkPermission();
    if (permission == LocationPermission.deniedForever) {
      return Future.error(
          'Location permissions are permantly denied, we cannot request permissions.');
    }

    if (permission == LocationPermission.denied) {
      permission = await Geolocator.requestPermission();
      if (permission != LocationPermission.whileInUse &&
          permission != LocationPermission.always) {
        return Future.error(
            'Location permissions are denied (actual value: $permission).');
      }
    }
    Position position= await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
    print(permission);
    print(position);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: (){
            getLocation();
          },
          child: Text('Get Location'),
        ),
      ),
    );
  }
}

I'm testing the app on my physical device. Please tell me what i should do for this to work.

Upvotes: 3

Views: 4342

Answers (2)

Valters Šverns
Valters Šverns

Reputation: 11

Before getting any location ask for permission first:

  await Geolocator.requestPermission();

Upvotes: 1

user16096259
user16096259

Reputation:

The only thing wrong is the string inside "android.name".

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

The correct is:

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

Upvotes: 4

Related Questions