Get image from camera without clicking ok after clicking on camera in android

I made a code to capture an image from a camera and it works fine, After capturing an image, it asks to click ok in the camera, but I want to get the image without clicking ok. my code is for below and I have no idea to get the image without clicking ok, 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);

        }
    }

};

      

+3


source to share


1 answer


On the button press 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


source







All Articles