首页 > 解决方案 > Ionic4 相机插件-cordova 在设备上不可用?

问题描述

我正在开发一个需要能够拍照的 Ionic4 应用程序。我添加了“cordova-plugin-camera”。当我在真实设备上运行此插件的功能拍照时,我收到错误“cordova_not_avaliable”。(请注意,其他本机 cordova 插件工作得很好- 即使在同一页面/模块中)。

我遵循了“cordova-plugin-camera”的 Ionic 文档的基本安装过程。不会引发其他错误。

import { Component, OnInit } from '@angular/core';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';

@Component({
  selector: 'app-picture',
  templateUrl: './picture.page.html',
  styleUrls: ['./picture.page.scss'],
})

export class PicturePage implements OnInit {

  options: CameraOptions = {
    quality: 100,
    destinationType: this.camera.DestinationType.FILE_URI,
    encodingType: this.camera.EncodingType.JPEG,
    mediaType: this.camera.MediaType.PICTURE
  }

constructor(private camera: Camera) { } 
ngOnInit() {}

takePicture() {
    this.camera.getPicture(this.options).then((imageData) => {
      let base64Image = 'data:image/jpeg;base64,' + imageData;
      // this.presentAlert('success');
    }, (err) => {
      // this.presentAlert(err); // Displays "cordova_not_avaliable"
      // (For show on DEVICE. I know rest logic of alert is missing)
    });
  }
}

我希望科尔多瓦可用的,因为它在安卓设备上运行。不存在其他错误(另请注意,我在离子服务上得到完全相同的结果)。

编辑:“还要注意我在这种环境中还不是很有经验,所以我可能会遗漏一些明显的东西。”

编辑:“标题(删除预览)”

标签: cordova-pluginsionic4

解决方案


找到解决方案,在我的相机选项中,我错过了

sourceType: this.camera.PictureSourceType.CAMERA

这解决了问题。


推荐阅读