Extracting Results from Android ZXing IntentIntegrator

I am new to ZXing and have studied their APIs. Have I seen Using ZXing to create an Android barcode scanner application and getting a scan result when using zxing?

I understand that the details of the scan result are in the "contents" line. How to extract the details? Looking at the QR generator, http://zxing.appspot.com/generator/ there are many fields, such as name, company and phone number. How to extract this data?

I need something like

//String extractedName = contents.getName() 

Sorry, I am not very familiar with this. I would appreciate it if someone could provide me with detailed steps. Thank.

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
    }
}
}
+3
source share
4

. . , . "" "id", . for .

+2

?

QR- - . , , , QR-, .

Wiki ZXing QR-, .

+1

IntentIntegrator

protected void onCreate(Bundle savedInstanceState) { <br>
        super.onCreate(savedInstanceState);<br>
        setContentView(R.layout.activity_main);<br>
        new IntentIntegrator(this).initiateScan();<br>
    }

onActivityResult

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) { <br>
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);<br>
        if (scanResult != null) {<br>
            TextView t = (TextView) findViewById(R.id.textView2);<br>
            String data[] =scanResult.getContents().split("\n");<br>
            for(String k:data){<br>
                t.append(k+"\n");<br>
            }<br>
        }<br>

        // else continue with any other code you need in the method

    }

In this, I got the data using the getContents method and split this data string. Then we added this data to textview2

+1
source

first check the beginning of the line, for example if it starts with (xyxy), like "vcard". Be careful! "vcard" is not the right line!

If it is vCard, I used to split it into parts.

String[] vCardContent = content.split("\n");

The next step is to check each part if it starts with, for example. "N:" nickname "Name"

0
source

All Articles