Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to listen to the picture captured by camera in android

In my application I just want to listen to the picture captured by user in camera and increase the photo count.I tried listen to

<action android:name="android.provider.MediaStore.ACTION_IMAGE_CAPTURE" />
<action android:name="android.media.action.IMAGE_CAPTURE" />
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
<action android:name="android.intent.action.CAMERA_BUTTON" />

above intents .But these intents are not working for galaxy. Is there any other method to listen to the captured images.

like image 375
thej Avatar asked Nov 19 '25 04:11

thej


2 Answers

Look here

The clue is to launch the activity with the intent pased as parameter:

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

And capture the result of the activity:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case TAKE_PICTURE:
        if (resultCode == Activity.RESULT_OK) {
            // Do something
        }
    }
}
like image 144
gutiory Avatar answered Nov 20 '25 18:11

gutiory


I think you should use picture callback

                    Camera.PictureCallback picture_callback = new Camera.PictureCallback() {

                        @Override
                        public void onPictureTaken(byte[] data, Camera camera) {
                            // WRITE YOUR CODE WHEN PICTURE TAKEN.
                            // "data" IS YOUR TAKEN PICTURE FRAME. 
                        }
                    };

set picture_callback to your camera and every time when you take picture control will come in above function.

you can set your picture callback to

if you have raw frame
        mCamera.takePicture(null, picture_callback, null);

if you have jpeg frame
        mCamera.takePicture(null, null, picture_callback);

hope it will help you..

if you want to use default camera then you can use it.

Camera mCamera = Camera.open();

like image 43
Bharat Sharma Avatar answered Nov 20 '25 16:11

Bharat Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!