question

johncanyon-2528 avatar image
0 Votes"
johncanyon-2528 asked johncanyon-2528 answered

how i can grant permission WRITE_SETTINGS in the app



 var bi = Settings.System.CanWrite(Android.App.Application.Context);
                         if (bi)
                         {
                             Console.WriteLine("IT HAS PERMISIONS`enter code here`");
                         }
                         else
                         {
                             Intent intent = new Intent(Android.Provider.Settings.ActionManageWriteSettings);
                             intent.SetData(Android.Net.Uri.Parse("package:" + Android.App.Application.Context.PackageName));
                             StartActivity(intent);
                             Console.WriteLine("doesnt have permisions");
                         }

i get obviously direct in else execution block, but intent get null what is the problem? how i can grant permissions for write settings? i use xamarin with c# for android mobile AND ALREADY INSERT TO MANIFEST <uses-permission android:name="android.permission.WRITE_SETTINGS" />

dotnet-csharpdotnet-xamarinformsdotnet-xamarinessentials
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, @johncanyon-2528 I created a basic demo to test the code, it works as expected. What error did you face in test? Could you post more details about error log? And do you test the code on another device or emulator? Will that work?

1 Vote 1 ·

1 Answer

johncanyon-2528 avatar image
1 Vote"
johncanyon-2528 answered

Intent intent = new Intent(Settings.ActionManageWriteSettings);
intent.SetData(Android.Net.Uri.Parse($"package:{Android.App.Application.Context.PackageName}"));
intent.AddFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(intent);

in the end work with the code above

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.