-2

I have qrReader app so in ActivityResult i wrote to intent into the camera if I have response what I want that is it possible to take the picture automatically after the intent into the camera and after autofocus it ??(what should I have to add for autocapture)

        button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            IntentIntegrator intentIntegrator = new IntentIntegrator(activity);
            intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
            intentIntegrator.setPrompt("Scan");
            intentIntegrator.setCameraId(0);
            intentIntegrator.setBeepEnabled(false);
            intentIntegrator.setBarcodeImageEnabled(false);
            intentIntegrator.initiateScan();

        }
    });
}

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
    if(result!= null){
                if(result.getContents()==null){
                    Toast.makeText(getApplicationContext(),"you canceled the scanning",Toast.LENGTH_LONG).show();
                }
                else {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    textView.setText(result.getContents());
                    startActivityForResult(intent, TAKE_PICTURE);



                }



    }

    super.onActivityResult(requestCode, resultCode, data);
}
EasyE
  • 44
  • 9

1 Answers1

0

Add the following code:

Write a method

public void capturePhoto() throws Exception { 
        mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
        Thread.sleep(WAIT_GENERIC);
        mCamera.stopPreview();
        mCamera.release();
    } 

And call it in your onResult else as

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            IntentIntegrator intentIntegrator = new IntentIntegrator(activity);
            intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
            intentIntegrator.setPrompt("Scan");
            intentIntegrator.setCameraId(0);
            intentIntegrator.setBeepEnabled(false);
            intentIntegrator.setBarcodeImageEnabled(false);
            intentIntegrator.initiateScan();

        }
    });
}

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
    if(result!= null){
                if(result.getContents()==null){
                    Toast.makeText(getApplicationContext(),"you canceled the scanning",Toast.LENGTH_LONG).show();
                }
                else {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    capturePhoto();
                    textView.setText(result.getContents());
                    startActivityForResult(intent, TAKE_PICTURE);



                }



    }

To answer your question in your camera previewclass add:

ShutterCallback shutterCallback = new ShutterCallback() {
        public void onShutter() {
            //           Log.d(TAG, "onShutter'd");
        }
    };

    PictureCallback rawCallback = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            //           Log.d(TAG, "onPictureTaken - raw");
        }
    };

    PictureCallback jpegCallback = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            new SaveImageTask().execute(data);
            resetCam();
            Log.d(TAG, "onPictureTaken - jpeg");
        }
};
Akshay
  • 1,161
  • 1
  • 12
  • 33