Android.OS.Environment.GetExternalStoragePublicDirectory is deprecated. Alternative?

I'm currently building a .Net Maui App that is only targeting android. I need to save some data in the public external storage that I can access and copy to my PC and that persists even if I uninstall the app. I choose the Documents directory.

The following does the job:

string dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDocuments).AbsolutePath

But I get a warning from my IDE that GetExternalStoragePublicDirectory is deprecated.

I've found several postings that

Android.App.Application.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryDocuments)

will also work, but that does not return the same result. The deprecated method returns

/storage/emulated/0/Documents

while the other one returns

/storage/emulated/0/Android/data/com.companyname.myappname/files/Documents

Hence the appname is in the path, this is not persistent in case the app is uninstalled. So what is the correct way to get the public external documents directory?



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)