I am trying to save image to SD card and I added some code for it.But after clicking the “OK”/Checkmark in the camera, my app exits.Would I have to check if the directory that I am trying to store it in exists?How would i do that?.. !file.exists(){file.mkdirs}? ..In my code I have tried to store it in /Android folder which exists in every SD card.
file = new File(Environment.getExternalStorageDirectory().getPath()
+ "/Android/" + "bhe_app" + ".jpg");
imageUri = Uri.fromFile(file);
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(i, cameraData);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
iv.setImageBitmap(bmp);
}
}
Create the directory before creating the File.
the variable
createdDirectorywill beYou will have to make sure that your app has the permission to write to the SD Card(Check your
AndroidManifest.xml)