GDG Chicago Android

Google Developers Group

Barcode scanning is one of the quickest way to gather information for your app. Here is a code snippit that you can add to your application


//begins the barcoding intent
public void barcode(){
Log.i("mssg", "Barcode Button pressed");
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "Product_MODE");// Product_MODE or QR_CODE_MODE
startActivityForResult(intent, 0);
}


// handle info from result
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");// Barcode number or QR code info
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// do things with info gathered

} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}

Views: 50

Tags: android, barcode

Comment

You need to be a member of GDG Chicago Android to add comments!

Join GDG Chicago Android

© 2014   Created by Uki Dominque Lucas.

Badges  |  Report an Issue  |  Terms of Service