Created
January 28, 2015 10:32
-
-
Save AlexHedley/e7374ab15ebd3722e904 to your computer and use it in GitHub Desktop.
Integrate Zxing into Android Studio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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