0

I'm using Android's Storage Access Framework in a Xamarin application to allow the user to save SQLite3 files to the SD card and also open files from the SD card.

To save the file:

Intent save = new Intent(Intent.ActionCreateDocument);
save.AddCategory(Intent.CategoryOpenable);
save.SetType("application/*");
save.PutExtra(Intent.ExtraTitle, "database.db3");
StartActivityForResult(save, 40);

How can I save an existing db3 file instead of creating this new empty one?

To open the file:

Intent read = new Intent(Intent.ActionOpenDocument);
read.AddCategory(Intent.CategoryOpenable);
read.SetType("application/*");
StartActivityForResult(read, 50);

When the file is opened how do I access it in the code?

  • Does this answer your question? [Using SAF File Picker in Android 10 (Q) to copy files from Downloads to local app folder](https://stackoverflow.com/questions/58899075/using-saf-file-picker-in-android-10-q-to-copy-files-from-downloads-to-local-ap) – Andrew Mar 15 '23 at 19:09
  • Basically you get back a `Uri` in your `onActivityResult` (the old way of doing it) and then you can get and input or output stream from the Uri and then you can write/read your data from these streams. – Andrew Mar 15 '23 at 19:14

1 Answers1

0

You can check the Access documents and other files from shared storage. On Android 11 (API level 30) and higher, you cannot use the ACTION_OPEN_DOCUMENT_TREE intent action to request access to the following directories:

  • The root directory of the internal storage volume.

  • The root directory of each SD card volume that the device manufacturer considers to be reliable, regardless of whether the card is emulated or removable. A reliable volume is one that an app can successfully access most of the time.

  • The Download directory.

You can use the FileOutputStream and here is the sample about How to properly save a file in a shared folder in Xamarin?

Guangyu Bai - MSFT
  • 2,555
  • 1
  • 2
  • 8