Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onActivityResult is not called for MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA

Tags:

android

I am trying to call the camera with intent MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA. However, using StartActivityForResult does not call onActivityResult.

How can I solve this?

like image 320
Majid Avatar asked Jul 20 '11 07:07

Majid


1 Answers

// get image count in media store befor start camera  Start camera with chooser 
public void startCameraActivity() {
        Cursor cursor = loadCursor();

        image_count_before = cursor.getCount();

        cursor.close();

        Intent cameraIntent = new Intent(
                MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
        cameraIntent = Intent.createChooser(cameraIntent, "Select Camera");
        List<ResolveInfo> activities = getPackageManager()
                .queryIntentActivities(cameraIntent, 0);
        if (activities.size() > 0)
            startActivityForResult(cameraIntent, CAPTURE_IMAGES_FROM_CAMERA);
        else
            Toast.makeText(this, "No Camera application", Toast.LENGTH_SHORT)
                    .show();
    }

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

        switch (requestCode) {

        case CAPTURE_IMAGES_FROM_CAMERA:

            exitingCamera();
            break;

        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    public Cursor loadCursor() {

        final String[] columns = { MediaStore.Images.Media.DATA,
                MediaStore.Images.Media._ID };

        final String orderBy = MediaStore.Images.Media.DATE_ADDED;

        return getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
                null, orderBy);
    }

    public String[] getImagePaths(Cursor cursor, int startPosition) {

        int size = cursor.getCount() - startPosition;

        if (size <= 0)
            return null;

        String[] paths = new String[size];

        int dataColumnIndex = cursor
                .getColumnIndex(MediaStore.Images.Media.DATA);

        for (int i = startPosition; i < cursor.getCount(); i++) {

            cursor.moveToPosition(i);

            paths[i - startPosition] = cursor.getString(dataColumnIndex);
        }

        return paths;
    }

    private void exitingCamera() {

        Cursor cursor = loadCursor();
        String[] paths = getImagePaths(cursor, image_count_before);
        cursor.close();
        new ProcessImage(paths).execute();

    }
like image 131
bala Avatar answered Oct 10 '22 17:10

bala