Android Camerapova错误';插件未安装';,但该插件已安装| 8
我正在制作一个需要获取照片的应用程序,并将其最后发送到服务器上。 因此,应用离子5和离子8 我已经安装了这个插件,这是我的照片组件:Android Camerapova错误';插件未安装';,但该插件已安装| 8,android,angular,cordova,ionic-framework,Android,Angular,Cordova,Ionic Framework,我正在制作一个需要获取照片的应用程序,并将其最后发送到服务器上。 因此,应用离子5和离子8 我已经安装了这个插件,这是我的照片组件: constructor( private cameraPreview: CameraPreview ) { } takePhoto() { // camera options (Size and location). In the following example, the preview uses the rear c
constructor(
private cameraPreview: CameraPreview
) { }
takePhoto() {
// camera options (Size and location). In the following example, the preview uses the rear camera and display 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)
});
}
}
所以,这是我的HTML组件
...
<button mat-raised-button color="primary" (click)="takePhoto()">prendi la foto</button>
...
运行cordova插件列表
我看到:
cordova-plugin-camera-preview 0.11.2 "cordova-plugin-camera-preview"
这是我在应用程序模块上提供的:
providers: [
CameraPreview
]
但是,当我运行ionic cordova运行android时,我运行takePhoto()方法
我得到了这个错误:
我一直试图卸载、删除android平台,但什么都没有。错误不会消失
更新
我添加了检查平台,但Chrome canary打印我:
Angular is running in the development mode. Call enableProdMode() to enable the production mode.
cordova.js:1233 deviceready has not fired after 5 seconds.
cordova.js:1226 Channel not fired: onCordovaInfoReady
也许问题是这个
有什么解决办法吗
谢谢,这个问题经常发生,因为平台还没有准备好。请在您调用任何插件之前检查平台已准备就绪:
import { Component, OnInit } from '@angular/core';
import { Platform } from '@ionic/angular';
import { CameraPreview, CameraPreviewOptions } from '@ionic-native/camera-preview/ngx'; // don't add ngx if you are on 'ionic-angular' mode
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent implements OnInit {
constructor(
private platform: Platform,
private cameraPreview: CameraPreview
) {
}
ngOnInit() {
this.platform.ready().then(_ => {
this.takePhoto() // here the call of your function
})
}
takePhoto() {
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)
});
}
}
谢谢你的回复。我已经试过了,现在chrome canary将我在问题的更新部分中输入的信息打印给我。@Mr.Developer这三行是信息,不应该停止应用程序功能的工作,你可以暂时忽略它们。之后插件是否工作?很抱歉,强制后插件不工作。我还在寻找其他解决办法。谢谢
import { Component, OnInit } from '@angular/core';
import { Platform } from '@ionic/angular';
import { CameraPreview, CameraPreviewOptions } from '@ionic-native/camera-preview/ngx'; // don't add ngx if you are on 'ionic-angular' mode
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent implements OnInit {
constructor(
private platform: Platform,
private cameraPreview: CameraPreview
) {
}
ngOnInit() {
this.platform.ready().then(_ => {
this.takePhoto() // here the call of your function
})
}
takePhoto() {
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)
});
}
}