I have added the following permissions in AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Application can create any file or directory under the filesDir (See below code). But it can't create any custom directory in the "/storage/emulated/0/".
TestActivity.java
public void test(Context context) {
File filesDir = context.getExternalFilesDir(null);
System.out.println("filesDir: " + filesDir.getAbsolutePath());
File subFilesDir = new File(filesDir, "SubFilesDir");
boolean subFilesDirCreated = subFilesDir.mkdirs();
System.out.println("subFilesDir: " + subFilesDirCreated + ", exists: " + subFilesDir.exists());
File testDir = new File("/storage/emulated/0/TestDir");
boolean testDirCreated = testDir.mkdirs();
System.out.println("testDir: " + testDirCreated + ", exists: " + testDir.exists());
}
Here is the output: (The testDir can't be created!)
I/System.out: filesDir: /storage/emulated/0/Android/data/com.testapp/files
I/System.out: subFilesDir: true, exists: true
I/System.out: testDir: false, exists: false
It shouldn't relate to the "root" permission because it is just "/storage/emulated/0/". All applications should be able to create any custom file or dir in that directory.
What's the problem? How to fix?
Thanks.