how i can grant permission WRITE_SETTINGS in the app

johncanyon 201 Reputation points
2021-09-22T16:11:14.033+00:00
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" />

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,298 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,321 questions
{count} votes

Accepted answer
  1. johncanyon 201 Reputation points
    2021-09-23T12:25:24.07+00:00

    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

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. eyuel zewdu 0 Reputation points
    2023-08-15T18:09:18.7833333+00:00
    0 comments No comments