androidandroid-11android-storage

Not able to create directory in /storage/emulated/0/Android/data/myproject.data/data in android 11


Am trying to create directory in the runtime but it throws file not found exception

Directory where i want to create :/storage/emulated/0/Android/data/myproject.data/data

Android 11 and sdk android-30.0.3

static final String MAIN_DIR = "/storage/emulated/0/Android/data/myproject.data";
String logReportPath = MAIN_DIR+"/logcat";
File logDirectory = new File(logReportPath);
if(!logDirectory.exists())
{

  if(logDirectory.mkdirs()){
 
  }else{

   // always returning false and coming to this else condition .

  }

}else
{

}

Could you please me why am not able to create the directory in runtime in storage?


Solution

  •   String logReportPath = "logcat";
        File fileAddress = getApplicationContext().getExternalFilesDir(logReportPath); //storage/emulated/0/Android/data/YOUR_PROJECT/files/logcat
        if(!fileAddress.exists()) {
            fileAddress.mkdirs();
        }else {
            Log.i("INFO","directory or file not found");
        }