• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Creating a Directory After Android 11

I've been searching the internet for almost 7hrs now, I can't seem to find a code that works and it took me a while to find out that the method below no longer works and is deprecated

Code:
File file = new File(Environment.getExternalStorageDirectory(),sName);
file.mkdirs();

Also tried adding android:requestLegacyExternalStorage="true" in the manifest but still the same result.

So my question is: Is it possible to create a directory directly in internal storage automatically when the app starts for the first time, similar to what WhatsApp does?

Like if someone downloads and opens the app for the first time there'd be a new directory created (after gaining the permission to do so) in Internal Storage directly (not in Android/data sub-folders) for the app files in the future

And if it's possible, how can I do such a thing?

I'd be very grateful for as little as any pointer in that direction, I've been on this issue for much more time than I expected

Thank you in advance
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones