List of usage examples for android.provider Contacts KIND_EMAIL
int KIND_EMAIL
To view the source code for android.provider Contacts KIND_EMAIL.
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(); }/* w w w. j a v a 2 s.com*/ 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
/** * This method will save a contact object into the devices contacts database. * //from w w w .j a v a2 s. c om * @param contact the contact to be saved. * @returns true if the contact is successfully saved, false otherwise. */ @Override public boolean save(JSONObject contact) { ContentValues personValues = new ContentValues(); String id = getJsonString(contact, "id"); String name = getJsonString(contact, "displayName"); if (name != null) { personValues.put(Contacts.People.NAME, name); } String note = getJsonString(contact, "note"); if (note != null) { personValues.put(Contacts.People.NOTES, note); } /* STARRED 0 = Contacts, 1 = Favorites */ personValues.put(Contacts.People.STARRED, 0); Uri newPersonUri; // Add new contact if (id == null) { newPersonUri = Contacts.People.createPersonInMyContactsGroup(mApp.getContentResolver(), personValues); } // modify existing contact else { newPersonUri = Uri.withAppendedPath(Contacts.People.CONTENT_URI, id); mApp.getContentResolver().update(newPersonUri, personValues, PEOPLE_ID_EQUALS, new String[] { id }); } if (newPersonUri != null) { // phoneNumbers savePhoneNumbers(contact, newPersonUri); // emails saveEntries(contact, newPersonUri, "emails", Contacts.KIND_EMAIL); // addresses saveAddresses(contact, newPersonUri); // organizations saveOrganizations(contact, newPersonUri); // ims saveEntries(contact, newPersonUri, "ims", Contacts.KIND_IM); // Successfully create a Contact return true; } return false; }
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 w w. ja va 2s.c o m 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 w w w. j a v a 2 s. c o 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; } }