@SuppressWarnings("unchecked") private void addPhone(String key, Telephone telephone, Map<String, Object> map) { List<String> collection = (List<String>) map.computeIfAbsent(key, k -> new ArrayList<>()); collection.add(telephone.getText()); }
private void copyPersonData(VCard card, Map<String, Object> contact, TransformerContext context) { // Addresses are lossy: there is no distinction in VCard between business and home addresses if (!card.getAddresses().isEmpty()) { safeSet( "homeAddress", context.transform(LinkedHashMap.class, card.getAddresses().get(0)), contact); } card.getEmails().stream().filter(v -> v.getValue() != null).forEach(v -> addEmail(v, contact)); card.getTelephoneNumbers() .stream() .filter(t -> t.getText() != null) .forEach( telephone -> { for (TelephoneType telephoneType : telephone.getTypes()) { if (TelephoneType.CELL.equals(telephoneType)) { // this could overwrite some numbers since MS contacts only have one mobile contact.put("mobilePhone", telephone.getText()); } else if (TelephoneType.WORK.equals(telephoneType)) { addPhone("businessPhones", telephone, contact); } else { addPhone("homePhones", telephone, contact); } } }); if (card.getBirthday() != null) { safeSet("birthday", card.getBirthday().getText(), contact); } }
private static PhoneNumber convertToGooglePhoneNumber(Telephone vCardTelephone) { PhoneNumber phoneNumber = new PhoneNumber(); phoneNumber.setValue(vCardTelephone.getText()); if (vCardTelephone.getPref() != null && vCardTelephone.getPref() == VCARD_PRIMARY_PREF) { phoneNumber.setMetadata(PRIMARY_FIELD_METADATA); } else { phoneNumber.setMetadata(SECONDARY_FIELD_METADATA); } return phoneNumber; }
r.addProperty(VCARD4.hasTelephone, telephone.getText()); } else { Resource telephoneResource = personModel.createResource(); telephoneResource.addProperty(VCARD4.value, telephone.getText()); for (TelephoneType type : telephone.getTypes()) { for (Resource telTypeResource : getPhoneOrMailTypes(type.getValue(), MAP_OF_PHONE_TYPES))
@Override protected VCardDataType _dataType(Telephone property, VCardVersion version) { if (version == VCardVersion.V4_0) { if (property.getText() != null) { return VCardDataType.TEXT; } if (property.getUri() != null) { return VCardDataType.URI; } } return VCardDataType.TEXT; }
public void readVCF(){ try{ File file = new File(Environment.getExternalStorageDirectory()+"/temp.vcf"); List<VCard> vcards = Ezvcard.parse(file).all(); for (VCard vcard : vcards){ System.out.println("Name: " + vcard.getFormattedName().getValue()); System.out.println("Telephone numbers:"); for (Telephone tel : vcard.getTelephoneNumbers()){ System.out.println(tel.getTypes() + ": " + tel.getText()); } } }catch(Exception e){e.printStackTrace();}}
try{ File file = new File(Environment.getExternalStorageDirectory()+"/vcards.vcf"); List<VCard> vcards = Ezvcard.parse(file).all(); for (VCard vcard : vcards){ System.out.println("Name: " + vcard.getFormattedName().getValue()); System.out.println("Telephone numbers:"); for (Telephone tel : vcard.getTelephoneNumbers()){ System.out.println(tel.getTypes() + ": " + tel.getText()); } } }catch(Exception e){e.printStackTrace();}
@Override protected JCardValue _writeJson(Telephone property) { String text = property.getText(); if (text != null) { return JCardValue.single(text); } TelUri uri = property.getUri(); if (uri != null) { return JCardValue.single(uri.toString()); } return JCardValue.single(""); }
@Override protected void _writeXml(Telephone property, XCardElement parent) { String text = property.getText(); if (text != null) { parent.append(VCardDataType.TEXT, text); return; } TelUri uri = property.getUri(); if (uri != null) { parent.append(VCardDataType.URI, uri.toString()); return; } parent.append(VCardDataType.TEXT, ""); }
String phone = ""; for (Telephone telephone : vcard.getTelephoneNumbers()) { phone += arrayToString(telephone.getTypes().toArray()) + ": " + telephone.getText() + "\n";
@Override protected String _writeText(Telephone property, WriteContext context) { String text = property.getText(); if (text != null) { return escape(text, context); } TelUri uri = property.getUri(); if (uri != null) { if (context.getVersion() == VCardVersion.V4_0) { return uri.toString(); } String ext = uri.getExtension(); String value = (ext == null) ? uri.getNumber() : uri.getNumber() + " x" + ext; return escape(value, context); } return ""; }
String phoneAddr = phone.getText(); boolean internationalPhone = phoneAddr.startsWith("+") || phoneAddr.startsWith("00"); phoneAddr = StringUtil.removeNonNumeric(phoneAddr);