如何从QR扫描使用zxing捕获数据 [英] how to capture data from qr scanner using zxing

查看:148
本文介绍了如何从QR扫描使用zxing捕获数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序和一个部分涉及QR扫描。大量的研究后,我成功地开发一个独立的扫描应用程序。当用户打开扫描仪​​和扫描QR特别code,他得到一定的价值,例如一个URL。现在我要存储在扫描取入我的Andr​​oid code中的数据。任何人可以帮助我我怎么做呢?

这是我所看到的,我需要捕获活动课Zxing的工作。不过,我不知道到底需要做什么。所有这一切我看网上直销我博客使用意图打电话吧code扫描。但是,我的应用程序的目的不是为了仅仅扫描产品。我需要存储扫描产品的信息,并在以后将其用于其他目的。

请帮我。

谢谢,
Amey

下面是Zxing的code ..这是与所有扫描涉及的主要活动。我有什么用在线阅读了解到,我需要捕获返回的数据时,酒吧code扫描。

 公共无效的onActivityResult(INT申请code,INT结果code,意图意图){
    如果(结果code == RESULT_OK){
        如果(要求code == HISTORY_REQUEST_ code){            INT itemNumber = intent.getIntExtra(Intents.History.ITEM_NUMBER,-1);            如果(itemNumber> = 0){
                HistoryItem historyItem = historyManager.buildHistoryItem(itemNumber);
                德codeOrStoreSavedBitmap(NULL,historyItem.getResult());
            }
        }
    }
}
如果(Intents.Scan.ACTION.equals(动作)){//扫描意图要求的格式,并把结果返回给调用活动
    来源= IntentSource.NATIVE_APP_INTENT;    德codeFormats =德codeFormatManager.parseDe codeFormats(意向);
    如果(intent.hasExtra(Intents.Scan.WIDTH)及&放大器; intent.hasExtra(Intents.Scan.HEIGHT)){        INT宽度= intent.getIntExtra(Intents.Scan.WIDTH,0);
        INT高度= intent.getIntExtra(Intents.Scan.HEIGHT,0);        如果(宽度大于0&放大器;&放大器;高度大于0){
            cameraManager.setManualFramingRect(宽度,高度);
        }
    }
}


解决方案

您好我终于找到了这个问题的答案。这并不是说困难,因为我认为(因为Zxings code已被写入由Zxing团队,而不是由我..反正..)

所以,如果你想存储通过QR扫描(由Zxing提供)在你的Andr​​oid code捕获的数据(不管出于什么目的。在我的情况,我想这个数据发送到Web服务器..反正。 。),那么你只需要修改下面的函数..这里是你得到的扫描活动的结果。

 公共无效handleDe code(结果rawResult,位图巴code){
inactivityTimer.onActivity();
的lastResult = rawResult;
Log.d(最后结果,检查,如果生的结果是什么,我希望);
的System.out.println(的lastResult);
ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(这一点,rawResult);
historyManager.addHistoryItem(rawResult,resultHandler);
}

我添加日志和报表打印,以检查是否我得到正确的结果。是的,它没有给我一个正确的答案..
您可以在CaptureActivity类找到。

@triggs:感谢您的帮助!你没让我在正确的轨道: - )

I am developing an application and a part of that involves QR scanning. After a lot of research I was successful in developing a stand alone scanning app. When a user opens the scanner and scans a particular QR code, he gets some value, e.g. a URL. Now I want to store the data acquired on scanning into my android code. Can anybody help me how do i go about it?

From what I can see, I need to work with capture activity class of Zxing. However, I am not sure what exactly needs to be done. All the blogs that I read online direct me to use an Intent to call barcode scanning. However, the purpose of my app is not to just scan the products. I need to store the information of the scanned product and later use it for some other purpose.

Kindly help me.

Thanks, Amey

Here is the code from Zxing.. this is the main activity that deals with all the scanning. to what i have learnt by reading online, i need to capture the data returned when a barcode is scanned..

public void onActivityResult(int requestCode, int resultCode, Intent intent) { 
    if (resultCode == RESULT_OK) { 
        if (requestCode == HISTORY_REQUEST_CODE) { 

            int itemNumber = intent.getIntExtra(Intents.History.ITEM_NUMBER, -1); 

            if (itemNumber >= 0) { 
                HistoryItem historyItem = historyManager.buildHistoryItem(itemNumber);             
                decodeOrStoreSavedBitmap(null, historyItem.getResult()); 
            } 
        }
    } 
} 


if (Intents.Scan.ACTION.equals(action)) { // Scan the formats the intent requested, and   return the result to the calling activity 
    source = IntentSource.NATIVE_APP_INTENT; 

    decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); 
    if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {

        int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); 
        int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); 

        if (width > 0 && height > 0) { 
            cameraManager.setManualFramingRect(width, height); 
        } 
    }
}

解决方案

Hi I have finally found an answer to this question. It was not that difficult as i thought (since Zxings code has been written by Zxing team and not by me.. anyway..)

So if you want to store the data captured by qr scanner(provided by Zxing) in your android code (for whatever purpose.. in my case i want to send this data to the web server.. anyway..) then you just need to modify the following function.. here is where you get the result of the scanned activity..

public void handleDecode(Result rawResult, Bitmap barcode) {
inactivityTimer.onActivity();
lastResult = rawResult;
Log.d("last result", "checking if raw result is what i expect");
System.out.println(lastResult);
ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult);
historyManager.addHistoryItem(rawResult, resultHandler);
}

I have added Log and print statements to check if i am getting the correct result. and yes, it did give me a correct answer.. you can find this in CaptureActivity class.

@triggs: thanks for your help! You did get me on a right track :-)

这篇关于如何从QR扫描使用zxing捕获数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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