Hi all. I try to open files, change them and save them in android 11+.
I know that you need permission to access all files. I receive it.
if (Android.OS.Environment.IsExternalStorageManager)
{
await DisplayAlert("Android VERSION R OR ABOVE", "HAVE MANAGE_EXTERNAL_STORAGE GRANTED!", "ОК");
}
else
{
await DisplayAlert("Android VERSION R OR ABOVE", "NO HAVE MANAGE_EXTERNAL_STORAGE GRANTED!", "ОК");
string package = AppInfo.Current.PackageName;
var uri = Android.Net.Uri.Parse($"package:{package}");
Platform.CurrentActivity.StartActivityForResult(new Intent
(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission, uri), 10);
}
When opening a file, I get its uri and create a file.
Intent intent = Intent;
var uri = intent.Data;
string uriPath = uri.Path;
Java.IO.File file = new Java.IO.File(uriPath);
string fullFilePath = file.AbsolutePath;
string f = file.Path;
Launcher.OpenAsync(new OpenFileRequest
{
File = new ReadOnlyFile(fullFilePath)
});
If I get the path from a file and try to display it, I get an error.
Tell me how to open files correctly, modify them and save them in the same path?
The MAUI file selector is not suitable for this purpose. It copies the file to the application's cache. In other words, I need to get the text editor to work.