【问题标题】:Pragmatically enable GPS from AlertBox务实地从 AlertBox 启用 GPS
【发布时间】:2017-09-30 13:25:12
【问题描述】:

我在 Xamarin Platform Visual Studio 上使用 C# 构建了一个 Android 应用程序。 我正在尝试构建一个允许用户直接从应用程序启用 GPS 的 AlertDialog。甚至将他发送到位置设置。到目前为止,我有这段代码可以检查 GPS 是否启用。我所需要的只是如何在 AlertDialog 上制作一个 OnClick 按钮,它甚至可以从应用程序启用 GPS 或打开设置。

 LocationManager lm = (LocationManager)GetSystemService(Context.LocationService);
        bool gps_enabled = false;
        bool network_enabled = false;
        gps_enabled = lm.IsProviderEnabled(LocationManager.GpsProvider);
        network_enabled = lm.IsProviderEnabled(LocationManager.NetworkProvider);
if (!gps_enabled && !network_enabled)
        {
            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            dialog.SetTitle("Warning");
            dialog.SetMessage("Your phone location is not enabled" + "\n" + "Please enable your location and run SpeedReport again");
            dialog.SetPositiveButton("Enable", (object sender1, DialogClickEventArgs e1) => {/*i guess i need to enter some code here*/});

【问题讨论】:

    标签: c# android xamarin gps xamarin.android


    【解决方案1】:

    看看这个: https://developer.xamarin.com/api/field/Android.Provider.Settings.ActionLocationSourceSettings/

    你必须写这样的东西:

    var locationIntent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
    locationIntent.SetFlags(ActivityFlags.NewTask);
    context.StartActivity(locationIntent);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 1970-01-01
      • 2021-07-22
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多