0
Xamarin Platform Visual StudioでC#を使用してAndroidアプリを構築しました。 私は、ユーザーがアプリケーションから直接GPSを有効にするAlertDialogを構築しようとしています。あるいは、彼を場所の設定に送ることさえできます。これまではGPSが有効かどうかをチェックするこのコードを持っています。私が必要とするのは、AlertDialogのOnClickボタンを使ってアプリケーションからGPSを有効にしたり、設定を開く方法です。AlertBoxからGPSを有効にする
var locationIntent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
locationIntent.SetFlags(ActivityFlags.NewTask);
context.StartActivity(locationIntent);
:あなたが好きなものを記述する必要が
https://developer.xamarin.com/api/field/Android.Provider.Settings.ActionLocationSourceSettings/
:
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*/});