Good morning programmers ("the magicians"). I'm going to the following: I need to create files on the SD card, whenever I try to create it ends up creating it in the memory of the phone and not in the external SD. My code is as follows:
String file_path = Environment.getExternalStorageDirectory()+"/Psinapsis/Imagenes/Inventario"
File dir = new File(file_path);
if (!dir.exists()) {
Log.i(Constantes.TAG,"file_path existe NO");
dir.mkdirs();
Log.i(Constantes.TAG,"dirTrue:" + dir.mkdirs());//devuelve FALSO :(
}
I have assembled the following permissions in the manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I've also tried to generate the permissions at run time:
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
// MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}else {
Toast.makeText(getApplicationContext(),"Tengo permiso",Toast.LENGTH_SHORT).show();
}
What have I done wrong? :( obs: I already tried it with mkdir (), like nothing