I am trying to take a photo and to save it to a custom location-
public void SavePhoto(View view){
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "WorkingWithPhotosApp");
imagesFolder.mkdirs();
File image = new File(imagesFolder, "QR_" + timeStamp + ".png");
Uri uriSavedImage = Uri.fromFile(image);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(imageIntent, REQUEST_IMAGE_CAPTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data==null){
Toast.makeText(MainActivity.this, "Data is null", Toast.LENGTH_SHORT).show();
}
else{
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ImageView mImageView=(ImageView)findViewById(R.id.imageView);
mImageView.setImageBitmap(imageBitmap);
}
}
}
data is null in onActivityResult(). What did I miss?
EXTRA_OUTPUT
. Hence,extras.get("data")
is supposed to benull
. Your photo, if it exists, will be at the location that you specified inEXTRA_OUTPUT
. See github.com/commonsguy/cw-omnibus/tree/master/Camera/Content for one using files and github.com/commonsguy/cw-omnibus/tree/master/Camera/… for one usingFileProvider
. – CommonsWare