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/