简体   繁体   English

如果安装了Google护目镜,则通过意图使用Zxing的问题

[英]Issue in using Zxing via intent if google goggles is installed

I am using following code to invoke Barcode scanner apps from Zing 我正在使用以下代码从Zing调用条形码扫描程序应用程序

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);
    }
};

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

The problem is if Barcode scanner app is not installed and user has any other scanning app like google goggles i dont get desired result back.This breaks my application. 问题是如果没有安装条形码扫描仪应用程序,并且用户有任何其他扫描应用程序,如谷歌护目镜,我没有得到所需的结果回来。这打破了我的应用程序。

Is there any way in which i can prevent this ?? 有什么办法可以阻止这个吗?

Yes. 是。 call Intent.setPackage() with value "com.google.zxing.client.android". 使用值“com.google.zxing.client.android”调用Intent.setPackage() This will force it to only accept a response from Barcode Scanner. 这将迫使它仅接受条形码扫描仪的响应。

Note however that this will make it impossible for other apps to respond, like Barcode Scanner+. 但请注意,这将使其他应用无法响应,例如Barcode Scanner +。

its better to integrate the bar code scanner to your app. 最好将条形码扫描仪集成到您的应用程序中。 Zxing is an open source code you can download it from here . Zxing是一个开源代码,可以从这里下载。 And for the Integration please refer this: http://www.falatic.com/index.php/12/building-zxing-for-android-part-3-using-eclipse . 有关集成,请参阅: http//www.falatic.com/index.php/12/building-zxing-for-android-part-3-using-eclipse I think this will solve your issue. 我认为这将解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM