I can't get permission to manage external storage on Android 11

I'm trying to add an intent to work with external storage files, but the "Settings" class does not contain this permission

// Android 11
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
    try
    {
        Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
        intent.AddCategory("android.intent.category.DEFAULT");
        intent.SetData(Android.Net.Uri.Parse(String.Format("package:%s", Android.App.Application.Context.PackageName)));
        StartActivityForResult(intent, 2296);
    }
    catch { }
}

how to solve this?

I hope for your help, thank you in advance

Upvotes: 1

Views: 1904

Answers (2)

Wendy Zang - MSFT
Wendy Zang - MSFT

Reputation: 10958

You could use Android.Provider.Settings.

Change:

Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);

To:

Intent intent = new Intent(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission);

Upvotes: 1

Vaibhav Goyal
Vaibhav Goyal

Reputation: 1972

I think you are not encountering an error, it is just giving you a warning because this Settings is only available on Android R onwards and you are targeting below that, that's why it is showing Warning. For me it's working perfectly fine. And if it's an error, make sure you imported Settings from the android.provider.Settings.

Upvotes: 0

Related Questions