Hello,
Welcome to our Microsoft Q&A platform!
Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDocuments)
is deprecated, And We no longer have access to create a directory on Android 10+ in the public external storage, here is simlar thread, you can refer to it.
https://stackoverflow.com/a/58379655/8354952
I recommend you to use following path, you can store DB files into your own application's external storage (here is path :"/storage/emulated/0/Android/data/com.companyname.rrecordaudiopermission1/filesfilename.png")
string testPath= Android.App.Application.Context.GetExternalFilesDir("").AbsolutePath + $"{filename}.png";
===================
Update=========================
If you user could grand the android.permission.MANAGE_EXTERNAL_STORAGE
, you can create a folder in the android 11.
First of all, add this permission in your AndroidManifest.xml
.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
Then, use Snackbar
to grand the permission.
if (!Environment.IsExternalStorageManager)
{
Snackbar.Make(FindViewById(Android.Resource.Id.Content), "Permission needed!", Snackbar.LengthIndefinite)
.SetAction("Settings", new MyOnClickListener(this)).Show();
}
internal class MyOnClickListener:Java.Lang.Object,View.IOnClickListener
{
private MainActivity mainActivity;
public MyOnClickListener()
{
}
public MyOnClickListener(MainActivity mainActivity)
{
this.mainActivity = mainActivity;
}
public void OnClick(View v)
{
// throw new System.NotImplementedException();ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
try
{
mainActivity.StartActivity(new Intent(
Android.Provider.Settings.ActionManageAllFilesAccessPermission,
Android.Net.Uri.Parse("package:" + Android.App.Application.Context.PackageName)));
}
catch (Exception ex)
{
Intent intent = new Intent();
intent.SetAction(Android.Provider.Settings.ActionManageAllFilesAccessPermission);
mainActivity.StartActivity(intent);
}
}
}
}
If you user grand this permission, you can create folder like following screenshot.
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
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.