I am using the following code to capture the image from the camera and store it in the public directory pictures. How do I use the same image and set it as in ImageView?
public void take_photo(){
if (ActivityCompat.checkSelfPermission(Contact_info.this,Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.CAMERA},40);
}
return;
}
Intent cameraIntent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (ActivityCompat.checkSelfPermission(Contact_info.this,Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},50);
}
return;
}
File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String pictureName = "Image1.jpg";
File imageFile = new File(pictureDirectory, pictureName);
Uri pictureUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
pictureUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", imageFile);
} else{
pictureUri = Uri.fromFile(imageFile);
}
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
My on activity result code:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
if(requestCode==CAMERA_REQUEST){
//Commented since upon using this and trying to save the image in the file, the app crashes giving a null pointer exception
//Bitmap cameraImage =(Bitmap) data.getExtras().get("data");
//contact_image.setImageBitmap(cameraImage);
}
}
}
I do not want to know how to set the image in an ImageView, I want to know how i can use the image that is taken by the camera and stored in the phone directory as the image in the ImageView