Skip to content Skip to sidebar Skip to footer

Using Intent To Use Camera In Android

I am using the following code to use camera by using intent. In the parameter of intent I am passing android.provider.MediaStore.ACTION_IMAGE_CAPTURE. It is able to open the camera

Solution 1:

Try request code 1337.

startActivityForResult(cameraIntent , 1337);

Solution 2:

This how I use it

IntentcameraIntent=newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 1337);

Solution 3:

do you have the following declarations in your manifest ?:

<uses-featureandroid:name="android.hardware.camera" /><uses-permissionandroid:name="android.permission.CAMERA" /><uses-featureandroid:name="android.hardware.camera.autofocus" />

?? I used to do the same... here is my call to intent:

Filefile=newFile( _path );
    UrioutputFileUri= Uri.fromFile( file );

    Intentintent=newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
    intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
    intent.putExtra( MediaStore.EXTRA_VIDEO_QUALITY,1);

the only slight difference between my and your code - I have file path in URI sending among call

Solution 4:

I have used the following code and it worked!

@OverridepublicvoidonClick(View v) {
    // TODO Auto-generated method stubIntentintent=newIntent(
            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
    }
}

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode,
        final Intent data) {
    // TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        im.setImageDrawable(null);
        im.destroyDrawingCache();
        Bundleextras= data.getExtras();
        Bitmapimagebitmap= (Bitmap) extras.get("data");
        im.setImageBitmap(imagebitmap);
    }

}

Post a Comment for "Using Intent To Use Camera In Android"