通过网络应用程序启动Android zxing扫描仪似乎不起作用

时间:2013-01-23 22:07:46

标签: android jquery ajax web-applications zxing

我从网络应用程序扫描的起点是本文here 然后我意识到这就像点击这样的链接一样简单

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

但它不起作用。

我的网络应用程序很简单(使用jquery的ajax)

$("#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"
            }

        });
    });

不用说“#onebutton”是带有该id的按钮标签。当在android中的浏览器上按下这样的按钮时,它总是警告错误消息。它不要求扫描仪启动。 当我点击普通PC中的按钮时,控制台会说:

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

我做错了吗?我错过了什么吗?

提前谢谢大家!!

2 个答案:

答案 0 :(得分:0)

我不知道你是否完全理解链接的目的。

尝试添加到

Access-Control-Allow-Origin on server

或者

$("#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");
            }

        });
    });

但你可能不理解

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

这是打开zxing扫描仪获取一些代码信息的服务 并在打开后将其替换为给定的URL,如

... /扫描!RET = www.host.com / product_ {代码} .hmtl

扫描完成后,用

打开网页浏览器

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

答案 1 :(得分:0)

您应该使用这样的链接打开扫描仪:

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

请注意,在我的示例中,$ status是一个采用扫描条形码值的变量。这会将值作为参数传递给它所导致的页面地址。

我看到线程有点旧,但我希望这会对某人有所帮助。