Cordova Javascript QR扫描仪插件在Android上不工作(Cordova插件QR扫描仪)

Cordova Javascript QR扫描仪插件在Android上不工作(Cordova插件QR扫描仪),android,cordova,plugins,qr-code,bitpay,Android,Cordova,Plugins,Qr Code,Bitpay,我遵循文档 下面的函数“qrPrep()”下的代码将运行。但是,“qrScan01”功能不起作用。这就是显示摄像头扫描代码的功能 从HTML中将其称为 <button onclick="qrPrep();">QR Prepare</button> <button onclick="qrScan01();">QR Scan</button> <button onclick="qrShow();">QR Show</button>

我遵循文档

下面的函数“qrPrep()”下的代码将运行。但是,“qrScan01”功能不起作用。这就是显示摄像头扫描代码的功能

从HTML中将其称为

<button onclick="qrPrep();">QR Prepare</button>
<button onclick="qrScan01();">QR Scan</button>
<button onclick="qrShow();">QR Show</button>
这是LOGCAT输出。看起来摄像头正在启动,但应用程序屏幕崩溃并导航回/index.html:

D/CameraPreview: resume()
D/CameraInstance: Opening camera
D/CameraInstance: Configuring camera
I/CameraManager: Camera Display Orientation: 90
I/CameraManager: Initial camera parameters: preview-size=1920x1080;video-size=1920x1080;preferred-preview-size-for-video=1920x1080;
I/CameraConfiguration: Requesting focus mode value from among: [auto]
I/CameraConfiguration: Supported focus mode values: [infinity, auto, macro, continuous-video, continuous-picture]
I/CameraConfiguration: Can set focus mode to: auto
I/CameraConfiguration: Focus mode already set to auto
I/CameraConfiguration: Requesting flash mode value from among: [off]
I/CameraConfiguration: Supported flash mode values: [off, auto, on, torch, red-eye]
I/CameraConfiguration: Can set flash mode to: off
I/CameraConfiguration: Flash mode already set to off
I/PreviewScalingStrategy: Viewfinder size: 2621x1440
I/PreviewScalingStrategy: Preview in order of preference: [1920x1080, 1920x960, 1920x1440, 1280x720, 1600x1200, 1280x768, 1280x960,
I/CameraManager: Final camera parameters: video-size=1920x1080;preferred-preview-size-for-video=1920x1080;preview-size-values=1920x
I/CenterCropStrategy: Preview: 1080x1920; Scaled: 1474x2621; Want: 1440x2621
I/CameraPreview: Starting preview
D/CameraInstance: Starting preview
D/JsMessageQueue: Set native->JS mode to null
D/CordovaWebViewImpl: onPageDidNavigate(file:///android_asset/www/index.html?)

在我的公司里,我们使用。它可以处理多种扫描码,包括二维码,就我们的目的而言,它似乎比官方的cordova插件更容易处理

您可以通过以下方式使用它(所有代码示例均改编自文档):

package.json

{
  "name": "your-app",
  "dependencies": {
    "@ionic-native/barcode-scanner": "^5.19.1",
    "phonegap-plugin-barcodescanner": "^8.1.0",
    [...]
  },
  "cordova": {
    "plugins": {
      "phonegap-plugin-barcodescanner": {}
    }
  }
}
应用程序模块.ts

import {BarcodeScanner} from '@ionic-native/barcode-scanner/ngx';

@NgModule({
    declarations: [AppComponent],
    entryComponents: [...],
    imports: [...],
    providers: [
        BarcodeScanner,
        QrService,  // an example service to handle QR codes; can also be omitted
        [...]
    ],
    bootstrap: [AppComponent]
})
export class AppModule {}
qr.service.ts(示例服务)

从'@angular/core'导入{Injectable};
从'rxjs'导入{from,Observable};
从“rxjs/operators”导入{map};
从“@ionic native/barcode scanner/ngx”导入{BarcodeScanner,BarcodeScanResult}”;
@注射的({
providedIn:'根'
})
出口类服务{
构造函数(专用条码扫描程序:条码扫描程序){}
getQrCode$():可观察{
从(this.barcodeScanner.scan())返回
.烟斗(
地图((数据:条形码扫描结果)=>{
const barCodeData=JSON.parse(data.text);
返回条码数据;
})
);
}
}

嗨,我一点也不懂。我根本不用PhoneGap。我只是使用Cordova在Android上构建并运行我的HTML/CSS/Javascript代码。如果没有PhoneGap,这个插件会工作吗?另外,我不使用离子,但我在你的代码中看到了一些离子相关的东西-需要吗?你可以在没有PhoneGap的情况下使用这个插件,因为Cordova实际上是PhoneGap的衍生物。对不起,我没有意识到你没有使用爱奥尼亚,所以不幸的是,如果没有爱奥尼亚条形码扫描仪服务,我无法说出插件是如何工作的。。。
import {BarcodeScanner} from '@ionic-native/barcode-scanner/ngx';

@NgModule({
    declarations: [AppComponent],
    entryComponents: [...],
    imports: [...],
    providers: [
        BarcodeScanner,
        QrService,  // an example service to handle QR codes; can also be omitted
        [...]
    ],
    bootstrap: [AppComponent]
})
export class AppModule {}
import { Injectable } from '@angular/core';
import { from, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { BarcodeScanner, BarcodeScanResult } from '@ionic-native/barcode-scanner/ngx';

@Injectable({
    providedIn: 'root'
})
export class QrService {

    constructor(private barcodeScanner: BarcodeScanner) { }

    getQrCode$(): Observable<any> {
        return from(this.barcodeScanner.scan())
            .pipe(
                map((data: BarcodeScanResult) => {
                    const barCodeData = JSON.parse(data.text);
                    return barCodeData;
                })
            );
    }
}