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.
CodePudding user response:
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 ....