Cordova cordova-plugin-qrscanner: Opaque camera view

点点圈 提交于 2019-12-07 23:46:12

问题


I am working through quasar-framework and I do the wrap with cordova for android platform.

The scanner works fine but blindly.

When QRScanner.show() starts I am getting full opaque view. I try to do all html elements transparent, hide and even remove some of them after and before QRScanner.show() call but always I see the opaque view. Someone knows how to fix this?

<script>

export default {
    /*
        Fuentes:

        camera
        https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/index.html#takePicture

        qrscanner
        https://github.com/bitpay/cordova-plugin-qrscanner#prepare

    */
    mounted () {
        this.prepDevice()
    },
    data () {
        return {
            imageURI: '',
            authorized: false,
            selection: 'standard',
            selectOptions: [
                {
                    label: 'Camera-thumbnail',
                    value: 'camera-thmb'
                },
                {
                    label: 'Standard',
                    value: 'standard'
                }
            ],
            enableVisibility: 'hidden',
            backColor: 'transparent'
        }
    },
    methods: {
        prepDevice () {
            QRScanner.prepare(this.onDone)
        },
        onDone: function (err, status) {
            if(err) {
                alert("preparing: error code = " + err.code)
            }
            if(status.authorized) {
                this.authorized = true
            } else if (status.denied || !status.authorized) {
                this.openSettings()
            } else {
                //No se obtuvo permiso
            }
        },
        goScan: function () {
            //--->>> Funciona pero el escaneo es a ciegas (vista en negro) <<<---

            this.authorized = false

            QRScanner.show()

            /*
                var html = document.getElementsByTagName("*")
                for (var i=0; i<html.length; i++) {
                    html[i].style.backgroundColor = "transparent"
                }
            */


            //QRScanner.enableLight()
            QRScanner.scan(this.displayContents)
        },
        displayContents: function (err, text) {
            if(err){
                alert("scanning: error code = " + err.code)
                if(err.name === 'SCAN_CANCELED') {
                    alert("The scan was canceled before a QR code was found.")
                }
            } else {
                alert(text)
            }
            //QRScanner.hide()
            //QRScanner.disableLight()
            QRScanner.destroy() // hide, cancelScan...
            this.authorized = true
        },
        cancelScan() {
            QRScanner.cancelScan()
            this.authorized = true
        },
        openSettings() {
            if(status.canOpenSettings){
                if(confirm("Would you like to enable QR code scanning? You can allow camera access in your settings.")){
                    QRScanner.openSettings();
                }
            }
        }
    }
}

And the html where I call the goScan function:

<button v-if="authorized" class="secondary push" @click="goScan()">Go Scan</button>

Resource: https://github.com/bitpay/cordova-plugin-qrscanner

As I said the scan works fine but blindly with the full opaque camera view.

Thanks.


回答1:


If scanning is already working, you're nearly there. Ensuring the video preview is visible basically requires stepping through the layers of your application and confirming that the layer isn't obscuring the preview.

Start by inspecting the DOM of your app while it's running on the device. Try setting a background of none transparent on each element covering the view, including the body and html elements. In almost all cases, you'll find a rogue container with a white background somewhere in the layers of your app.

If you're entirely convinced the entire web view is transparent (note: this is very unusual), you'll need to inspect the native layers of your app to determine if another plugin or configuration setting is interfering with visibility. Instructions for this step would be very platform specific, so it's best to consult documentation/forums for the platform in question.



来源:https://stackoverflow.com/questions/43225506/cordova-cordova-plugin-qrscanner-opaque-camera-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!