When I invoke the startCamera the promise returns an error with the message “plugin_not_installed”.
I installed it using: $ ionic cordova:plugin add cordova-plugin-camera-preview
But i noticed that the docs for native only have “Camera” and not “CameraPreview”.
Any thoughts? Thank you very much.
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController } from 'ionic-angular';
import { UserProvider } from '../../providers/user-provider';
import { Diagnostic } from '@ionic-native/diagnostic';
import { CameraPreview, CameraPreviewOptions } from '@ionic-native/camera-preview';
@IonicPage()
@Component({
selector: 'picture-preview',
templateUrl: 'picture-preview.html',
providers: [CameraPreview, Diagnostic]
})
export class PicturePreviewPage {
constructor(public navCtrl: NavController,
public navParams: NavParams,
private toastCtrl: ToastController,
private userService: UserProvider,
private diagnostic: Diagnostic,
private cameraPreview: CameraPreview) {
this.checkPermissions();
}
checkPermissions() {
this.diagnostic.isCameraAuthorized().then((authorized) => {
if (authorized) {
console.log('starting Camera');
this.initializePreview();
}
else {
this.diagnostic.requestCameraAuthorization().then((status) => {
if (status == this.diagnostic.permissionStatus.GRANTED)
this.initializePreview();
else {
// Permissions not granted
// Therefore, create and present toast
this.toastCtrl.create(
{
message: "Cannot access camera",
position: "bottom",
duration: 5000
}
).present();
}
});
}
});
}
initializePreview() {
// Make the width and height of the preview equal
// to the width and height of the app's window
var cameraPreviewOpts: CameraPreviewOptions = {
x: 0,
y: 0,
width: window.screen.width,
height: window.screen.height,
camera: 'rear',
tapPhoto: true,
previewDrag: true,
toBack: true,
alpha: 1
};
var that = this;
this.cameraPreview.startCamera(cameraPreviewOpts).then(function () {
that.toastCtrl.create(
{
message: "Starting Camera: OK",
position: "bottom",
duration: 5000
}
).present();
}, function (error) {
console.log('error', error);
});
// More code goes here
}
}