4

I did code for capturing the image from camera and it works fine, After capturing the image it is asking for click ok in camera but i want to get image without clicking on ok button. my code for is as below and i don't have idea to get image without clicking ok button so please help me.

button_camera.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
            startActivityForResult(intent, 0);
        }
    });



protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case 0:
        if (resultCode == RESULT_OK) {


            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();

            Log.e("PATH", filePath+"");
            Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);

        }
    }

};
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
Rajesh Panchal
  • 1,140
  • 3
  • 20
  • 39

2 Answers2

0

On button click listerner write the following code

 cameraBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
            startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
        }
    });
0

To achieve this, we should notify the camera intent to enable quick capture mode, while calling it. Below the code:

private static final int REQUEST_IMAGE_CAPTURE = 1;

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra("android.intent.extra.quickCapture", true); // enables single click image capture
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
    startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}

Note: I learned from stackoverflow and few other sites people say some devices do not support this mode. And I am not sure what devices those are. To this date, I've tested on devices from different brands with API levels 21 to 28, which all has worked for me so far.

vss
  • 1,093
  • 1
  • 20
  • 33