Reputation: 509
I am working on android application. I have an Activity in which there is two button first one for selecting image from gallary. i have applied function on it. i have one more button capture image . i want to work on it .but don't know how to start camera .I want that when i click button capture image it should start camera for capture image.and there should be option to cancel if don't want to take picture. after pressing cancel camera should cancel. if i captures image it should it should show in Image View and automatically store in SD card .how should i proceed.
Upvotes: 1
Views: 1488
Reputation: 133560
http://developer.android.com/guide/topics/media/camera.html. Everything you need to know about starting a camera. Go through the link.
private static final int TAKE_PHOTO_CODE = 1;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(this)) );
startActivityForResult(intent, TAKE_PHOTO_CODE);
get uri
private File getTempFile(Context context){
return new File(path, "/tourpath/yourfilename.jpg");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch(requestCode){
case TAKE_PHOTO_CODE:
try {
Bitmap captureBmp = Media.getBitmap(getContentResolver(), Uri.fromFile(file));
iv.setImageBitmap(captureBmp);//show in imageview
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}
Upvotes: 1