如何打开位置设置页面或提示用户启用位置 [英] How do I open location settings page or prompt user to enable location

查看:128
本文介绍了如何打开位置设置页面或提示用户启用位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我一直在乱砍我的大脑并徒劳无功地搜索。我试图找到一种方法来提示用户通过直接进入设置页面或只是在屏幕上点击是来切换位置。

我见过的所有代码似乎都没有工作。任何人都有一些有用的东西。一个详细的例子将非常感谢。谢谢。

我是Xamarin开发的新手



我尝试了什么:



 public static bool CheckGPSConnection()
{
var gpsConnection = DependencyService.Get< IGPSConnectivity>();
返回gpsConnection.CheckGPSConnection();
}





AND



 if(Device.OS == TargetPlatform.Android)
{
if(!App.CheckGPSConnection())
{
bool answer = await DisplayAlert(Alert,你想开始GPS吗?,是,否);
if(answer)
{
Android.App.Application.Context.StartActivity(new Android.Content.Intent(Android.Provider.Settings.ActionLocationSourceSettings));
}
}
}









也尝试了这个,通过按照此处的指示创建依赖服务 android - 如何在xamarin.forms中打开我们的应用程序设置? - 堆栈溢出 [ ^ ]





我也通过创建依赖来尝试这个使用类的服务并编写此代码

< pre> public interface ISettingsService
{
void OpenSettings();
}









 public class SettingsServiceAndroid:ISettingsService 
{
public void OpenSettings()
{
Xamarin.Forms.Forms.Context.StartActivity(new Android.Content.Intent(Android.Provider.Settings) .ActionLocat ionSourceSettings));
}
}







并通过以下方式调用



 DependencyService.Get< ISettingsService>()。OpenSettings(); 

解决方案

一段时间后我自己找到了解决方案..我在这里给出了我的解决方案打开位置设置页面或提示用户启用位置 - Xamarin论坛 [ ^

hello,
i've been hacking my brain and googling away in vain. i am trying to find a way to prompt the user to switch location on either by going directly to the settings page or just tapping yes on the screen.
all code i've seen doesn't seem to work. does any one have something that works. a detailed example will be much appreciated. thank you.
I'm really new to Xamarin development

What I have tried:

public static bool CheckGPSConnection()
        {
            var gpsConnection = DependencyService.Get<IGPSConnectivity>();
            return gpsConnection.CheckGPSConnection();
        }



AND

if (Device.OS == TargetPlatform.Android)
{
    if (!App.CheckGPSConnection())
    {
        bool answer = await DisplayAlert("Alert", "Would you like to start GPS?", "Yes", "No");
        if (answer)
        {
              Android.App.Application.Context.StartActivity(new Android.Content.Intent(Android.Provider.Settings.ActionLocationSourceSettings));
        }
    }
}





also tried this , by creating a dependency service as instructed here
android - How to open setting from our application in xamarin.forms? - Stack Overflow[^]


I also Tried This by creating dependency service using a class and wrote this code 

<pre>public interface ISettingsService
{
    void OpenSettings();
}





public class SettingsServiceAndroid : ISettingsService
{
    public void OpenSettings()
    {
        Xamarin.Forms.Forms.Context.StartActivity(new Android.Content.Intent(Android.Provider.Settings.ActionLocat‌​ionSourceSettings));
    }
}




and called it by the below

DependencyService.Get<ISettingsService>().OpenSettings();

解决方案

found the solution myself after a while.. i gave my solution here Opening Location Settings Page or Prompting user to Enable Location — Xamarin Forums[^]


这篇关于如何打开位置设置页面或提示用户启用位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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