简体   繁体   English

在 Android 上使用 Phonegap “捕获图像时出错”

[英]'Error capturing image' with Phonegap on Android

I need to capture an image with my Phonegap app.我需要使用我的 Phonegap 应用程序捕获图像。 On iOS everything works fine but on Android (via Phonegap Build) it throws an error with "Error capturing image".在 iOS 上一切正常,但在 Android 上(通过 Phonegap Build)它会抛出“错误捕获图像”的错误。

I added the following lines to my config.xml but that doesn't change anything:我在 config.xml 中添加了以下几行,但这不会改变任何内容:

<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:我的 API 调用如下所示:

    $(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.我将 Phonegap 3.7 与 Phonegap Build 一起使用。

Ok, now I know the answer.好的,现在我知道答案了。 The problem is the saveToPhotoAlbum: true option.问题是saveToPhotoAlbum: true选项。 Android doesn't recognize this. Android 不承认这一点。 When I delete this option everything works fine.当我删除此选项时,一切正常。

Check your cordova-camera-plugin version.检查您的cordova-camera-plugin 版本。 If it's under 4.0.1, this will be fixed by updating latest version.如果它低于 4.0.1,这将通过更新最新版本来修复。 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 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.cordova-camera-plugin更新到 4.0.2 或更高版本应该可以解决保存到相册的问题。

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.从 Android 8 开始,在相册中保存照片需要WRITE_EXTERNAL_STORAGE权限,但这不是 4.0.2 之前的cordova-camera-plugin版本所要求的。

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.权限要求在不同版本的 Android 和不同的 SDK 版本中发生了变化。 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" />对于在 Android 10 上使用 cordova-camera-plugin <=4.2.0 看到相同问题的任何人,您可以设置<preference name="android-targetSdkVersion" value="28" />

See this ticket for more info: https://github.com/apache/cordova-plugin-camera/issues/611有关更多信息,请参阅此票: https : //github.com/apache/cordova-plugin-camera/issues/611

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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