The following code neither creates the directory nor stores the photo in the directory that must be created.I do not know where the bug comes from, I'm searching the internet, but I can not find useful information. Do you see any fault?
mImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//Creamos la carpeta.
File imageFolder = new File(Environment.getExternalStorageDirectory() + "/LibretaPolicial");
if(!imageFolder.exists()){
imageFolder.mkdirs();
Toast.makeText(BorrarActivity.this, "Creado", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(BorrarActivity.this, "NOOOOO creado", Toast.LENGTH_SHORT).show();
}
File image = new File(imageFolder, numeroAleatorio+".jpg");
Uri uriSavedImage = Uri.fromFile(image);
//Le decimos al Intent que queremos guardar la imagen.
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
//Lamzamos la aplicación de la camara
startActivityForResult(cameraIntent, 1);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//Comprovamos que la foto se a realizado
if (requestCode == 1 && resultCode == RESULT_OK) { //requestCode: 1 requestCode : 0
//Creamos un bitmap con la imagen recientemente
//almacenada en la memoria
Bitmap bMap = BitmapFactory.decodeFile(
getExternalStorageDirectory()+
"/LibretaPolicial/"+numeroAleatorio+".jpg");
//Añadimos el bitmap al imageView para
//mostrarlo por pantalla
mImageView.setImageBitmap(bMap);
}
}
I believe the permissions in the AndroidManifest well and does not show me any errors, just do not create the directory or store the photo in the directory that should have been created.
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Activities.SplashActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN"
android:screenOrientation="portrait"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".Activities.MainActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Activities.BorrarActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Activities.ModificarActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Activities.BorrarPlacasActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Activities.ModificarPlacaActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Activities.ClaveActivity"
android:screenOrientation="portrait">
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE">
</uses-permission>
</manifest>