How to access my apps' legacy files in Environment.ExternalStorageDirectory in android 11 & 12?

Axiixa 21 Reputation points
2022-02-15T18:14:45.07+00:00

When I wrote this app I used Environment.ExternalStorageDirectory as the root for my app directory structure ("/Storage/Emulated/0/MyAppName"). My earlier updates used Android Target Version 9 (Android 28) and my current update uses Android target 10 (API 29). The app no longer has privs to access these files. These are SQlite files and a couple of subfolders. I used Visual Studio and Xamarin Android to develop and release the app.
I can't find anything that addresses how to access these files and move them into the apps private storage for use post Android 11. Is this even possible? Am I completely hosed?
Any help would be immensely appreciated!

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,971 Reputation points
    2022-02-16T06:09:06.673+00:00

    Hello @Axiixa ,​

    Welcome to our Microsoft Q&A platform!

    access my apps' legacy files in Environment.ExternalStorageDirectory in android 11 & 12

    The Environment.ExternalStorageDirectory is deprecated since Android API 29. Apps target Android 10 and higher are given scoped access into external storage. In this case, try using getExternalFilesDir() method or media store api to store the file.

    Or you could include MANAGE_EXTERNAL_STORAGE permission for your application to access the external storage.

    Here is the related doc, you could refer to it.
    https://developer.android.com/about/versions/10/privacy/changes#scoped-storage
    https://developer.android.com/training/data-storage#permissions

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.