打开本地相机后Ionic App崩溃-错误20 [英] Ionic App crash after Open native camera - Error 20

查看:199
本文介绍了打开本地相机后Ionic App崩溃-错误20的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ionic 4 上的cordova 相机插件来捕获一些图像.

I'm using the cordova camera plugin on ionic 4 to capture some image.

takePicture() {
   console.log(' camera takePicture ');
   const options: CameraOptions = {
      quality: 100,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    }

this.camera.getPicture(options).then((imageData) => {
  this.selectedImage = 'data:image/jpeg;base64,' + imageData;
 }, (err) => {
   // Handle error
   console.log('Camera issue:' + err);
 });

}

应用程序确实崩溃了,但是此代码始终返回相机问题:20 ,并且相机界面从不出现在手机屏幕上.

The application doesent crash but this code always return Camera issue: 20 and the camera interface never appears on the phone screen.

我试图像这样修改config.xml文件,因为我认为这是android权限存在问题,但stil无法正常工作:

I tried to modify the config.xml file like this because i thought it was problem with android permissions but stil not working:

<config-file mode="merge" parent="/*" target="AndroidManifest.xml">
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-feature android:name="android.hardware.camera" />
        <uses-feature android:name="android.hardware.camera.autofocus" />
<!--            <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
<!--            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
</config-file>

我不得不评论存储,因为它使同一行中的应用崩溃.

I had to comment the storage because it crashed the appllication in the same line.

此外,我尝试卸载并重新安装插件

Also, I tried to uninstall and reinstal the plugin

ionic cordova plugin remove cordova-plugin-camera
npm uninstall @ionic-native/camera

ionic cordova plugin add cordova-plugin-camera
npm install @ionic-native/camera

我不知道如何解决此问题,请给我一些帮助. 谢谢!

I have no idea how to solve this, I need some help please. Thanks!

推荐答案

您应该使用cordova-plugin-camera-preview插件来操纵离子相机.请注意,此插件仅与Android和iOS兼容.

You should use the cordova-plugin-camera-preview plugin to manipulate camera in ionic. Note that this plugin is only compatible with Android and iOS.

通过以下方式安装:

ionic cordova plugin add cordova-plugin-camera-preview
npm install @ionic-native/camera-preview

用法:

// camera options (Size and location). In this example, the preview uses the rear camera and displays the preview in the back of the webview 
const cameraPreviewOpts: CameraPreviewOptions = { 
    x: 0, 
    y: 0, 
    width: window.screen.width, 
    height: window.screen.height, 
    camera: 'rear', 
    tapPhoto: true, 
    previewDrag: true, 
    toBack: true, 
    alpha: 1 
} 

// start camera 
this.cameraPreview.startCamera(cameraPreviewOpts).then( 
    (res) => { console.log(res) }, 
    (err) => { console.log(err) }
);

这篇关于打开本地相机后Ionic App崩溃-错误20的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆