开发者

Integration problem ZXing via Intent

Well, I'm trying implement a integration of zxing with my Android App. In my app there is a MainA开发者_如何学Goctivity. In this MainActivity, I use a button to execute the first block of code below. But every time when execute the first block of code and the app read the QR Code, I receive as resultCode the value RESULT_CANCELED in the second block. The second block is executed as soon as the ZXing Activity is opened. What do I doing wrong?

First Block of Code

Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");
    intent1.setPackage("com.google.zxing.client.android");
    intent1.putExtra("SCAN_MODE", "ONE_D_MODE");
    startActivityForResult(intent1, 0);

Second block of code

public void onActivityResult(int requestCode, int resultCode, Intent intent2) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents2 = intent2.getStringExtra("SCAN_RESULT");
            String format2 = intent2.getStringExtra("SCAN_RESULT_FORMAT");
            EditText assetMon1 = (EditText) findViewById(R.id.assetMon1);
            assetMon1.setText(contents2);
        } else if (resultCode == RESULT_CANCELED) {
            // Every time I receive this code
        }
    }
}


I have very similar code in my app. The only significant difference is that I have "PRODUCT_MODE" instead of "ONE_D_MODE".


Follow the sample code provided in the project under android-integration. Just call the methods in this class rather than debug your own version. I think using requestCode 0 is most likely to be the problem, but I'm guessing. It is supposed to be a sort of unique ID for the request. But 0 might be used by something else and you're really hearing a response to something else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜