0

I new in the android developing. I want to develop simple application that will be able to take a picture using the cell phone camara and show it on the screen of the cell phone.

Is there some simple example that i can use ? or some code that can help me learn how to do it ?

Thanks for any help

Yanshof
  • 9,659
  • 21
  • 95
  • 195
  • 3
    possible duplicate of [Capture Image from Camera and Display in Activity](http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity) – Paresh Mayani Oct 31 '11 at 07:56

2 Answers2

2

to start camera you use

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                startActivityForResult(cameraIntent, 0); 

and here you have the handeling

   protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == 0) {  
            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
            imageView.setImageBitmap(photo);
        }  
    } 
Lukap
  • 31,523
  • 64
  • 157
  • 244
0

Try this.. Use the below code in onCreate

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 URI mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
        "pic_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);

    try {
        intent.putExtra("return-data", true);
        startActivityForResult(intent, CAMERA_RESULT);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }

Then OnActivityResult

   @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == RESULT_OK) {
           //Here you will get path of image stored in sdcard then pass it to next activity as your desires..
                           mImagePath = extras.getString("image-path");
                mSaveUri = getImageUri(mImagePath);
              Bitmap   mBitmap = getBitmap(mImagePath);
                       // here mBitmap is assigned to any imageview and you can use it in for display
         }
         }

   private Uri getImageUri(String path) {
    return Uri.fromFile(new File(path));
       }

     private Bitmap getBitmap(String path) {
     Uri uri = getImageUri(path);
     InputStream in = null;
   try {
       in = mContentResolver.openInputStream(uri);
    return BitmapFactory.decodeStream(in).copy(Config.ARGB_8888, true);
} catch (FileNotFoundException e) {
    //Log.e(TAG, "file " + path + " not found");
}
return null;
       }

            }
deepa
  • 2,496
  • 1
  • 26
  • 43