Scanning via Intent
C
Written by Christian Powell
Updated over a week ago

The simplest way to integrate barcode scanning into your app is to invoke the Barcode Scanner via an intent.

Java

import com.vuzix.sdk.barcode.ScannerIntent;
import com.vuzix.sdk.barcode.ScanResult2;
private static final int REQUEST_CODE_SCAN = 0;
Intent scannerIntent = new Intent(ScannerIntent.ACTION);
startActivityForResult(scannerIntent, REQUEST_CODE_SCAN);


The scan result will be returned to you in onActivityResult():

Java

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_SCAN: if (resultCode == Activity.RESULT_OK) {
ScanResult2 scanResult = data.getParcelableExtra(ScannerIntent.RESULT_EXTRA_SCAN_RESULT2);
// do something with scan result
} return;
}
super.onActivityResult(requestCode, resultCode, data);
}

For more information on barcode scanning by intent, including intent extras that are available, refer to the JavaDoc for the ScannerIntent class.

A sample Android Studio project demonstrating barcode scanning via intent is available here: Sample App Download

Did this answer your question?