How to enable location tracking permissions from app itself?
Solution 1
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
Solution 2
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.
Keerti Purswani
Updated on December 08, 2022Comments
-
Keerti Purswani over 1 year
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?
-
Keerti Purswani over 5 yearsYes, I have added the permissions but I am talking about the case when user explicitly turned off gps permissions. For example- in google maps, you get a pop up to enable it. Simple permissions also deals with app permissions only.
-
Miguel Ruivo over 5 yearsIf the user explicitly turned off permissions for a specific app, that's probably because he doesn't want to use that feature and so he should be aware of such, that's a normal behavior I'd say, and will probably need to enable on the settings himself. However, as I mentioned, with the
simple_permissions
you can ask or check for a specific permission on runtime. -
Keerti Purswani over 5 yearsUser didn't turn off permissions for particular app, he turned off location tracking serices itself - the general settings. Simple permissions are to enable permissions for particular app, not the location tracker itself of the device
-
Miguel Ruivo over 5 yearsI'm afraid it's beyond of the apps capabilities. It's up to the user and system to manage those settings. Same happens if you turn off wifi/data and so on, you'll need to turn those on manually (or, in some scenarios, by any system configuration).
-
Keerti Purswani over 5 yearsThere has to be some way. I have seen it happening in apps like Uber, Ola and google maps itself!
-
Miguel Ruivo over 5 yearsSo we're probably not talking about the same. Anyway, if it's possible with native, it's probably possible with Flutter as well. In the worst case, you'd have to create a platform channel and do it in both android/iOS (if not yet available by any package).
-
Keerti Purswani over 5 yearsI want my app to work on both android and iOS and the permissions that geolocator plugins check are again the app permissions instead of GPS permissions