Starting the android zxing scanner via web app doesn't seem to work

烈酒焚心 提交于 2020-01-06 07:53:30

问题


My starting point for scanning from a web app was this article here Then i realized it was as simple as clicking a link like this

http://zxing.appspot.com/scan?req=http%3A%2F%2FLOCAL_SERVER_NAME%2FMY_APP_NAME%2FMY_SERVLET%3Fcode%3D%7BCODE%7D

but it didn't work.

My web app is simple like this (using ajax from jquery)

$("#onebutton").click(function(){
        $.ajax({
            url: "http://zxing.appspot.com/scan",
            success:function(){
                alert("success");
            },
            error:function(){
                alert("error");
            },
            data:{
                req:"http%3A%2F%2F192.168.1.100:8080%2FMY_APP_NAME%2FMY_SERVLET%3Fcode%3D%7BCODE%7D"
            }

        });
    });

needless to say that "#onebutton" is a button tag with that id. When Pressing such button on a browser in android it always alerts the error message. It doesn't ask for the scanner to start up. When i click the button in a normal PC, the console says:

"Origin http://192.168.1.100:8080 is not allowed by Access-Control-Allow-Origin".

Am i doing something wrong?. Am i missing something?

Thank you all in advance!!


回答1:


I dont know if you fully understand purpose of link.

Try to add to

Access-Control-Allow-Origin on server

Or

$("#onebutton").click(function(){
        $.ajax({
            url: "http://zxing.appspot.com/scan?ret=http%3A%2F%2F192.168.1.100:8080%2FMY_APP_NAME%2FMY_SERVLET%3Fcode%3D%7BCODE%7D",
            success:function(){
                alert("success");
            },
            error:function(){
                alert("error");
            }

        });
    });

but you propably dont understand

<a href="zxing://scan/?ret=http%3A%2F%2Ffoo.com%2Fproducts%2F%7BCODE%7D%2Fdescription&SCAN_FORMATS=UPC_A,EAN_13"> ads </a>

This is serve to open zxing scanner get some code information and replace it in the given url after it is open like

.../scan!ret=www.host.com/product_{code}.hmtl

after scan it open web browser with

http://www.host.com/product_123.html




回答2:


You should use a link like this to open the scanner:

<a href="zxing://scan/?ret=http://something.com/yourpage$status={CODE}"> 
    <span>My scan</span>
</a>

Please, pay attention that in my example $status is a variable which takes the value of the scanned barcode. This passes the value as a parameter in the address of the page it is leading to.

I see that the thread is a bit old, but I hope this will help someone.



来源:https://stackoverflow.com/questions/14490290/starting-the-android-zxing-scanner-via-web-app-doesnt-seem-to-work

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