1

I am trying to write a new folder in internal storage, however it's not created no matter what I do.

Here is the code I use:

        File file = new File(path,"TestFolder");
        file.mkdirs();
        Log.e("file path","" + file);

The file output is /storage/emulated/0/TestFolder which is the exact path I want to write the storage to, but it's not writing.

I added these permission in the manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

I also added this line android:requestLegacyExternalStorage="true" in the <application> tag.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mr.Goomer
  • 73
  • 7
  • Does this answer your question? [Android create folders in Internal Memory](https://stackoverflow.com/questions/8124612/android-create-folders-in-internal-memory) – DevWithZachary Aug 18 '21 at 14:58
  • No, still doesn't write the folder... – Mr.Goomer Aug 18 '21 at 15:13
  • Note that you do not have rights to create a directory there on Android 11+. – CommonsWare Aug 18 '21 at 15:17
  • @CommonsWare So how come WhatsApp mange writing its main folder to internal storage ? – Mr.Goomer Aug 18 '21 at 15:20
  • Perhaps they still have `targetSdkVersion` set to `29`. That will not be an option for you in a couple of months. Also, WhatsApp is owned by Facebook, and Facebook is able to strike deals with device manufacturers that you and I are not. For example, WhatsApp could be pre-installed on the device, and device manufacturers can grant whatever rights that they want to pre-installed apps. Comparing yourself to WhatsApp is not realistic. – CommonsWare Aug 18 '21 at 15:41

0 Answers0