I\'ve been searching the simple example to take a photo, and save it using URI and retrieve the photo for image processing , I\'ve tried lot of example code, but none of them w
define a variable like this
protected static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0;
Use the code for calling camera from android.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"fname_" +
String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
and in the class calling this override the onActivityResult function and enter the code below.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
//use imageUri here to access the image
Bundle extras = data.getExtras();
Log.e("URI",imageUri.toString());
Bitmap bmp = (Bitmap) extras.get("data");
// here you will get the image as bitmap
}
else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
}
}
}