科尔多瓦条码扫描器不能在Android 6.0.1上工作
我在设置Ionic 3.19上的BarcodeScanner时遇到了一些问题。这是我的代码到目前为止。测试设备是运行Android 6.0.1的LG Nexus 5。我正在运行科尔多瓦7.0.1。科尔多瓦条码扫描器不能在Android 6.0.1上工作
以下实现在浏览器中按预期工作,但在手机上,它只是告诉我“授予权限”,然后条形码扫描器的摄像头不出现。
存款money.ts
import { Component } from '@angular/core'; import { ModalController } from 'ionic-angular';
import { BarcodeScanner, BarcodeScannerOptions } from '@ionic-native/barcode-scanner';
import { AndroidPermissions } from '@ionic-native/android-permissions';
import { ScanQRCodeModal } from '../scan-qr-code/scan-qr-code';
@Component({
selector: 'page-deposit',
templateUrl: 'deposit-money.html'
})
export class DepositMoneyPage {
options: BarcodeScannerOptions;
scanData: {};
constructor(private barcodeScanner: BarcodeScanner,
private androidPermissions: AndroidPermissions,
private modalCtrl: ModalController) {
}
checkCameraPermissions() {
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.CAMERA).then(
success => { alert('Permission granted'); this.scanQRCode()},
err => { alert('asking for permisison'); this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA) }
);
}
scanQRCode() {
this.options = {
prompt : "Scan your voucher code"
}
this.barcodeScanner.scan(this.options).then((barcodeData) => {
console.log(barcodeData);
this.scanData = barcodeData;
}, (err) => {
console.log("Error occured: " + err);
});
}
showScanQRCodeModal() {
let scanQRCodeModal = this.modalCtrl.create(ScanQRCodeModal);
scanQRCodeModal.present();
}
}
存款money.html
<ion-header> <ion-navbar>
<ion-title>
Deposit Money
</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<button ion-item (click)="checkCameraPermissions()">Scan QR Code</button>
</ion-list>
<div *ngIf="scanData">
<p>Scanned Text: {{scanData.text}}</p>
<p>Scanned Format: {{scanData.format}}</p>
</div>
</ion-content>
回答:
尝试使用这个插件
<plugin spec="https://github.com/Telerik-Verified-Plugins/BarcodeScanner.git" source="git" > <param name="CAMERA_USAGE_DESCRIPTION" value="To scan barcodes." />
</plugin>
以上是 科尔多瓦条码扫描器不能在Android 6.0.1上工作 的全部内容, 来源链接: utcz.com/qa/258236.html