Keerti Purswani
Keerti Purswani

Reputation: 5361

How to enable location tracking permissions from app itself?

I am using google_maps_flutter and location plugins to show user's location in my app. I want to enable gps permissions from my app itself, it seems trivial but when I tried using plugins (like permission plugin), I am able to enable only app permissions to access location and not the gps permissions. I am able to check the location and give a toast if permission isn't there but how do I enable it from app itself?

Upvotes: 2

Views: 2148

Answers (2)

Ian
Ian

Reputation: 13842

I think what you want is to open the location settings, rather than the permissions, which is included in the AndroidManifest. Also most geolocator plugins have a request permissions method in them, if you need that, rather than the settings.

Assuming you want the user to open and turn on the location, in Android, I think you would need to create an intent, so it would look something like this..

import 'package:android_intent/android_intent.dart';

Then in your class...

static Future makeLocationDialogRequest() async { 

  final AndroidIntent intent = new AndroidIntent(
    action: 'android.settings.LOCATION_SOURCE_SETTINGS',);

  intent.launch();
}

And then later maybe do a check using your plugin of choice to check if the user did in fact enable the location.

Note, this is for Android only, so do a check beforehand if its an Android device,eg

var platform = Theme.of(context).platform;

With further info on android_intent here

Upvotes: 3

Miguel Ruivo
Miguel Ruivo

Reputation: 17746

Usually, you only need to include the permissions on the manifest.xml file (on Android), such as:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.INTERNET" />

or on iOS by adding this values to your info.plist

NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription

However, if you want to check or ask for a particular permission in runtime you can do so with simple_permissions package.

Upvotes: 2

Related Questions