I have the problem that the following code creates the folder and the file in the internal memory.
And as I read in the documentation the path that I invoke getStErnalStoragePublicDirectory
should do it in the SD memory.
I requested the permissions WRITE_EXTERNAL_STORAGE
at run time as well as in the Manifest.
public void writeFile(String text){
String state = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(state))
{
Toast.makeText(this,"mounted",Toast.LENGTH_LONG).show();
if(!Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
{
Toast.makeText(this,"tienes permiso de escritura",Toast.LENGTH_LONG).show();
}
}
File miFile= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
Toast.makeText(this,miFile.getAbsolutePath(),Toast.LENGTH_LONG).show();
File archivo=new File(miFile.getAbsolutePath()+"/micarpeta/");
archivo.mkdirs();
File file=new File(archivo,"Ejemplo.txt");
Toast.makeText(this,file.getAbsolutePath(),Toast.LENGTH_LONG).show();
try{
OutputStreamWriter fos=new OutputStreamWriter(new FileOutputStream(file));
fos.write(text);
fos.close();
}
catch (FileNotFoundException e)
{
Log.e("writeFile",e.getMessage());
} catch (IOException e) {
e.printStackTrace();
}