enthusiastdev
enthusiastdev

Reputation: 995

How to access/(read files from) /storage/emulated/0/Android/data/com.abc.appName folderpath in Android 11?

How to access /storage/emulated/0/Android/data/com.abc.appName folderpath? When I am trying to access in that way:

    String path = Environment.getExternalStorageDirectory()+"/Android/data";
    File directory = new File(path);
    File[] files = directory.listFiles();

It is not returning anything, which means the files is null.

Upvotes: 5

Views: 24080

Answers (1)

MustafaKhaled
MustafaKhaled

Reputation: 1489

Simply, you can use

context.getExternalFilesDir(String type)

where type parameter refers to the type of file e.g. Environment.DIRECTORY_PICTURES or Environment.DIRECTORY_MUSIC, etc...

if you would like to access the folder itself, just pass null to getExternalFilesDir method.

val folder = applicationContext.getExternalFilesDir(null)
val files = folder?.listFiles()
Log.d("Your Tag", "onCreate: ${folder?.path}")
Log.d("Your Tag", "onCreate: Your files are ${files}")

this will return the path as:

/storage/emulated/0/Android/data/*yourPackageName*/files

Your files are .... 

Upvotes: 3

Related Questions