Forum Cross Platform with Xamarin

Setting WRITE_SETTINGS in application

Hi,

I'm dealing with being able to handle the Flight mode of mobile phone.

In the manifiest (i.e. Android) I have set WRITE_SETTINGS permission in Properties. As far as i know, it should be granted once the user install the app.

Now I'm in development phase and testing the app using Live Player in my Android device.

As I run the app in debug mode, there's no grant access permission dialog available, so It's supposed that as I'm in debug mode, such permissions are granted.

My intention is to switch on/off Flight mode in the phone.

My code is:

const string permission = Manifest.Permission.WriteSettings;
Context context = Android.App.Application.Context;
if (ContextCompat.CheckSelfPermission(context, permission) == (int)Permission.Granted)
{
         Android.Provider.Settings.Global.PutInt(context.ContentResolver, Android.Provider.Settings.Global.AirplaneModeOn, 1);
         return true;
} else {
         Toast.MakeText(context, "No podemos activar el Modo Avión para cambiar IP en la Red!", ToastLength.Long).Show();
}

When my app is running and try to set AirplaneMode to true, the device shows the Toast Message.

What's misssing? What should I do?

Sign In or Register to comment.