@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.