1.

Suppose you need to create an App name as ” MyGalryApp”. Here you have an activity name as “Home Activity” where you have one button to take a Picture. If you click on that button it will open Camera to click Picture. Once you click the Picture it should display in Imageview. What code you will write for this problem?

Answer»

We will write below to do display an image in imageview after clicked by Camera 

  • First we need o add Camera Permission in Manifest file.
<uses-permission android:name="android.permission.CAMERA" />
  • When user click on the BUTTON for take the image, we will call Implicit Intent with Action Image Capture.
intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 1);
  • Once Image has been clicked we will override onActivityResult METHOD for displaying image in imageview.
H  if (requestCode == 1 && resultCode == RESULT_OK) {  BITMAP bitmap = (Bitmap) data.getExtras().GET("data"); imageView.setImageBitmap(bitmap);


Discussion

No Comment Found

Related InterviewSolutions