Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a 1-D barcode from string in Android?

I am using ZXing via intent to scan 1D bar-codes. ZXing sends me back the type of 1D barcode that was scanned (UPC-A, Code 39, etc...) and the string that is encoded in the barcode. I would like to take the type and string and generate and image of the 1D barcode and display it in an ImageView in an activity.

I am also open to displaying the barcode in a TextView using a font similar to "Free 3 of 9", but I cannot figure out how to do this.

I noticed that there is an activity in ZXing called EncodeActivity that can perform what I need, but only for QR codes.

Any help would be appreciated.

Thanks.

like image 343
Matt Wear Avatar asked Feb 01 '11 17:02

Matt Wear


2 Answers

Using ZXing IntentIntegrator and IntentResult classes!

    String data = "123456789";

    Intent intent = new Intent("com.google.zxing.client.android.ENCODE");  

    intent.addCategory(Intent.CATEGORY_DEFAULT); 

    intent.putExtra("ENCODE_FORMAT", "CODE_128");  

    intent.putExtra("ENCODE_DATA", data);  

    startActivity(intent); 

It only works if you have the Barcode reader installed on your Android

If you need help, ask me!

like image 97
Mark Comix Avatar answered Sep 28 '22 16:09

Mark Comix


Display Barcode using Google barcode reader

Intent intent = new Intent("com.google.zxing.client.android.ENCODE");   
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra("ENCODE_TYPE", "TEXT_TYPE"); 
intent.putExtra("ENCODE_DATA",scan_code_main); // content part
intent.putExtra("ENCODE_FORMAT",scan_code_2); // format part

startActivity(intent);
like image 23
Utpal Avatar answered Sep 28 '22 15:09

Utpal