开发者

How to get information by bar code?

开发者 https://www.devze.com 2023-04-06 07:32 出处:网络
I\'m a new android develo开发者_运维知识库per, and I try to create an app for using bar code. I try ZXing, it is very easy. But now I need get information about product by bar code. How can I do that?

I'm a new android develo开发者_运维知识库per, and I try to create an app for using bar code. I try ZXing, it is very easy. But now I need get information about product by bar code. How can I do that?


You'll need to use some kind of web service to look up the product information associated with an UPC/EAN code using for example an AsyncTask. A quick Google search turned up the Internet UPC Database.

Here's a sample record of what data they provide: http://www.upcdatabase.com/item/0081697521221

Please carefully read their ToS: http://www.upcdatabase.com/docs/terms.asp


To use one dimensional barcodes use PRODUCT_MODE. If you want to be able to scan them all don't set anything in extras scan_mode.

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


Bar code gives you nothing but a number (product number). You need to have a web service where you can send this number to get more details.


you have to call the barcode reader by intent, then the user scans the barcode(if they have the barcode reader installed), and the barcode reader sends the data to your app

here's the code on how to do it. http://code.google.com/p/zxing/wiki/ScanningViaIntent

as you can see in public void onActivityResult

these are the data returned by the scanner

        String contents = intent.getStringExtra("SCAN_RESULT");
        String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
0

精彩评论

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