科尔多瓦栏code Android上的扫描仪 - 取消扫描并返回到应用程序 [英] Cordova barcode scanner on Android - cancel scan and return to app

查看:310
本文介绍了科尔多瓦栏code Android上的扫描仪 - 取消扫描并返回到应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个科尔多瓦的应用程序,用于Android设备,它使用了吧code扫描插件。该应用程序本身在设备准备一个覆盖到默认的Andr​​oid后退按钮:

We have a Cordova app, intended for Android devices, which uses the bar code scanner plugin. The app itself as an overwrite to the default Android back button upon device ready:

document.addEventListener("backbutton", onBackKeyDown, false);

问题是,当用户取消由pressing后退按钮扫描,相机关闭,应用程序显示web视图,然后启动后退按钮事件(即调用onBackKeyDown功能)。至于如果后退按钮是pssed上的WebView本身,而不是在扫描活动$ P $。
我们已经尝试一些替代品,例如 - 在开始扫描之前,删除事件监听器:

The issue is that when the user cancels the scan by pressing the back button, The camera closes and the app display the webview, and then launches the "backbutton" event (i.e. invoking the onBackKeyDown function). As if the back button was pressed on the webview itself and not on the scan activity. we have tried some alternatives, for example - before starting the scan, remove the event listener:

function startScan() {

    document.removeEventListener("backbutton", onBackKeyDown, false);   
    cordova.plugins.barcodeScanner.scan(    
....

但它并没有帮助。
我们不能忽略它的插件本身,因为它不是一种活动。这意味着我们必须这样做的JavaScript的。

but it didn't help. We cannot override it on the plugin itself, since it's not an activity. Meaning we must do it on the JavaScript.

任何解决方案大多是AP preciated。

Any solution is mostly appreciated.

推荐答案

您还在吗?我在与后退按钮的问题我自己...
我使用PhoneGap的酒吧code扫描插件太,并有后退按钮事件侦听器。

Are you still on this? I'm having issues with the back button myself... I use the barcode scanner plugin for phonegap too, and have an event listener for the back button.

我落得这样做是增加我设置为true每次扫描一个标志,然后每次调用onBackKeyDown功能 - 如果这是真的,然后恢复到备份虚假不执行函数的其余部分...

What I ended up doing is adding a flag that I set to true on every scan and then whenever calling the onBackKeyDown function - if it is true then reset to back false without executing the rest of the function...

var in_barcode_scan = false;
function onBackKeyDown() {
    if (in_barcode_scan) {
        in_barcode_scan = false;
    } else {
        //do whatever you need when a legit back button is triggered.
    }
}
function startScan() {
    in_barcode_scan = true;
    cordova.plugins.barcodeScanner.scan(.....
}

我现在有其他的问题我自己(取消吧code扫描杀死其他一些事件侦听器),但是这也许应该为你做的伎俩...

I'm now having other issues myself (cancelling the barcode scanner kills some other event listeners), but this should probably do the trick for you...

Jospeh。

这篇关于科尔多瓦栏code Android上的扫描仪 - 取消扫描并返回到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆