Wednesday 13 February 2013

Code To Start Camera with Build-in Intent

This code will show you how to start camera using intent and save the image to the file name.

Step1)Private constants & variable uses in the class:

 private static int TAKE_PIC = 1;
 private Uri FileUri;
 
Step2)Once the code is run, the camera pops up, just take your photo, and click on “Done” button on the screen. That would close the camera app and returns to your own App.
          
  private void ClickPhoto() {
  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  File file = new File(Environment.getExternalStorageDirectory(), "img1.jpg");
 
  FileUri = Uri.fromFile(file);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, FileUri);
  startActivityForResult(intent, TAKE_PICTURE);
 
}

Step3)You need to override the onActivityResult to handle when the camera returns to your app:
                         
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data){
 
  if (requestCode == TAKE_PIC){
   //do whatever you want
  }
 
 }

 Thank U....

0 comments:

Post a Comment

 

Copyright © Unique Android Tutorial.. Design by Free CSS Templates | Blogger Theme by BTDesigner | Powered by Blogger