Search code examples
androidonactivityresult

Android onclick radio button camera intent not working


i have a radio button. when i click on radio button camera intent is opened after taking a image using camera. image is not updating to image view.

i have used all permissions in my manifest file.

RB_PhotoStatus
            .setOnCheckedChangeListener(new android.widget.RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group,
                        int checkedId) {
                    switch (checkedId) {
                    case R.id.yes:
                        //photoCollected = "Yes";
                         // create intent with ACTION_IMAGE_CAPTURE action 
                        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        startActivityForResult(intent, 0);

                        break;

                    case R.id.no:
                        photoCollected = "No";
                        break;
                    }

                }
            });




@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {



          super.onActivityResult(requestCode, resultCode, data);

            Bitmap bp = (Bitmap) data.getExtras().get("data");
            imageView1.setImageBitmap(bp);


    }

Solution

  • Taking Photos Simply!

    This answer explains how to capture photos using an existing camera application.

    <manifest ... >
        <uses-feature android:name="android.hardware.camera"
                      android:required="true" />
        ...
    </manifest>
    

    Request for camera application.

    static final int REQUEST_IMAGE_CAPTURE = 1;
    
    private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
    

    Camera return intent with data on Activity override function onActivityResult as bellow:-

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            mImageView.setImageBitmap(imageBitmap);
        }
    }
    

    For more info follows this link given bellow:

    http://developer.android.com/training/camera/photobasics.html