I am making an app in which I am trying to create the "Download/Datax" directory and write txt files to the external SD memory and I am using this code:
File directorioExt = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOCUMENTS ), "/Download/Datax/" );
if (!directorioExt.exists()) {
File directoriox = new File( Environment.getExternalStorageDirectory() + "/Download/Datax/" );
directoriox.mkdirs();
}
But the directory cannot be created in external memory. I have also placed in the manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Can someone tell me how to achieve this?
Actually your code is correct:
One of the reasons why you could not create the specified directory is not having the permission
WRITE_EXTERNAL_STORAGE
, for devices with Android 6.0 operating system it is not enough to define it in the fileAndroidManifest.xml
, you must request it manually:Check this answer:
Error displaying external file directory in an AlertDialog in android 6.0 (READ_EXTERNAL_STORAGE / WRITE_EXTERNAL_STORAGE )