Hello,
I assume I have to find a way to write some platform specific code to ask for this permission?
Yes, this permission needs to open the android application settings page, then grand this permission by users.
You can use Conditional compilation for android platform code.
For example, you want to request this permission in the button click event. you can popup a SnackBar, tell user about this permission needed and let user to click.
private void OnCounterClicked(object sender, EventArgs e)
{
#if ANDROID
var activity=Platform.CurrentActivity;
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.R)
{
if (!Android.OS.Environment.IsExternalStorageManager)
{
Google.Android.Material.Snackbar.Snackbar.Make(activity.FindViewById(Android.Resource.Id.Content), "Permission needed!", Google.Android.Material.Snackbar.Snackbar.LengthIndefinite)
.SetAction("Settings", new MyClickHandler()).Show();
}
}
#endif
}
Next, you need to implement the Android.Views.View.IOnClickListener interface for SnackBar. It will open the application settings page; user need to grand the manager external permission.
#if ANDROID
internal class MyClickHandler : Java.Lang.Object, Android.Views.View.IOnClickListener
{
public void OnClick(Android.Views.View v)
{
try
{
Android.Net.Uri uri = Android.Net.Uri.Parse("package:" + Platform.CurrentActivity.ApplicationInfo.PackageName);
Android.Content.Intent intent = new Android.Content.Intent(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission, uri);
Platform.CurrentActivity.StartActivity(intent);
}
catch (Exception ex)
{
Android.Content.Intent intent = new Android.Content.Intent();
intent.SetAction(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission);
Platform.CurrentActivity.StartActivity(intent);
}
}
}
#endif
In the end, please open the AndroidManifest.xml
and add <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
permission.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.