I want my Android application to create a public folder in the internal storage of the phone. I want to save some text files there that I want to be available even after the application uninstalls.
The goal is to create some txt that I want to transfer to my PC for further analysis. I wanted to try the Environment.DIRECTORY_DOCUMENTS, but the targeted phone is old and it doesn’t have the folder.
I have read the documentation but I can’t find any solution. I also tried to hard code the folder, but still it wont be created. I just want to have a folder like the picture camera folder.
I have tried this but it doesn't work.
Here is the code that I use:
File file = new File("/folder to create here", "name of file here" + File.pathSeparator + "txt");
if (!file.mkdirs())
Log.e(getClass().toString(), "Save Data -> Directoy not created");
try {
fos = new FileOutputStream(file);
fos.write(saveString.toString().getBytes());
fos.flush();
fos.close();
}
catch (Exception e){
if (e instanceof FileNotFoundException) {
Toast.makeText(getApplicationContext(), "Could not create file, please try again", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
if (e instanceof IOException) {
Toast.makeText(getApplicationContext(), "Could not write in file, please try again", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
Is there any way to do it or not. There are many application like viber that create folders in the root.
Thanks in advance for your help.