1

I've been searching for a good 7hrs now as to how to create a directory in Internal Storage upon the starting of the app for the first time (similar to what WhatsApp and many other apps do)

I came to the conclusion that this code doesn't work anymore since it's deprecated, and starting from Android 11 it just doesn't work

File file = new File(Environment.getExternalStorageDirectory(),"AppName");
file.mkdirs();

I've seen in a YouTube comment that it's simply not possible to do what I'm aiming for starting from Android 11, and that the most I can do is create the directory in Internal Storage/Android/data/data/com.example.myapp but how is it not possible? I've seen many apps having that feature

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Storage Access Framework should still work: https://stackoverflow.com/questions/36546606/how-to-create-new-folder-in-sd-card-by-using-storage-access-framework – ashu May 13 '21 at 03:32
  • @ashu It states in the answer that the user "chooses " where the app's directory is created, isn't there a way that would automatically create the directory when the user starts the app for the first time? – YoussefHammad May 13 '21 at 03:39
  • 1
    I think that's the point of removing direct storage access in recent versions. Google wants Android users to know when an app writes their storage – ashu May 13 '21 at 03:57
  • @ashu But in the case of WhatsApp, Telegram and a few others (MyBoy, MatsuPlayer, CamScanner, Dcoder, those are the ones I have) There's a directory created for them already without me choosing where exactly that directory should exist. The only possible exmplanation for that is that these directories were created before that update, but I remember I downloaded one of them recently – YoussefHammad May 13 '21 at 04:08
  • 1
    We don't know if those apps are targeting Android 11 yet. Once they do, they shouldn't be able to have regular access to the external file system on Android 11 and higher. – ashu May 13 '21 at 04:11
  • 1
    Looks like everyone **will be** forced to migrate from legacy to newer storage model on targetting Android 11. https://developer.android.com/about/versions/11/privacy/storage – ashu May 13 '21 at 10:17

0 Answers0