Praful Korat
Praful Korat

Reputation: 428

How to get all data from Qr code like Name, Email, Contact info programetically?

I use ZXingScannerView for scan Barcode and it shows only barcode type and content. But I want to extract full data from content like name, birth date, etc...

Scan result shown in the below image, its result of business card scan, it gives mixed content how can I extract all fields?

Here Only two methods for this

How i separate all field like name, email, number, etc..


String format= rawResult.getBarcodeFormat().toString());
String Content=rawResult.getText());

enter image description here

Upvotes: 0

Views: 2587

Answers (2)

Michael
Michael

Reputation: 2496

You can use the class ResultParser which is included in the zxing library.

...
import com.google.zxing.Result;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.ResultParser;
...
ParsedResult parsedResult = ResultParser.parseResult(rawResult);
switch (parsedResult.getType()) {
    case ADDRESSBOOK:
        AddressBookParsedResult addressResult = (AddressBookParsedResult) parsedResult;
        String[] addresses = addressResult.getAddresses();
        String[] phoneNumbers = addressResult.getPhoneNumbers();
        String[] emails = addressResult.getEmails();
        ...

Upvotes: 0

Bill Horvath
Bill Horvath

Reputation: 1717

You need to split the content by lines first, then decide how to deal with each line.

String[] lines = content.split("\n");
for (String line : lines){
    String[] typeAndValue = line.split("[:;]", 2);
    String type = typeAndValue[0];
    String value = typeAndValue[1];
    // ...do the voodoo that you do...
}

Upvotes: 1

Related Questions