简体   繁体   中英

'Error capturing image' with Phonegap on Android

I need to capture an image with my Phonegap app. On iOS everything works fine but on Android (via Phonegap Build) it throws an error with "Error capturing image".

I added the following lines to my config.xml but that doesn't change anything:

<feature name="Camera">
    <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/camera" />
<feature name="http://api.phonegap.com/1.0/file" />
<feature name="http://api.phonegap.com/1.0/media" />
<feature name="http://api.phonegap.com/1.0/network" />

My API call looks like that:

    $(document).on('click', '#cameraPreview', function() {
        pictureSource = navigator.camera.PictureSourceType;
        destinationType = navigator.camera.DestinationType;

        navigator.camera.getPicture(onGetPictureSuccess, onGetPictureFail, {
          quality: 40,
          sourceType: Camera.PictureSourceType.CAMERA,
          destinationType: Camera.DestinationType.FILE_URI,
          allowEdit: true,
            encodingType: Camera.EncodingType.JPG,
          targetWidth: 1000,
          targetHeight: 1000,
          saveToPhotoAlbum: true,
          correctOrientation: 1
        });
    });

I use Phonegap 3.7 with Phonegap Build.

Ok, now I know the answer. The problem is the saveToPhotoAlbum: true option. Android doesn't recognize this. When I delete this option everything works fine.

Check your cordova-camera-plugin version. If it's under 4.0.1, this will be fixed by updating latest version. Otherwise, I have no idea.

This is a known issue and already be fixed. You can see more detail below link. https://issues.apache.org/jira/browse/CB-13781

Updating cordova-camera-plugin to version 4.0.2 or higher should fix the problem with saving to the photo album.

Since Android 8, saving a photo in the photo album requires the WRITE_EXTERNAL_STORAGE permission, but this is not requested by versions of cordova-camera-plugin older than 4.0.2.

For more information:

对我来说,我必须添加这个权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

The permission requirements have changed in different versions of Android and different SDK versions. Make sure you are using the appropriate plugin version for your target OS version.

For anyone seeing this same issue with cordova-camera-plugin <=4.2.0 on Android 10, you can set <preference name="android-targetSdkVersion" value="28" />

See this ticket for more info: https://github.com/apache/cordova-plugin-camera/issues/611

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM