1

Using the Zxing library I am generating QR Code for UPI transactions. Below is the string

 String UPI = "upi://pay?pa=" + payeeAddress + "&pn=" + payeeName
            + "&tr=" + trxnRefId
            + "&tn=" + trxnNote + "&am=" + payeeAmount + "&cu=" + currencyCode+ "&ad="+ str ;

Using Zxing Scanner, how to read values one by one like transaction reference id, amount and payee name.

Present I am getting a full string of UPI using the below code.

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);

      Toast.makeText(this, "Scanned: " + result.getContents(), 
                     Toast.LENGTH_LONG).show();
}
Prakash Reddy
  • 944
  • 10
  • 20

1 Answers1

1

Zxing's result.text gets you a string of the content of the QR Code. you could create a function to get the value that you want.

val trxnRefId = result.text.substringAfter(&tr=).substringBefore(&tn=)
Mateo Hervas
  • 545
  • 1
  • 5
  • 20
  • I can not able to get text object and substringAfter method – Niranjan Reddy Feb 27 '20 at 14:06
  • That is because of the onActivityResult. First get your result.getContents and check what content do you have on it. you should have the result of the scan by zxing as a string. then you can do the `.substringAfter(&tr=).substringBefore(&tn=)` method – Mateo Hervas Feb 27 '20 at 15:04