【发布时间】: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