Search code examples
androidandroid-intentqr-codezxing

Extracting results from Android ZXing IntentIntegrator


I am rather new to ZXing and has been exploring their API. I have seen Using ZXing to create an android barcode scanning app and getting scan result when using zxing?

I understand that the details of the scan result is in the string "contents". How do I extract out the details? Looking at the QR generator, http://zxing.appspot.com/generator/ there are many fields like name, company and phone number. How do i extract these details?

I would need something like

//String extractedName = contents.getName() 

Sorry, I am very new to this. I would appreciate if someone can provide me detailed steps. Thanks.

TestActivity

public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
    IntentIntegrator.initiateScan(MenuActivity.this);
}
};


public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
    if (resultCode == RESULT_OK) {
        String contents = intent.getStringExtra("SCAN_RESULT");
        String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
        // Handle successful scan
        //How to get name from contents?

    } else if (resultCode == RESULT_CANCELED) {
        // Handle cancel
    }
}
}

Solution

  • I have successfully extracted it. The scanned results is inside the string 'contents'. Lets say you scanned a code with name and id. The string will contain "name" "id" separated by a whitespace. You can use a for loop to handle it.