如何获得QR code型 [英] how to get QR code type

查看:268
本文介绍了如何获得QR code型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Zxing库工作脱code QR code为Android。我可以QR code。现在,我要赶c将其返回什么类型的QR $ C $的说(URL,电话2-14,纯文本等)。我试图探索<一个href=\"http://$c$c.google.com/p/zxing/source/browse/trunk/core/src/com/google/zxing/client/result/ResultParser.java?r=2283\"相对=nofollow> ResultParser 类,但我不能使用它。

I am working with Zxing library to decode QR code for android. I can get QR Code. Now, I want to catch what types of QR code it returns say (URL,Phone Nubmer,Plain Text etc). I tried to explore ResultParser class but i can't use it.

更新:我使用ResultParser类中删除我的错误的程序

Updated: I remove my wrong procedure using ResultParser class.

下面是我的onActivityResult code。

Here is my onActivityResult Code.

    @Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            contents = intent.getStringExtra("SCAN_RESULT");
        // check the contents strings here 
          //  Need to get actual return type of result 
            if (contents.contains("https:") || contents.contains("http:")) {
                aBarcode.setBarcode_Type(WEB_URL);
                Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(contents));
                startActivity(browserIntent);

            } else {
                aBarcode.setBarcode_Type(PLAIN_TEXT);
                Toast.makeText(getApplicationContext(), contents,
                        Toast.LENGTH_LONG).show();
            }
            barcodeList.add(aBarcode);
            // show previous barcodes detail
            showBarcodeReaderHistory();
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            Log.e("Barcode Result", "Result canceled");
        }
    }
}

更新:我开ScanActivity这样的:

Updated :I open ScanActivity like:

// start scan after button click
        btnScanQRCode.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {

                 Intent intent = new Intent(
                 "com.google.zxing.client.android.SCAN");
                 intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                 startActivityForResult(intent, 0);

            }
        });

希望,我清楚所有。等待你的很大的敲门声。
谢谢你。

Hope, i clear it to all. Waiting for your great knock. Thank you.

推荐答案

您可以modifie的 CaptureActivity 图书馆获得QR code型到你的活动。

You can modifie the CaptureActivity of the library to get the QR Code type into your Activity.

CaptureActivity 还有一个方法的名称 handleDe codeExternally 返回的数据到你的活动添加此行

In CaptureActivity there is a method name handleDecodeExternally which returns the data to your Activity add this line

intent.putExtra("QR_TYPE", getString(resultHandler.getDisplayTitle()));

在活动结束。

然后得到这个价值,你的活动的的onActivityResult

And then get this value to your Activity's onActivityResult

String type = intent.getStringExtra("QR_TYPE");

最后,你有QR code类型。

Finally you have the type of QR Code.

感谢您

在在 com.google.zxing.client.android您资兴市库项目包有一个名为活动 CaptureActivity 。而该活动有名为 handleDe codeExternally 其中简要介绍了吧$ C $的内容C,然后把手code扫描仪之外的结果。在该方法中有由你送你的QR找到你的活动是什么数据的意图。

In your zixing library project under com.google.zxing.client.android package there is an Activity named CaptureActivity. And on that Activity there is method named handleDecodeExternally which Briefly show the contents of the barcode, then handle the result outside Barcode Scanner. In that method there is an intent by which you have send the data what you found on QR to your activity.

补充说行,你离开这个活动之前,增加它会像这之后 -

add that line before you leave this activity, After adding it will be like this --

      // ------------- Mine Added -------------------
      intent.putExtra("QR_TYPE", getString(resultHandler.getDisplayTitle()));
      // --------------------------------------------

      sendReplyMessage(R.id.return_scan_result, intent); 

我想你会发现这个 sendReplyMessage(R.id.return_scan_result,意向);在 CaptureActivity 650 +/-行C $ C>。谢谢

i think you will find this sendReplyMessage(R.id.return_scan_result, intent); in 650 +/- line in CaptureActivity. Thank you

这篇关于如何获得QR code型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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