I am trying to create a folder in android when calling the makeDir("FolderCreated") method, it is created in the following path:
/ROOT/Android/data/com.AppName/files/FolderCreated
package com.example.liferegisterdiary;
import android.content.Context;
import java.io.File;
/*
* This is a file and folder controller 2021
* Here you create and read files and folders.
*/
public class FileFolderController {
/*
* In MainActivity.java
* Context context = this;
* and then
* fileFolderController = new FileFolderController(context);
*/
Context context;
public boolean mkdirStatus;
public FileFolderController(Context context) {
this.context = context;
mkdirStatus = true;
}
public boolean makeDir(String folderName) {
try {
String intStorageDir = this.context.getExternalFilesDir("") + "";
File newFolder = new File(intStorageDir, folderName);
return newFolder.mkdirs();
} catch (Exception e) {
return false;
}
}
public boolean existsDir(String folderRoute) {
try {
String intStorageDir = this.context.getExternalFilesDir("") + "";
File newFolder = new File(intStorageDir, folderRoute);
return newFolder.exists();
} catch (Exception e) {
return false;
}
}
}
What I want is to know how the makeDir("FolderCreated") method creates a folder for me in the root... that is, that it doesn't go to Android/data/com.APPName but creates it in the main root .
that is /ROOT/FolderCreated
Previously it was possible, but as of Android 10 it was defined that you cannot create files or directories outside the application structure , you can only create files or directories inside:
no matter if you use
getFilesDir()
orgetExternalFilesDir()