List of usage examples for android.provider Contacts KIND_POSTAL
int KIND_POSTAL
To view the source code for android.provider Contacts KIND_POSTAL.
Click Source Link
From source file:android.syncml.pim.vcard.VCardComposer.java
/** Loop append ADR / EMAIL property. */ private void appendContactMethodStr(List<ContactStruct.ContactMethod> contactMList, int version) { HashMap<String, String> emailMap = new HashMap<String, String>(); String joinMark = version == VERSION_VCARD21_INT ? ";" : ","; for (ContactStruct.ContactMethod contactMethod : contactMList) { // same with v2.1 and v3.0 switch (Integer.parseInt(contactMethod.kind)) { case Contacts.KIND_EMAIL: String mailType = "INTERNET"; if (!isNull(contactMethod.data)) { int methodType = new Integer(contactMethod.type).intValue(); if (emailTypeMap.containsKey(methodType)) { mailType = emailTypeMap.get(methodType); } else if (emailTypes.contains(contactMethod.label.toUpperCase())) { mailType = contactMethod.label.toUpperCase(); }/*from w w w .j av a 2s. co m*/ if (emailMap.containsKey(contactMethod.data)) { mailType = emailMap.get(contactMethod.data) + joinMark + mailType; } emailMap.put(contactMethod.data, mailType); } break; case Contacts.KIND_POSTAL: if (!isNull(contactMethod.data)) { mResult.append("ADR;TYPE=POSTAL:").append(foldingString(contactMethod.data, version)) .append(mNewline); } break; default: break; } } for (Map.Entry<String, String> email : emailMap.entrySet()) { if (version == VERSION_VCARD21_INT) { mResult.append("EMAIL;"); } else { mResult.append("EMAIL;TYPE="); } mResult.append(email.getValue()).append(":").append(email.getKey()).append(mNewline); } }
From source file:com.phonegap.ContactAccessorSdk3_4.java
/** * Takes a JSON contact object and loops through the available addresses. If the * address has an id that is not equal to null the address will be updated in the database. * If the id is null then we treat it as a new address. * /*w w w. jav a 2s. c o m*/ * @param contact the contact to extract the addresses from * @param uri the base URI for this contact. */ private void saveAddresses(JSONObject contact, Uri uri) { ContentValues values = new ContentValues(); Uri newUri = Uri.withAppendedPath(uri, Contacts.People.ContactMethods.CONTENT_DIRECTORY); String id = null; try { JSONArray entries = contact.getJSONArray("addresses"); if (entries != null && entries.length() > 0) { JSONObject entry; values.put(Contacts.ContactMethods.KIND, Contacts.KIND_POSTAL); for (int i = 0; i < entries.length(); i++) { entry = entries.getJSONObject(i); id = getJsonString(entry, "id"); String address = getJsonString(entry, "formatted"); if (address != null) { values.put(Contacts.ContactMethods.DATA, address); } else { values.put(Contacts.ContactMethods.DATA, createAddressString(entry)); } if (id == null) { Uri contactUpdate = mApp.getContentResolver().insert(newUri, values); } else { Uri tempUri = Uri.withAppendedPath(newUri, id); mApp.getContentResolver().update(tempUri, values, null, null); } } } } catch (JSONException e) { Log.d(LOG_TAG, "Could not save address = " + e.getMessage()); } }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
static private void addContactMethodsToContactEntry(ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(ContactMethods.CONTENT_URI, null, "person=" + personId, null, null); int kindIndex = c.getColumnIndexOrThrow(ContactMethods.KIND); int dataIndex = c.getColumnIndexOrThrow(ContactMethods.DATA); int auxDataIndex = c.getColumnIndexOrThrow(ContactMethods.AUX_DATA); try {//from w ww . j a v a 2 s . c om while (c.moveToNext()) { int kind = c.getInt(kindIndex); switch (kind) { case Contacts.KIND_IM: { ImAddress address = new ImAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_IM); address.setAddress(c.getString(dataIndex)); Object object = ContactMethods.decodeImProtocol(c.getString(auxDataIndex)); if (object == null) { address.setProtocolPredefined(ImAddress.PROTOCOL_NONE); } else if (object instanceof Integer) { address.setProtocolPredefined(PROVIDER_IM_PROTOCOL_TO_ENTRY_PROTOCOL.get((Integer) object)); } else { if (!(object instanceof String)) { throw new IllegalArgumentException("expected an String, " + object); } address.setProtocolPredefined(ImAddress.PROTOCOL_CUSTOM); address.setProtocolCustom((String) object); } entry.addImAddress(address); break; } case Contacts.KIND_POSTAL: { PostalAddress address = new PostalAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_POSTAL); address.setValue(c.getString(dataIndex)); entry.addPostalAddress(address); break; } case Contacts.KIND_EMAIL: { EmailAddress address = new EmailAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_EMAIL); address.setAddress(c.getString(dataIndex)); entry.addEmailAddress(address); break; } } } } finally { if (c != null) c.close(); } }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
protected static void updateProviderWithContactEntry(String account, Long syncLocalId, ContactEntry entry, ContentProvider provider) throws ParseException { final String name = entry.getTitle(); final String notes = entry.getContent(); final String yomiName = entry.getYomiName(); final String personSyncId = lastItemFromUri(entry.getId()); final String personSyncVersion = lastItemFromUri(entry.getEditUri()); // Store the info about the person ContentValues values = new ContentValues(); values.put(People.NAME, name);/*from ww w .j av a 2s. co m*/ values.put(People.NOTES, notes); values.put(People.PHONETIC_NAME, yomiName); values.put(SyncConstValue._SYNC_ACCOUNT, account); values.put(SyncConstValue._SYNC_ID, personSyncId); values.put(SyncConstValue._SYNC_DIRTY, "0"); values.put(SyncConstValue._SYNC_LOCAL_ID, syncLocalId); values.put(SyncConstValue._SYNC_TIME, personSyncVersion); values.put(SyncConstValue._SYNC_VERSION, personSyncVersion); Uri personUri = provider.insert(People.CONTENT_URI, values); // Store the photo information final boolean photoExistsOnServer = !TextUtils.isEmpty(entry.getLinkPhotoHref()); final String photoVersion = lastItemFromUri(entry.getLinkEditPhotoHref()); values.clear(); values.put(Photos.PERSON_ID, ContentUris.parseId(personUri)); values.put(Photos.EXISTS_ON_SERVER, photoExistsOnServer ? 1 : 0); values.put(SyncConstValue._SYNC_ACCOUNT, account); values.put(SyncConstValue._SYNC_ID, personSyncId); values.put(SyncConstValue._SYNC_DIRTY, 0); values.put(SyncConstValue._SYNC_LOCAL_ID, syncLocalId); values.put(SyncConstValue._SYNC_TIME, photoVersion); values.put(SyncConstValue._SYNC_VERSION, photoVersion); if (provider.insert(Photos.CONTENT_URI, values) == null) { Log.e(TAG, "error inserting photo row, " + values); } // Store each email address for (Object object : entry.getEmailAddresses()) { EmailAddress email = (EmailAddress) object; values.clear(); contactsElementToValues(values, email, ENTRY_TYPE_TO_PROVIDER_EMAIL); values.put(ContactMethods.DATA, email.getAddress()); values.put(ContactMethods.KIND, Contacts.KIND_EMAIL); Uri uri = Uri.withAppendedPath(personUri, People.ContactMethods.CONTENT_DIRECTORY); provider.insert(uri, values); } // Store each postal address for (Object object : entry.getPostalAddresses()) { PostalAddress address = (PostalAddress) object; values.clear(); contactsElementToValues(values, address, ENTRY_TYPE_TO_PROVIDER_POSTAL); values.put(ContactMethods.DATA, address.getValue()); values.put(ContactMethods.KIND, Contacts.KIND_POSTAL); Uri uri = Uri.withAppendedPath(personUri, People.ContactMethods.CONTENT_DIRECTORY); provider.insert(uri, values); } // Store each im address for (Object object : entry.getImAddresses()) { ImAddress address = (ImAddress) object; values.clear(); contactsElementToValues(values, address, ENTRY_TYPE_TO_PROVIDER_IM); values.put(ContactMethods.DATA, address.getAddress()); values.put(ContactMethods.KIND, Contacts.KIND_IM); final byte protocolType = address.getProtocolPredefined(); if (protocolType == ImAddress.PROTOCOL_NONE) { // don't add anything } else if (protocolType == ImAddress.PROTOCOL_CUSTOM) { values.put(ContactMethods.AUX_DATA, ContactMethods.encodeCustomImProtocol(address.getProtocolCustom())); } else { Integer providerProtocolType = ENTRY_IM_PROTOCOL_TO_PROVIDER_PROTOCOL.get(protocolType); if (providerProtocolType == null) { throw new IllegalArgumentException("unknown protocol type, " + protocolType); } values.put(ContactMethods.AUX_DATA, ContactMethods.encodePredefinedImProtocol(providerProtocolType)); } Uri uri = Uri.withAppendedPath(personUri, People.ContactMethods.CONTENT_DIRECTORY); provider.insert(uri, values); } // Store each organization for (Object object : entry.getOrganizations()) { Organization organization = (Organization) object; values.clear(); contactsElementToValues(values, organization, ENTRY_TYPE_TO_PROVIDER_ORGANIZATION); values.put(Organizations.COMPANY, organization.getName()); values.put(Organizations.TITLE, organization.getTitle()); values.put(Organizations.COMPANY, organization.getName()); Uri uri = Uri.withAppendedPath(personUri, Organizations.CONTENT_DIRECTORY); provider.insert(uri, values); } // Store each group for (Object object : entry.getGroups()) { GroupMembershipInfo groupMembershipInfo = (GroupMembershipInfo) object; if (groupMembershipInfo.isDeleted()) { continue; } values.clear(); values.put(GroupMembership.GROUP_SYNC_ACCOUNT, account); values.put(GroupMembership.GROUP_SYNC_ID, lastItemFromUri(groupMembershipInfo.getGroup())); Uri uri = Uri.withAppendedPath(personUri, GroupMembership.CONTENT_DIRECTORY); provider.insert(uri, values); } // Store each phone number for (Object object : entry.getPhoneNumbers()) { PhoneNumber phone = (PhoneNumber) object; values.clear(); contactsElementToValues(values, phone, ENTRY_TYPE_TO_PROVIDER_PHONE); values.put(People.Phones.NUMBER, phone.getPhoneNumber()); values.put(People.Phones.LABEL, phone.getLabel()); Uri uri = Uri.withAppendedPath(personUri, People.Phones.CONTENT_DIRECTORY); provider.insert(uri, values); } // Store the extended properties for (Object object : entry.getExtendedProperties()) { ExtendedProperty extendedProperty = (ExtendedProperty) object; if (!"android".equals(extendedProperty.getName())) { continue; } JSONObject jsonObject = null; try { jsonObject = new JSONObject(extendedProperty.getXmlBlob()); } catch (JSONException e) { Log.w(TAG, "error parsing the android extended property, dropping, entry is " + entry.toString()); continue; } Iterator jsonIterator = jsonObject.keys(); while (jsonIterator.hasNext()) { String key = (String) jsonIterator.next(); values.clear(); values.put(Extensions.NAME, key); try { values.put(Extensions.VALUE, jsonObject.getString(key)); } catch (JSONException e) { // this should never happen, since we just got the key from the iterator } Uri uri = Uri.withAppendedPath(personUri, People.Extensions.CONTENT_DIRECTORY); if (null == provider.insert(uri, values)) { Log.e(TAG, "Error inserting extension into provider, uri " + uri + ", values " + values); } } break; } }