コード例 #1
0
  /** Scan a barcode on button click with Scandit SDK */
  public void scanItem() {
    // start scanning
    if (ScanditSDKBarcodePicker.canRunPortraitPicker()) {
      // the standard picker can be used
      Log.i("scanner", "Using standard scanner.");
      mBarcodePicker =
          new ScanditSDKBarcodePicker(
              this, SCANDIT_APP_KEY, ScanditSDKBarcodePicker.CAMERA_FACING_BACK);
    } else {
      // the legacy picker must be used
      Log.i("scanner", "Using legacy scanner.");
    }

    // From ScanditSDKSampleBarcodeActivity
    // initializeAndStartBarcodeScanning()
    // Add both views to activity, with the scan GUI on top.
    setContentView(mBarcodePicker);

    // Register listener, in order to be notified about relevant events
    // (e.g. a successfully scanned bar code).
    mBarcodePicker.getOverlayView().addListener(this);

    // show search bar in scan user interface
    mBarcodePicker.getOverlayView().showSearchBar(true);

    // To activate recognition of 2d codes
    mBarcodePicker.setQrEnabled(true);
    mBarcodePicker.setDataMatrixEnabled(true);

    // Start scanning stuff
    mBarcodePicker.startScanning();
  }
コード例 #2
0
 @Override
 protected void onResume() {
   // Once the activity is in the foreground again, restart scanning.
   if (mBarcodePicker != null) {
     mBarcodePicker.startScanning();
   }
   super.onResume();
 }