如何从应用程序本身启用位置跟踪权限? [英] How to enable location tracking permissions from app itself?

查看:153
本文介绍了如何从应用程序本身启用位置跟踪权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 google_maps_flutter permission 插件),我只能启用应用程序访问位置的权限,而不能启用gps权限.如果没有许可,我可以检查位置并举杯,但是如何从应用程序本身启用它?

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?

推荐答案

我认为您想要打开的是AndroidManifest中包含的位置设置,而不是权限.另外,如果需要,大多数geolocator插件中都有一个请求权限方法,而不是设置.

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.

假设您希望用户打开并打开该位置,在Android中,我认为您需要创建一个intent,因此它看起来像这样.

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.

注意,这仅适用于Android,因此请事先检查其是否为Android设备,例如

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

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

有关android_intent的更多信息,此处

With further info on android_intent here

这篇关于如何从应用程序本身启用位置跟踪权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆