Skip to content

Instantly share code, notes, and snippets.

@AlexHedley
Created January 28, 2015 10:32
Show Gist options
  • Select an option

  • Save AlexHedley/e7374ab15ebd3722e904 to your computer and use it in GitHub Desktop.

Select an option

Save AlexHedley/e7374ab15ebd3722e904 to your computer and use it in GitHub Desktop.
Integrate Zxing into Android Studio
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}
dependencies {
compile 'com.google.zxing:core:2.2'
compile 'com.embarkmobile:zxing-android-minimal:1.2.1@aar'
}
// import the various classes
// Add the controls to your View
Button button;
TextView tvScanResults;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_barcode);
button = (Button) findViewById(R.id.button);
tvScanResults = (TextView) findViewById(R.id.textView);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
IntentIntegrator.initiateScan(this);
}
// Add the following
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
tvScanResults.setText(scanResult.getContents());
} else {
// else continue with any other code you need in the method
Log.v("BarcodeActivity", "No result");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment