androidfilemkdirs

I am unable to create a folder for my app within my external storage


In the beginning the code was working perfectly. But when I deleted the file from my internal storage to test the code it stopped working and every time it is returning 'false' from the mkdirs() function.

I reinstalled the app several times, cleared caches but it is still not working. I have also granted the permission to write in external storage.

File direct = new File(Environment.getExternalStorageDirectory()+"/My App/Media/Images/Saved Images");

if (!direct.exists()) {
    boolean b=direct.mkdirs();
    System.out.println("Value"+b);
}

Solution

  • Okay I found the solution. In API 29 the getExternalStorageDirectory() is deprecated. Instead of that I used

    File direct=new File(Objects.requireNonNull(getApplicationContext().getExternalFilesDir(null)).getAbsolutePath()+"/My App/Media/Images/Saved Images");