我運行一個簡單的演示來使用cordova-plugin-qrscanner,它可以掃描qrcode但沒有相機預覽。Ionic cordova-plugin-qrscanner沒有相機預覽
相關代碼的打擊:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AndroidPermissions } from '@ionic-native/android-permissions';
import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController,
public androidPermissions: AndroidPermissions,
public qrScanner: QRScanner) {
}
qrscanner() {
// Optionally request the permission early
this.qrScanner.prepare()
.then((status: QRScannerStatus) => {
if (status.authorized) {
// camera permission was granted
alert('authorized');
// start scanning
let scanSub = this.qrScanner.scan().subscribe((text: string) => {
console.log('Scanned something', text);
alert(text);
this.qrScanner.hide(); // hide camera preview
scanSub.unsubscribe(); // stop scanning
});
this.qrScanner.resumePreview();
// show camera preview
this.qrScanner.show();
// wait for user to scan something, then the observable callback will be called
} else if (status.denied) {
alert('denied');
// camera permission was permanently denied
// you must use QRScanner.openSettings() method to guide the user to the settings page
// then they can grant the permission from there
} else {
// permission was denied, but not permanently. You can ask for permission again at a later time.
alert('else');
}
})
.catch((e: any) => {
alert('Error is' + e);
});
}
}
<ion-header>
<ion-navbar transparent>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding style="background: none transparent;">
<button ion-button (click)="qrscanner()">qrscanner</button>
</ion-content>
我跑在Android離子項目,然後單擊按鈕卻沒有任何反應,沒有攝像頭預覽顯示。
我再次測試項目,發現它可以掃描qrcode並得到結果測試,但沒有相機預覽。
我搜索的問題,有人說應該設置身體和任何元素透明。我嘗試但不起作用。
Android. Nothing appears on screen. #35
誰能幫助?
你得到錯誤? –
@suraj沒有錯誤,它可以很好地掃描qrcode,但沒有相機預覽 – Story5
[顯示](http://ionicframework.com/docs/native/qr-scanner/#show)返回一個承諾..嘗試'this.qrScanner .show()。then(data => console.log(data),err => console.log(err));' –