I am trying to make an app where the user can take a picture and that picture gets stored in an imageview. I have tried dozens of methods to get this to work.
A lot of answers I've viewed suggest using data.getExtra("data") with using the MediaStore intent and passing in ACTION_CAMERA_CAPTURE. This returns a smaller image and the image I am trying to display is large so the image shows up blurry using this method.
The other option is to use this same method and pass in EXTRA_OUTPUT. However, this requires putting in the storage location and every answer I have seen tells me to put in Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES). However when I try to do data.getData() in onActivityResult I get null. How do I do this?
alert.setPositiveButton("Take Photo", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
profileFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "image_" +
String.valueOf(System.currentTimeMillis()) + ".jpg");
profile = Uri.fromFile(profileFile);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, profile);
startActivityForResult(intent, 1);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK) {
ImageView imageView = (ImageView) findViewById(R.id.ProfileImage);
//This returns null.
//I am guessing that the Environment.getExternalSt...() method is getting a storage
//location that does not exist.
//I don't know what the correct storage location is and I have not
//been able to find it.
Uri u = data.getData();
File finalFile = new File(getRealPathFromURI(u));
Picasso.with(this).load(finalFile).into(imageView);
}
}