cordova-plugins - Ionic cordova-plugin-qrscanner没有相机预览

标签 cordova-plugins qr-code ionic3 ionic-native

我运行了一个简单的演示以使用cordova-plugin-qrscanner,它可以扫描qrcode,但是没有相机预览。

qrscannerDemo on Github

相关代码重击:

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上运行ionic项目,然后单击按钮,但没有任何 react ,也没有显示摄像头预览。

我再次测试该项目,发现它可以扫描qrcode并获得结果测试,但没有相机预览。

我搜索了问题,有人说应该将主体和所有元素设置为透明。我尝试但不起作用。

Android. Nothing appears on screen. #35

有人帮忙吗?

最佳答案

在顶级index.html中:

<ion-app style="background: none transparent;"></ion-app>

在相机显示页面的html文件中:
<ion-content style="background: none transparent;">

关于cordova-plugins - Ionic cordova-plugin-qrscanner没有相机预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45316875/

相关文章:

cordova - Cordova 平台 www 可用吗?

android - 如何创建执行命令的二维码?

ios - 如何在 swift 中实现带定时器的 QRScanner?

angular - 如何读取 firebase 推送通知内容并触发 ionic2 中的方法?

angular - 共享相同的 Web (Angular 4) 和移动 (Ionic 3) 代码库

android - Cordova/Phonegap 获取设备的电话号码 (Android & iOS)

angularjs - 如何在 ionic 应用程序中检测多指触摸

ionic-framework - 如何使用 Cordova 在应用中安装 Facebook Pixel 并跟踪转化?

android - 生成二维码以在 iOS 应用程序中打开 Facebook 页面

ionic-framework - 在 Ionic 3 中显示由 Native Camera 拍摄的 FILE_URI 图像