Xamarin Android create txt file that is editable by other app

Viewed 135

I have a Xamarin Android App where I want to create a txt file that is editable by another app

For now, I've successfully created the file with this code

string content = "this is content of the file";
string path = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Documents");
File.WriteAllText(path, content);

But I can not edit that file with another App like TurboEditor or by Windows Notepad (if I connect my device to a windows machine). It seems like the file is set to readonly, and only my app can edit it.

TurboEditor throwing exception Permission Denial:Writing com.sec.android.app.myfiles.external.providers.MyFilesFileProvider uri content://com.sec.android.app.myfiels.FileProvider/device_storage/Documents/file.txt from pid=895, uid-10219 requires the provider to be exported, or grantUriPermission()

So how can I achieve this?

NB :

  • I cannot edit the file, but I can delete it from android file explorer
  • I create the file on External Storage in Documents folder
  • TurboEditor is an app just like Notepad but on android, it's available on playstore
1 Answers

Finally, I can edit the file. So with the code that I posted, you should be able to edit the file

I don't know why this happens, but here's how I found it

I can edit the file if

  • Open TurboEditor
  • Browse the file to edit
  • Edit and save the file

BUT I cannot edit the file if

  • Open My Files v 11.5.01.341 (Samsung file explorer)
  • Browse the file that I want to edit
  • Click on the file then popup "Open with" will show up and I choose TurboEditor
  • Edit and save the file
  • BOOM exception occurred

I'm using Android 10 with Samsung Galaxy Tab A 2019 Model SM-T515

Related