Scanning via Intent
  • 05 Sep 2024
  • 1 Minute to read
  • Contributors
  • Dark
    Light

Scanning via Intent

  • Dark
    Light

Article summary

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

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():

@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 on our Github.


Was this article helpful?