0
所以我用名片全能王API來獲取vCard格式字符串,這個字符串從出現BEGIN:VCARD到END:VCARD如何通過名片全能王得到字符串名VCF格式字符串的Android
日起實行:VCARD和END:VCARD,如何分別在String中獲取姓名,電話號碼和電子郵件?任何參考我應該怎麼做?
所以我用名片全能王API來獲取vCard格式字符串,這個字符串從出現BEGIN:VCARD到END:VCARD如何通過名片全能王得到字符串名VCF格式字符串的Android
日起實行:VCARD和END:VCARD,如何分別在String中獲取姓名,電話號碼和電子郵件?任何參考我應該怎麼做?
@Override
public void onQRCodeRead(final String text, PointF[] points) {
pointsOverlayView.setPoints(points);
if (text.length() > 0 && !text.isEmpty()) {
resultTextView.setText(text);
qrCodeReaderView.stopCamera();
btnSaveToContact.setVisibility(View.VISIBLE);
btnSaveToContact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkandRequestPermission()) {
VCard vCard = Ezvcard.parse(text).first();
File vcfFile = new File(getActivity().getExternalFilesDir(null), "generated.vcf");
VCardWriter writer = null;
try {
writer = new VCardWriter(vcfFile, vCard.getVersion());
writer.write(vCard);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(vcfFile), "text/x-vcard");
startActivity(i);
}
}
});
model = new Model();
model.setQrText(resultTextView.getText().toString());
model.setDate(getDateTime().toString());
realm.beginTransaction();
realm.copyToRealm(model);
realm.commitTransaction();
}
}
這裏「text」是我的qr碼結果。我在做什麼是做一個.vcf文件和存儲我的qrcode結果。然後VCardWriter將完成其工作..它將分離關於聯繫人應用程序的結果文本。並自動存儲在聯繫人應用程序中。
或者如果你想每個單獨的結果作爲一個字符串。這是你如何得到它。
String name = vCard.getFormattedName().getValue();
String email = vCard.getEmails().get(0).getValue();
String address = vCard.getAddresses().get(0).getStreetAddress() + vCard.getAddresses().get(0).getCountry();
String birthday = vCard.getBirthday().getText().toString();
String telephone = vCard.getTelephoneNumbers().toString();
你需要先添加這種依賴性:
compile 'com.googlecode.ez-vcard:ez-vcard:0.10.0'