I use this code to make a folder under /sdcard/Download
String toLocation = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() +
+ "/MyFolder/example.txt";
File toLocationFile = new File(toLocation);
if (!toLocationFile.getParentFile().exists()) {
toLocationFile.getParentFile().mkdirs();
}
The build is targeted to API 30. The code can create folder "MyFolder" in Android 11 device but can't in Android 10 device.
Why does the same call get different result?
Notes:
Not set requestLegacyExternalStorage = true in AndroidManifest; means I am using scoped storage.
No write permission.