I want to use camera facility in android application.
I want to capture image on click of button control can any one suggest me the best example of it.
Try android dev's site: Camera access in android also read this article: Using android camera
And for more look at related section of this question.
These are a few Q&A here to get started:
Using the camera activity in Android
Use camera flashlight in Android
How do I save data from Camera to disk using MediaStore on Android?
And some tutorials out there:
http://mobile.tutsplus.com/tutorials/android/android-sdk-quick-tip-launching-the-camera/
http://2008.hfoss.org/Tutorial:Creating_a_Camera_Application
Please Check this answer :
public class ImageUploading extends Activity
{
Uri imageUri = null;
ImageButton btnSubmit ;
public void onCreate(Bundle onsavedInstantState)
{
super.onCreate(onsavedInstantState);
setContentView(R.layout.edit_profile);
btnSubmit = (ImageButton) findViewById(R.id.btnSubmit);
btnSubmit.setClickable(true);
btnSubmit.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
File imgFile = new File(Environment.getExternalStorageDirectory(),"my_photo.png");
imageUri = Uri.fromFile(imgFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent,0);
}
});
}
@Override
public void onActivityResult(int RequestCode, int ResultCode, Intent imageIntent)
{
super.onActivityResult(RequestCode, ResultCode, imageIntent);
try
{
if(RequestCode == 0)
{
if(ResultCode == Activity.RESULT_OK)
{
getContentResolver().notifyChange(imageUri, null);
ContentResolver objContentResolver = getContentResolver();
Bitmap imgBitmap = android.provider.MediaStore.Images.Media.getBitmap(objContentResolver, imageUri);
Drawable imgDrawable = new BitmapDrawable(imgBitmap);
btnSubmit.setBackgroundDrawable(imgDrawable);
}
}
}
catch(Exception e)
{}
}
}
It will capture image on button click, and set this image as background image for that button itself.
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(id);
button.setonClickListener(new View.onClickListener()
{
public void onClick(View view)
{
Intent intent = new Intent();
intent.putExtra("aspectX", 730);
intent.putExtra("aspectY", 1115);
intent.putExtra("outputX", 730);
intent.putExtra("outputY", 1115);
intent.setAction("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, PICK_FROM_CAMERA);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
{
case PICK_FROM_CAMERA : if (resultCode == RESULT_OK)
{
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
Bitmap photo = (Bitmap) data.getExtras().get("data");
((ImageView)findViewById(R.id.selectedimage)).setImageBitmap(photo);
OutputStream outstream;
try {
outstream = getContentResolver().openOutputStream(uri);
photo.compress(Bitmap.CompressFormat.JPEG,100, outstream);
outstream.close();
} catch (FileNotFoundException e) {}
catch (IOException e){}
}
break;
EDIT: its perfect and working.just try it and provide me feedback if u like it.
Hy Check these all links .. i hope its useful for you.
http://www.softwarepassion.com/android-series-taking-photos-with-andorid-built-in-camera/
http://achorniy.wordpress.com/2010/04/26/howto-launch-android-camera-using-intents/
https://github.com/mistaguy/snapit/tree/master/src/com/mistaguy/snapit
http://mobile.tutsplus.com/tutorials/android/android-sdk-quick-tip-launching-the-camera/
http://notes.hfoss.org/index.php/Tutorial:Camera_and_Gallery_Demo
http://www.anddev.org/take_picture_from_camera_emulator-t168.html
Try this one, if it doesnt work I will give you the trunk link.