简体   繁体   English

如何以编程方式从二维码中获取所有数据,如姓名、电子邮件、联系信息?

[英]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.我使用 ZXingScannerView 扫描条码,它只显示条码类型和内容。 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());

在此处输入图片说明

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...
}

You can use the class ResultParser which is included in the zxing library.您可以使用 zxing 库中包含的 ResultParser 类。

...
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();
        ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从联系人列表中获取电子邮件ID,姓名和电话号码 - How to get email id, name and number from contact list 从电话获取一些联系信息数据 - Get some contact info data from phone 查询以1行代码获取电子邮件,联系人姓名和电话号码 - query to get email , contact name , and number in 1 line of code 如何从联系人列表中获取电子邮件地址? - how to get email address from contact list? 从给定的电子邮件ID的地址簿中获取联系人姓名 - Get Contact name from adress book given email id 如何使用uId在Facebook中登录用户的信息,例如电子邮件ID,名称,城市等 - How I can get logged in user's info like email id,name,city etc. in Facebook with uId JSONObject不从QR代码获取数据 - JSONObject don't Get data from QR code 在将电话中的所有联系人填充到列表视图之后,如何获取选定的联系人姓名(将其传递到意图)? - How to get the selected Contact Name (to pass it into an intent) after populating all contacts from phone into a listview? Android二维码如何添加电子名片联系应用? - How to add vCard to contact application via QR code in Android? 如何从代码中获取运行中的OSGi容器信息(名称,版本等)? - How to get running OSGi container info (name, version etc.) from code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM