matan12128 :
//global variable
static final int CAMERA_REQUEST = 1;
ImageView imageview;
Bitmap bitmap;
//on create:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//take reference
imageview = findViewById(R.id.image_view);
//the onclick listener and the intent:
Button take_photo_btn = findViewById(R.id.photo_btn);
take_photo_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST);
}
});
//this is the activity for result:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && requestCode == RESULT_OK) {
Bundle extras = data.getExtras();
bitmap = (Bitmap) extras.get("image");
imageview.setImageBitmap(bitmap);
}
}
}
after i take a photo i didnt see it in the image view whats is the problem??
matan12128 :
Ok i found the problem
if (requestCode == CAMERA_REQUEST && requestCode == RESULT_OK
i nees to do this:
if(requestCode == CAMERA_REQUEST && resultCode == RESULT_OK)