Android scans product barcode

Source: Internet
Author: User
Android scans product barcode

The simplest Android barcode scanning function just now can only scan QR codes. If you want to scan a regular product barcode, You need to seat it in the program and modify it a little bit.

Interface changes:

Effect of bar code scanning:

Display scan results (the recognition speed is significantly lower than the QR code ):

Code changes:

Package com. easymorse;

Import Android. App. activity;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;
Import Android. widget. textview;

Public class showbarcodeactivity extends activity {

Private button;

Private button button2;

Private textview;

/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );

This. Button = (button) This. findviewbyid (R. Id. button01 );
This. Button. setonclicklistener (New onclicklistener (){

@ Override
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 );
}
});

This. button2 = (button) This. findviewbyid (R. Id. button02 );
This. button2.setonclicklistener (New onclicklistener (){

@ Override
Public void onclick (view v ){
Intent intent = new intent (
"Com. Google. zxing. Client. Android. Scan ");
Intent. putextra ("scan_mode", "ean_13 ″);
Startactivityforresult (intent, 0 );
}
});

This. textview = (textview) This. findviewbyid (R. Id. Hello );
}

@ Override
Protected void onactivityresult (INT requestcode, int resultcode, intent data ){
If (requestcode! = 0 ){
Return;
}

This. textview. settext (data. getstringextra ("scan_result "));
}
}

After writing this example, you can see that you do not need to write it now:

Intent. putextra ("scan_mode", "qr_code_mode ");

Zxing's current library can automatically identify which encoding is used. If it is written, it specifies the type rather than the encoding of other types. In fact, the above:

Intent. putextra ("scan_mode", "ean_13 ″);

Incorrect. For specific constant parameters, see:

Http://zxing.org/w/docs/javadoc/constant-values.html

The above content is not modified. The correct source code is shared in the Svn of Google Code. See:

Http://easymorse.googlecode.com/svn/tags/barcode.proto.0.1.0/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.