使用zxing集成代码扫描我的android项目中的qr代码。我得到的字符串像 CMD#9874563210 。现在想分裂并进入两个字符串。
我尝试过以下功能来分割字符串,
public void populateScanData(String scanData){
/*StringTokenizer strTkn = new StringTokenizer(scanData, "#");
ArrayList<String> arrLis = new ArrayList<String>(scanData.length());
while(strTkn.hasMoreTokens())
arrLis.add(strTkn.nextToken());
String merCode = arrLis.toArray(new String[0]).toString();
String mobileNo = arrLis.toArray(new String[1]).toString();*/
String string = scanData;
String[] parts = string.split("#");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556
// Set to the credit acc field
txtCreditAcc.setText(part2);
// Set to the redemption merchant name
lblRedMerName.setText(part1);
}
但是在收到以下错误时
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=180446, result=0, data=null} to activity
这里是scannin qr代码的代码
/**
* Function to start the scan
* @param view - The view object calling the function
*/
public void startScan(View view) {
// Create the scanIntegrator
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
// Start the integrator
scanIntegrator.initiateScan();
// Start the integrator
AlertDialog alertDialog=scanIntegrator.initiateScan();
if(alertDialog==null) {
// Disable the credit account field
txtCreditAcc.setEnabled(false);
// disable the amount button
txtPayAmount.setEnabled(false);
//disable the reference button
txtPayReference.setEnabled(false);
//disable the debit account layout
layDebitAccount.setEnabled(false);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
// Store the scanning result
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
// Check if the result is null,
if (scanningResult != null) {
// get the scan content
String scanContent = scanningResult.getContents();
populateScanData(scanContent);
} else {
generalMethods.showToastMessage(context,"No scan data received!");
}
//Enable the credit account field
txtCreditAcc.setEnabled(true);
// Enable the amount button
txtPayAmount.setEnabled(true);
//Enable the reference button
txtPayReference.setEnabled(true);
//Enable the debit account layout
layDebitAccount.setEnabled(true);
}
请帮助我,好久不见了。感谢!