Intent does not set the camera parameters

后端 未结 2 550
生来不讨喜
生来不讨喜 2020-11-27 23:18

I am opening camera app as external intent from my applications. I am using following code to invoke the camera and following are my conditions:

  1. It should open
相关标签:
2条回答
  • 2020-11-27 23:34
    intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
    

    this is an intent to start capture with the front camera instead of the default rear camera.

    this works as it is used in this popular cordova plugin in this link at line 145 : https://github.com/EddyVerbruggen/VideoCapturePlus-PhoneGap-Plugin/blob/master/src/android/nl/xservices/plugins/videocaptureplus/VideoCapturePlus.java

    hope this helps anyone facing the same problem.

    also do you know if you can set an intent to disable the camera controls(filters,switch between cameras..etc) , so that they doesn't show ?

    0 讨论(0)
  • 2020-11-27 23:50

    Unfortunately, when using the camera with Intent, the only extra parameter you can set is

    MediaStore.EXTRA_OUTPUT
    

    Eg

    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
    

    Which allows you to map where the Camera application will store the image.

    Camera Facing intent extra can sometimes work:

    action.putExtra("android.intent.extras.CAMERA_FACING", 1);
    

    Looking in the android source files, there are some "test" methods that are in the Util class file but not officially documented:

    (Util)

    private static final String EXTRAS_CAMERA_FACING =
            "android.intent.extras.CAMERA_FACING";
    
    // This is for test only. Allow the camera to launch the specific camera.
    public static int getCameraFacingIntentExtras(Activity currentActivity) {
        int cameraId = -1;
    
        int intentCameraId =
                currentActivity.getIntent().getIntExtra(Util.EXTRAS_CAMERA_FACING, -1);
    
        if (isFrontCameraIntent(intentCameraId)) {
            // Check if the front camera exist
            int frontCameraId = CameraHolder.instance().getFrontCameraId();
            if (frontCameraId != -1) {
                cameraId = frontCameraId;
            }
        } else if (isBackCameraIntent(intentCameraId)) {
            // Check if the back camera exist
            int backCameraId = CameraHolder.instance().getBackCameraId();
            if (backCameraId != -1) {
                cameraId = backCameraId;
            }
        }
        return cameraId;
    }
    

    And in the photomodule, the following method is used:

    (PhotoModule)

    private int getPreferredCameraId(ComboPreferences preferences) {
        int intentCameraId = Util.getCameraFacingIntentExtras(mActivity);
        if (intentCameraId != -1) {
            // Testing purpose. Launch a specific camera through the intent
            // extras.
            return intentCameraId;
        } else {
            return CameraSettings.readPreferredCameraId(preferences);
        }
    }
    

    And when the camera app initialises the photo mode, it calls this method to check which camera to use:

    mCameraId = getPreferredCameraId(mPreferences);
    
    0 讨论(0)
提交回复
热议问题