0

I want to implement functionality that allows an Android user to write a file to their devices SD card and have the ability to pop that SD card into a different device and access the file from the new device - in case their original device is damaged and no longer usable.

I'm able to write to the SD card, getting the path like so:

Java.IO.File[] externalFilesDirs = Android.App.Application.Context.GetExternalFilesDirs(null);

if (externalFilesDirs.Any())
{
    string externalSdPath = externalFilesDirs.Length > 1 ? externalFilesDirs[1].AbsolutePath :  externalFilesDirs[0].AbsolutePath; 
}

However, this stores the file in an app-specific folder that I'm unable to access from another app, or the same app on a different device.

I'm targeting Android 11 and I know that scoped storage is the standard now, but is there any way to write to a non-app specific folder on the SD card or access the app-specific folder outside of the app that created it?

2 Answers2

0

Standard now is using SAF.

Storage Access Framework.

Let the user select the removable micro sd card with ACTION_OPEN_DOCUMENT_TREE.

After that you can create files on it until full.

blackapps
  • 8,011
  • 2
  • 11
  • 25
0

You can use this code to make the user to access the sd card.

startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), requestCode);

Here is the answer you can refer to Android M write to SD Card.

More information you can check this article about Grant access to a directory's contents

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