I am trying to create a PDF file and add it to the internal storage of the android phone. I want to create a directory for my app outside the app data folder so the phone user could access it from its Files system app.
The code I am using to create the folder is the following :
File myDir = new File(getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "MyApp");
if(!myDir.exists()) {
myDir.mkdir();
}
File file = new File(myDir, customer+"_"+date+".pdf");
How can I fix this problem please?
Okay this code leads me to save the file in this location "/storage/emulated/0/Android/data/com.example.myapplication/files/Download/MyApp"
I want to move it to /storage/emulated/0/MyApp
I used to write this code, but now that 'getExternalStorageDirectory' is deprecated
File externalStorageDirectory = Environment.getExternalStorageDirectory();
File dir = new File(externalStorageDirectory, "MyApp");
if (!dir.exists()) {
dir.mkdir();
}