Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

google maps - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...