0
我在設置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>