@Override
 public void onBackPressed() {
   if (mBarcodePicker != null) {
     mBarcodePicker.stopScanning();
   }
   finish();
 }
 @Override
 public void didCancel() {
   mBarcodePicker.stopScanning();
   Intent intent = new Intent();
   setResult(RESULT_CANCELED, intent);
   finish();
 }
 @Override
 protected void onPause() {
   // When the activity is in the background immediately stop the
   // scanning to save resources and free the camera.
   if (mBarcodePicker != null) {
     mBarcodePicker.stopScanning();
   }
   super.onPause();
 }
 @Override
 protected void onPause() {
   // When the activity is in the background immediately stop the
   // scanning to save resources and free the camera.
   if (mBarcodePicker != null) {
     mBarcodePicker.stopScanning();
   }
   LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
   locationManager.removeUpdates(this);
   super.onPause();
 }
  @Override
  public void didScanBarcode(String barcode, String symbology) {
    Log.i("scanner", "Scan done!! barcode=\"" + barcode + "\"; symbology=\"" + symbology + "\"");
    Log.i("scanner", "scan result: " + barcode);

    // Stop recognition to save resources.
    mBarcodePicker.stopScanning();
    mBarcodePicker = null;

    Intent intent = new Intent();
    intent.putExtra("barcode", barcode);
    setResult(RESULT_OK, intent);
    finish();
  }
 /**
  * Called when the user entered a bar code manually.
  *
  * @param entry The information entered by the user.
  */
 @Override
 public void didManualSearch(String entry) {
   // Stop recognition to save resources.
   mBarcodePicker.stopScanning();
   Toast.makeText(this, "User entered: " + entry, Toast.LENGTH_LONG).show();
 }