When code bellow as a part of application is executed locally (directly started from Android Studio) it works correct.
String folderName = Environment.DIRECTORY_DOWNLOADS;
File folder = new File(Environment.getExternalStoragePublicDirectory(folderName) + "/SampleApp/");
if (!folder.mkdirs()) {
FirebaseCrashlytics.getInstance().recordException(new Exception("Storage access class: can't create folder");
Log.d("Debug", "Can't create new folder on path: " + folder.getPath());
return false;
}
return folder.exists();
The full path where new folder gets created is:
/storage/emulated/0/Download/SampleApp
But when the same code as a part of application gets uploaded to Google Play and then installed to the same phone, folder can't create and an exception gets triggered. Logged debug path is the same:
/storage/emulated/0/Download/SampleApp
I get the problem only on Android 12 devices. Has something specific changed from Android 11 to 12? I also tried using mkdir()
but end result is the same. Inbetweeen both tests I obviously removed the SampleApp folder, so it doesn't exist when I try app version from Google Play.