0

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.

tomazj
  • 303
  • 3
  • 13
  • Maybe you are forgetting to give the appropriate app permissions after you've installed it from Google Play? – Dan Baruch Jun 29 '22 at 07:45
  • Permission used are the same in both examples. If there weren't correct permission set, local version also wouldn't work. – tomazj Jun 29 '22 at 07:49
  • No, I mean, as part of installing from the Android Studio you approved the needed permissions and when you installed from Google Play you simply forgot to approve those permissions, I'm asking if there's such a possibility – Dan Baruch Jun 29 '22 at 07:57

1 Answers1

0

After much trying I found out that:

Files.createDirectory()

From: java.nio.file did the trick; instead of using mkdir().

tomazj
  • 303
  • 3
  • 13