Java Code Examples for com.google.zxing.integration.android.IntentResult#getContents()

The following examples show how to use com.google.zxing.integration.android.IntentResult#getContents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShareContactActivity.java    From Travel-Mate with MIT License 8 votes vote down vote up
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null) {
        //if QRcode has nothing in it
        if (result.getContents() != null) {
            //if QRCode contains data
            //retrieve results
            String resultContents = result.getContents();
            String[] values = resultContents.split(":");
            String userName = values[0];
            String userEmail = values[1];
            addContact(userName, userEmail);
        }
    }
}
 
Example 2
Source File: MainActivity.java    From PLDroidMediaStreaming with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;
    }
    if (requestCode ==  IntentIntegrator.REQUEST_CODE) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if(result != null) {
            if(result.getContents() == null) {
                Toast.makeText(this, "扫码取消!", Toast.LENGTH_SHORT).show();
            } else {
                mInputTextTV.setText(result.getContents());
            }
        }
    }
}
 
Example 3
Source File: SignTransactionActivity.java    From tron-wallet-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if(result != null) {
        if(result.getContents() != null) {
                byte[] transaction_bytes = null;
                try {
                    transaction_bytes = Hex.decode(result.getContents());
                } catch (Exception ignored) { }

                Intent intent = new Intent();
                intent.putExtra(TRANSACTION_SIGNED_EXTRA, transaction_bytes);

                setResult(TRANSACTION_SIGN_REQUEST_CODE, intent);
                finish();
            }
        }
        else {
            super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 4
Source File: KeyScanningActivity.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);

  if ((scanResult != null) && (scanResult.getContents() != null)) {
    String data = scanResult.getContents();

    if (data.equals(Base64.encodeBytes(getIdentityKeyToCompare().serialize()))) {
      Dialogs.showInfoDialog(this, getVerifiedTitle(), getVerifiedMessage());
    } else {
      Dialogs.showAlertDialog(this, getNotVerifiedTitle(), getNotVerifiedMessage());
    }
  } else {
    Toast.makeText(this, R.string.KeyScanningActivity_no_scanned_key_found_exclamation,
                   Toast.LENGTH_LONG).show();
  }
}
 
Example 5
Source File: ThirdPartyScannerActivity.java    From SecScanQR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method handles the results of the scan
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    Intent intent = getIntent();

    if(result != null){
        if(result.getContents()==null){
            setResult(RESULT_CANCELED, intent);
            finish();
            return;
        } else {
            qrcode = result.getContents();
            intent.putExtra("SCAN_RESULT", qrcode);
            setResult(RESULT_OK, intent);
            finish();
            return;
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 6
Source File: ScanActivity.java    From HomeApplianceMall with MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // 获取解析结果
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null) {
        if (result.getContents() == null) {
            finish();
            Toast.makeText(this, "取消扫描", Toast.LENGTH_LONG).show();
        } else {
            String goodId = null;
            String[] res = result.getContents().split("#");
            if(res!=null && res.length==3){
                if(res[0].equals(KEY_1) && res[2].equals(KEY_2)){
                    goodId = res[1];
                }
            }
            if(goodId!=null){
                Intent intent = new Intent(ScanActivity.this,GoodDetailActivity.class);
                intent.putExtra("goodId",goodId);
                startActivity(intent);
            }else{
                Toast.makeText(this, "请扫描本网站二维码!", Toast.LENGTH_LONG).show();
            }
            finish();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 7
Source File: MainActivity.java    From SmartProxy with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == START_VPN_SERVICE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            startVPNService();
        } else {
            switchProxy.setChecked(false);
            switchProxy.setEnabled(true);
            onLogReceived("canceled.");
        }
        return;
    }

    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if (scanResult != null) {
        String configUrl = scanResult.getContents();
        if (isValidUrl(configUrl)) {
            setConfigUrl(configUrl);
            textViewConfigUrl.setText(configUrl);
        } else {
            Toast.makeText(MainActivity.this, R.string.err_invalid_url, Toast.LENGTH_SHORT).show();
        }
        return;
    }

    super.onActivityResult(requestCode, resultCode, intent);
}
 
Example 8
Source File: FragmentPaymentBill.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == requestCodeBarcode) {
        IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
        if (result.getContents() != null) {
            String barCode = result.getContents();
            if (barCode.length() == 26) {
                String billId = barCode.substring(0, 13);
                String payId = barCode.substring(13, 26);
                String company_type = barCode.substring(11, 12);
                String price = barCode.substring(13, 21);

                while (payId.startsWith("0")) {
                    payId = payId.substring(1);
                }

                fragmentPaymentBillBinding.fpbEdtBillId.setText(billId);
                fragmentPaymentBillBinding.fpbEdtPayId.setText(payId);
                fragmentPaymentBillBinding.fpbEdtPrice.setText(addCommasToNumericString((Integer.parseInt(price) * 1000) + ""));
                fragmentPaymentBillBinding.fpbImvCompany.setImageResource(getCompany(company_type));

                fragmentPaymentBillBinding.getFragmentPaymentBillViewModel().observeAmount.set(true);

            }
        }
    }


}
 
Example 9
Source File: DeviceActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Receives value of scanned QR code and sets it as device ID.
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if (scanResult != null) {
        mDevice.deviceID = scanResult.getContents();
        mIdView.setText(mDevice.deviceID);
    }
}
 
Example 10
Source File: AddressBookActivity.java    From bitseal with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) 
{
   ((AddressBookRecordAdapter)mAddressBookListView.getAdapter()).notifyDataSetChanged();
   
   // Get the result of the QR code scan
   IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
   if (result != null)
   {
   	String contents = result.getContents();
   	if (contents != null)
   	{
   		contents = contents.trim(); // Remove leading or trailing spaces
   		
   		Log.i(TAG, "Found QRcode with the following contents: " + contents);
   		
   		if (contents.substring(0, 3).equals(BITMESSAGE_ADDRESS_PREFIX))
   		{
   			openNewEntryDialog(contents);
   		}
   		else
   		{
   			Toast.makeText(getApplicationContext(), R.string.addressBook_toast_qr_address_invalid, Toast.LENGTH_LONG).show();
   			openNewEntryDialog("");
   		}
   	} 
   	else 
   	{
   		Log.i(TAG, "No QRcode found");
   		openNewEntryDialog("");
   	}
   }
}
 
Example 11
Source File: WXDebugActivity.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null) {
        if (result.getContents() == null) {
            Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
        } else {
            handleDecodeInternally(result.getContents());
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 12
Source File: AddProductDialogFragment.java    From pos with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
	IntentResult scanningResult = IntentIntegrator.parseActivityResult(
			requestCode, resultCode, intent);

	if (scanningResult != null) {
		String scanContent = scanningResult.getContents();
		barcodeBox.setText(scanContent);
	} else {
		Toast.makeText(getActivity().getBaseContext(),
				res.getString(R.string.fail),
				Toast.LENGTH_SHORT).show();
	}
}
 
Example 13
Source File: InventoryFragment.java    From pos with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
	IntentResult scanningResult = IntentIntegrator.parseActivityResult(
			requestCode, resultCode, intent);

	if (scanningResult != null) {
		String scanContent = scanningResult.getContents();
		searchBox.setText(scanContent);
	} else {
		Toast.makeText(getActivity().getBaseContext(), res.getString(R.string.fail),
				Toast.LENGTH_SHORT).show();
	}
}
 
Example 14
Source File: HomeActivity.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
    String scanResult = result.getContents();
    if (scanResult != null) {
        BrowserActivity.start(this, scanResult);
    }
}
 
Example 15
Source File: HomeFragment.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
    String scanResult = result.getContents();
    if (scanResult != null) {
        BrowserActivity.start(mActivity, scanResult);
    }
}
 
Example 16
Source File: MainActivity.java    From moserp with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null) {
        if (result.getContents() == null) {
            Log.d("MainActivity", "Cancelled scan");
            Toast.makeText(this.getApplicationContext(), R.string.toast_scan_cancelled, Toast.LENGTH_LONG).show();
        } else {
            Log.d("MainActivity", "Scanned: " + result.getContents());
            startActivity(ProductListActivity.buildIntent(getApplicationContext(), result.getContents()));
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 17
Source File: WelcomeActivity.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode==IntentIntegrator.REQUEST_CODE) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (scanResult == null || scanResult.getFormatName() == null) {
            return; // aborted
        }
        String qrRaw = scanResult.getContents();
        DcLot qrParsed = dcContext.checkQr(qrRaw);
        switch (qrParsed.getState()) {
            case DcContext.DC_QR_ACCOUNT:
                String domain = qrParsed.getText1();
                new AlertDialog.Builder(this)
                        .setMessage(getString(R.string.qraccount_ask_create_and_login, domain))
                        .setPositiveButton(R.string.ok, (dialog, which) -> startQrAccountCreation(qrRaw))
                        .setNegativeButton(R.string.cancel, null)
                        .setCancelable(false)
                        .show();
                break;

            default:
                new AlertDialog.Builder(this)
                        .setMessage(R.string.qraccount_qr_code_cannot_be_used)
                        .setPositiveButton(R.string.ok, null)
                        .show();
                break;
        }
    }
}
 
Example 18
Source File: MainActivity.java    From andOTP with MIT License 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if(result != null) {
        if(result.getContents() != null) {
            addQRCode(result.getContents());
        }
    } else if (requestCode == Constants.INTENT_MAIN_BACKUP && resultCode == RESULT_OK) {
        if (intent.getBooleanExtra("reload", false)) {
            adapter.loadEntries();
            refreshTags();
        }
    } else if (requestCode == Constants.INTENT_MAIN_SETTINGS && resultCode == RESULT_OK) {
        boolean encryptionChanged = intent.getBooleanExtra(Constants.EXTRA_SETTINGS_ENCRYPTION_CHANGED, false);
        byte[] newKey = intent.getByteArrayExtra(Constants.EXTRA_SETTINGS_ENCRYPTION_KEY);

        if (encryptionChanged)
            updateEncryption(newKey);

        if (recreateActivity) {
            cacheEncKey = true;
            recreate();
        }
    } else if (requestCode == Constants.INTENT_MAIN_AUTHENTICATE) {
        if (resultCode != RESULT_OK) {
            Toast.makeText(getBaseContext(), R.string.toast_auth_failed_fatal, Toast.LENGTH_LONG).show();
            finishAndRemoveTask();
        } else {
            requireAuthentication = false;

            byte[] authKey = null;

            if (intent != null)
                authKey = intent.getByteArrayExtra(Constants.EXTRA_AUTH_PASSWORD_KEY);

            updateEncryption(authKey);
        }
    } else if (requestCode == Constants.INTENT_MAIN_QR_OPEN_IMAGE && resultCode == RESULT_OK) {
        if (intent != null) {
            addQRCode(ScanQRCodeFromFile.scanQRImage(this, intent.getData()));
        }
    }
}
 
Example 19
Source File: ImportOrExportActivity.java    From bitseal with GNU General Public License v3.0 4 votes vote down vote up
@Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent) 
  {	
// Get the result of the QR code scan
     IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
     if (result != null)
     {
      String contents = result.getContents();
      if (contents != null)
      {
   	   contents = contents.trim(); // Remove leading or trailing spaces
      		
   	   if (new AddressProcessor().validatePrivateKey(contents))
   	   {
   		   if (privateSigningKeyScan)
   		   {
   			   privateSigningKey = contents;
   		   }
   		   else if (privateEncryptionKeyScan)
   		   {
   			   privateEncryptionKey = contents;
   		   }
   		   
   		   openImportDialog();
   	   }
   	   else
   	   {
   		   Toast.makeText(getApplicationContext(), R.string.import_or_export_toast_scanned_code_invalid, Toast.LENGTH_LONG).show();
   		   openImportDialog();
   	   }
      }
      else 
      {
      		Log.i(TAG, "No QRcode found");
      		openImportDialog();
      }
     }
     
     // Reset the boolean values that allow us to detect which key type we have been scanning for
privateSigningKeyScan = false;
privateEncryptionKeyScan = false;
  }
 
Example 20
Source File: SwapWorkflowActivity.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if (scanResult != null) {
        if (scanResult.getContents() != null) {
            NewRepoConfig repoConfig = new NewRepoConfig(this, scanResult.getContents());
            if (repoConfig.isValidRepo()) {
                confirmSwapConfig = repoConfig;
                showRelevantView();
            } else {
                Toast.makeText(this, R.string.swap_qr_isnt_for_swap, Toast.LENGTH_SHORT).show();
            }
        }
    } else if (requestCode == REQUEST_WRITE_SETTINGS_PERMISSION) {
        if (Build.VERSION.SDK_INT >= 23 && Settings.System.canWrite(this)) {
            setupWifiAP();
        }
    } else if (requestCode == REQUEST_BLUETOOTH_ENABLE_FOR_SWAP) {

        if (resultCode == RESULT_OK) {
            Utils.debugLog(TAG, "User enabled Bluetooth, will make sure we are discoverable.");
            ensureBluetoothDiscoverableThenStart();
        } else {
            Utils.debugLog(TAG, "User chose not to enable Bluetooth, so doing nothing");
            SwapService.putBluetoothVisibleUserPreference(false);
        }

    } else if (requestCode == REQUEST_BLUETOOTH_DISCOVERABLE) {

        if (resultCode != RESULT_CANCELED) {
            Utils.debugLog(TAG, "User made Bluetooth discoverable, will proceed to start bluetooth server.");
            BluetoothManager.start(this);
        } else {
            Utils.debugLog(TAG, "User chose not to make Bluetooth discoverable, so doing nothing");
            SwapService.putBluetoothVisibleUserPreference(false);
        }

    } else if (requestCode == REQUEST_BLUETOOTH_ENABLE_FOR_SEND) {
        sendFDroidApk();
    }
}