Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 views
in Technique[技术] by (71.8m points)

Ionic capacitor Camera, File plugin_not_install

Ionic Framework               : @ionic/angular 5.5.2
   @angular-devkit/build-angular : 0.1100.7
   @angular-devkit/schematics    : 10.0.8
   @angular/cli                  : 10.0.8
   @ionic/angular-toolkit        : 2.3.3
Capacitor:

   Capacitor CLI   : 2.4.5
   @capacitor/core : 2.4.5

Utility:

   cordova-res : not installed
   native-run  : 1.3.0

I've been trying to let the user add images from the camera or gallery using this tutorial (https://enappd.com/blog/camera-and-image-picker-in-ionic-apps/148/). When I run the application on the emulator, the error message (from ToastController) said 'plugin_not_installed'.

page1.ts

import { Camera, CameraOptions } from "@ionic-native/Camera/ngx";
import { File } from "@ionic-native/file/ngx";

export class Page1 extends OnInit(){
constructor(
    private camera: Camera,
    private actionSheetController: ActionSheetController,
    private file: File
){}

  async pickImage(sourceType) {
    const options: CameraOptions = {
      quality: 100,
      sourceType: sourceType,
      destinationType: this.camera.DestinationType.FILE_URI,
      encodingType: this.camera.EncodingType.PNG,
      mediaType: this.camera.MediaType.PICTURE,
    };
    await this.camera.getPicture(options).then(
      (imageData) => {
        console.log(imageData);
        // imageData is either a base64 encoded string or a file URI
        if (imageData !== undefined)
          this.img = "data:image/jpeg;base64," + imageData;
      },
      (err) => {
        this.presentToast(err);
      }
    );
  }

  async selectImage() {
    const actionSheet = await this.actionSheetController.create({
      header: "Select Image source",
      buttons: [
        {
          text: "From Gallery",
          handler: () => {
            this.pickImage(this.camera.PictureSourceType.PHOTOLIBRARY);
          },
        },
        {
          text: "From Camera",
          handler: () => {
            this.pickImage(this.camera.PictureSourceType.CAMERA);
          },
        },
        {
          text: "Cancel",
          role: "cancel",
        },
      ],
    });
    return await actionSheet.present();
  }

page1.html

<ion-card id="pictureFrame" (click)="selectImage()">
</ion-card>
question from:https://stackoverflow.com/questions/65830328/ionic-capacitor-camera-file-plugin-not-install

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...