How to get '/storage/emulated/0/Android/media/$packageName' folder path programmatically?

1 day ago 1
ARTICLE AD BOX

Currently I can use both

val path: File? = Environment.getExternalStorageDirectory()?.let { File(it, "Android/media/${context.packageName}") }

and

val path: File? = context.externalMediaDirs.firstOrNull()

Is there any better way to get the path considering externalMediaDirs is deprecated? Note that I want the path to store non media files there.

I was intending to use externalMediaDirs to get /storage/emulated/0/Android/Media/<package name> without hardcoding but according to this article by CommonsWare, if the returned array contains 2+ items, the first one usually will be the removable storage (let's assume microSD card) which is not what I want.

Read Entire Article