Home > Back-end >  allowed File locations under Android 11
allowed File locations under Android 11

Time:11-04

I encounter a problem, since i want to recompile my App for the new Android 11 and above. And i think the core problem i have is with this scoped storage. Is there any List of allowed Filepaths where i can still read/write as i want or do i really have to integrate this MediaAccess API?

My Filepath to go would be as follows:

    public static string XmlFilename = "Arbeitszeiten.xml";
    public static string filepath = "/storage/emulated/0/Documents/Arbeitszeiten";

Until Android 10 it worked fine, since i want to save/edit/read a .xml file on the Device itself i need a "allowed" filepath. I thought that Scoped Storage blocks the Access to the /Android/data and ../obb folder. And that the Downloads, Pictures, Documents are Folders still accessible.

CodePudding user response:

I've had a problem looks like yours on Android 11 in kotlin. I solved it like this:

  1. I added file_path.xml in path src/main/res/xml

    FilePath

  2. I've used getExternalFilesDir for get file in the device storage.

Before:

val mPath = Environment.getExternalStorageDirectory().toString()   "/Ticket_"   date   ".jpeg"

After:

 val mPath = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).toString()   "/Ticket_"   date   ".jpeg"

I hope help you :)

CodePudding user response:

What helped me was to adapt my minimum Version to Android 10 API 29 and the Target Version to Android 11 API 30 in the Manifest. Since i didn't found the android:requestLegacyExternalStorage Permission i think it's only a temporary solution, but for now it works.

  • Related