android.provider.ContactsContract.CommonDataKinds.StructuredName Java Examples

The following examples show how to use android.provider.ContactsContract.CommonDataKinds.StructuredName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectContactModule.java    From react-native-select-contact with MIT License 6 votes vote down vote up
private void addNameData(WritableMap contactData, Cursor cursor) {
    int displayNameIndex = cursor.getColumnIndex(StructuredName.DISPLAY_NAME);
    contactData.putString("name", cursor.getString(displayNameIndex));

    int givenNameColumn = cursor.getColumnIndex(StructuredName.GIVEN_NAME);
    if (givenNameColumn != -1) {
        String givenName = cursor.getString(givenNameColumn);
        contactData.putString("givenName", givenName);
    }

    int familyNameColumn = cursor.getColumnIndex(StructuredName.FAMILY_NAME);
    if (familyNameColumn != -1) {
        String familyName = cursor.getString(cursor.getColumnIndex(StructuredName.FAMILY_NAME));
        contactData.putString("familyName", familyName);
    }

    int middleNameColumn = cursor.getColumnIndex(StructuredName.MIDDLE_NAME);
    if (middleNameColumn != -1) {
        String middleName = cursor.getString(middleNameColumn);
        contactData.putString("middleName", middleName);
    }
}
 
Example #2
Source File: ContactOperations.java    From tindroid with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a contact name. We can take either a full name ("Bob Smith") or separated
 * first-name and last-name ("Bob" and "Smith").
 *
 * @param fullName  The full name of the contact - typically from an edit form
 *                  Can be null if firstName/lastName are specified.
 * @param firstName The first name of the contact - can be null if fullName
 *                  is specified.
 * @param lastName  The last name of the contact - can be null if fullName
 *                  is specified.
 * @return instance of ContactOperations
 */
ContactOperations addName(final String fullName, final String firstName, final String lastName) {
    mValues.clear();
    if (!TextUtils.isEmpty(fullName)) {
        mValues.put(StructuredName.DISPLAY_NAME, fullName);
        mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
    } else {
        if (!TextUtils.isEmpty(firstName)) {
            mValues.put(StructuredName.GIVEN_NAME, firstName);
            mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
        }
        if (!TextUtils.isEmpty(lastName)) {
            mValues.put(StructuredName.FAMILY_NAME, lastName);
            // It's OK to add the same value again.
            mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
        }
    }
    if (mValues.size() > 0) {
        addInsertOp();
    }
    return this;
}
 
Example #3
Source File: ContactOperations.java    From tindroid with Apache License 2.0 6 votes vote down vote up
/**
 * Updates contact's name. The caller can either provide first-name
 * and last-name fields or a full-name field.
 *
 * @param uri               Uri for the existing raw contact to be updated
 * @param existingFirstName the first name stored in provider
 * @param existingLastName  the last name stored in provider
 * @param existingFullName  the full name stored in provider
 * @param firstName         the new first name to store
 * @param lastName          the new last name to store
 * @param fullName          the new full name to store
 * @return instance of ContactOperations
 */
ContactOperations updateName(Uri uri,
                                    String existingFirstName,
                                    String existingLastName,
                                    String existingFullName,
                                    String firstName,
                                    String lastName,
                                    String fullName) {
    mValues.clear();
    if (TextUtils.isEmpty(fullName)) {
        if (!TextUtils.equals(existingFirstName, firstName)) {
            mValues.put(StructuredName.GIVEN_NAME, firstName);
        }
        if (!TextUtils.equals(existingLastName, lastName)) {
            mValues.put(StructuredName.FAMILY_NAME, lastName);
        }
    } else {
        if (!TextUtils.equals(existingFullName, fullName)) {
            mValues.put(StructuredName.DISPLAY_NAME, fullName);
        }
    }
    if (mValues.size() > 0) {
        addUpdateOp(uri);
    }
    return this;
}
 
Example #4
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * Synchronously insert a contact with the designated @name into
 * the ContactsContentProvider.  This code is explained at
 * http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
 */
private void addContact(String name,
                        List<ContentProviderOperation> cpops) {
    final int position = cpops.size();

    // First part of operation.
    cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
              .withValue(RawContacts.ACCOUNT_TYPE,
                         mOps.getAccountType())
              .withValue(RawContacts.ACCOUNT_NAME,
                         mOps.getAccountName())
              .withValue(Contacts.STARRED,
                         1)
              .build());

    // Second part of operation.
    cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
              .withValueBackReference(Data.RAW_CONTACT_ID,
                                      position)
              .withValue(Data.MIMETYPE,
                         StructuredName.CONTENT_ITEM_TYPE)
              .withValue(StructuredName.DISPLAY_NAME,
                         name)
              .build());
}
 
Example #5
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * Synchronously insert a contact with the designated @name into
 * the ContactsContentProvider.  This code is explained at
 * http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
 */
private void addContact(String name,
                        List<ContentProviderOperation> cpops) {
    final int position = cpops.size();

    // First part of operation.
    cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
              .withValue(RawContacts.ACCOUNT_TYPE,
                         mOps.getAccountType())
              .withValue(RawContacts.ACCOUNT_NAME,
                         mOps.getAccountName())
              .withValue(Contacts.STARRED,
                         1)
              .build());

    // Second part of operation.
    cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
              .withValueBackReference(Data.RAW_CONTACT_ID,
                                      position)
              .withValue(Data.MIMETYPE,
                         StructuredName.CONTENT_ITEM_TYPE)
              .withValue(StructuredName.DISPLAY_NAME,
                         name)
              .build());
}
 
Example #6
Source File: DisplayActivity.java    From coursera-android with MIT License 6 votes vote down vote up
private void addRecordToBatchInsertOperation(String name,
		List<ContentProviderOperation> ops) {

	int position = ops.size();

	// First part of operation
	ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
			.withValue(RawContacts.ACCOUNT_TYPE, mType)
			.withValue(RawContacts.ACCOUNT_NAME, mName)
			.withValue(Contacts.STARRED, 1).build());

	// Second part of operation
	ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
			.withValueBackReference(Data.RAW_CONTACT_ID, position)
			.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
			.withValue(StructuredName.DISPLAY_NAME, name).build());

}
 
Example #7
Source File: DisplayActivity.java    From coursera-android with MIT License 6 votes vote down vote up
private void addRecordToBatchInsertOperation(String name,
                                             List<ContentProviderOperation> ops) {

    int position = ops.size();

    // First part of operation
    ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
            .withValue(RawContacts.ACCOUNT_TYPE, mType)
            .withValue(RawContacts.ACCOUNT_NAME, mName)
            .withValue(Contacts.STARRED, 1).build());

    // Second part of operation
    ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, position)
            .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
            .withValue(StructuredName.DISPLAY_NAME, name).build());

}
 
Example #8
Source File: CommonUtils.java    From SmartChart with Apache License 2.0 5 votes vote down vote up
/**
 * 往手机通讯录插入联系人
 *
 * @param ct
 * @param name
 * @param tel
 * @param email
 */
public static void insertContact(Context ct, String name, String tel, String email) {
    ContentValues values = new ContentValues();
    // 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
    Uri rawContactUri = ct.getContentResolver().insert(RawContacts.CONTENT_URI, values);
    long rawContactId = ContentUris.parseId(rawContactUri);
    // 往data表入姓名数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 内容类型
        values.put(StructuredName.GIVEN_NAME, name);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入电话数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Phone.NUMBER, tel);
        values.put(Phone.TYPE, Phone.TYPE_MOBILE);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入Email数据
    if (!TextUtils.isEmpty(email)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Email.DATA, email);
        values.put(Email.TYPE, Email.TYPE_WORK);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
}
 
Example #9
Source File: Name.java    From react-native-paged-contacts with MIT License 5 votes vote down vote up
private void fillFromCursor() {
    namePrefix = getString(StructuredName.PREFIX);
    givenName = getString(StructuredName.GIVEN_NAME);
    middleName = getString(StructuredName.MIDDLE_NAME);
    familyName = getString(StructuredName.FAMILY_NAME);
    nameSuffix = getString(StructuredName.SUFFIX);
    phoneticGivenName = getString(StructuredName.PHONETIC_GIVEN_NAME);
    phoneticMiddleName = getString(StructuredName.PHONETIC_MIDDLE_NAME);
    phoneticFamilyName = getString(StructuredName.PHONETIC_FAMILY_NAME);
}
 
Example #10
Source File: Name.java    From react-native-paged-contacts with MIT License 5 votes vote down vote up
public void addCreationOp(ArrayList<ContentProviderOperation> ops) {
    ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
            .withValue(StructuredName.GIVEN_NAME, givenName)
            .withValue(StructuredName.MIDDLE_NAME, middleName)
            .withValue(StructuredName.FAMILY_NAME, familyName)
            .withValue(StructuredName.PREFIX, namePrefix)
            .withValue(StructuredName.SUFFIX, nameSuffix)
            .withValue(StructuredName.PHONETIC_GIVEN_NAME, phoneticGivenName)
            .withValue(StructuredName.PHONETIC_FAMILY_NAME, phoneticFamilyName)
            .withValue(StructuredName.PHONETIC_MIDDLE_NAME, phoneticMiddleName);

    ops.add(op.build());
}
 
Example #11
Source File: ContactUtils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public static void insertContact(Context context, String name, String phone) {
	// 首先插入空值,再得到rawContactsId ,用于下面插值
	ContentValues values = new ContentValues();
	// insert a null value
	Uri rawContactUri = context.getContentResolver().insert(
			RawContacts.CONTENT_URI, values);
	long rawContactsId = ContentUris.parseId(rawContactUri);

	// 往刚才的空记录中插入姓名
	values.clear();
	// A reference to the _ID that this data belongs to
	values.put(StructuredName.RAW_CONTACT_ID, rawContactsId);
	// "CONTENT_ITEM_TYPE" MIME type used when storing this in data table
	values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
	// The name that should be used to display the contact.
	values.put(StructuredName.DISPLAY_NAME, name);
	// insert the real values
	context.getContentResolver().insert(Data.CONTENT_URI, values);
	// 插入电话
	values.clear();
	values.put(Phone.RAW_CONTACT_ID, rawContactsId);
	// String "Data.MIMETYPE":The MIME type of the item represented by this
	// row
	// String "CONTENT_ITEM_TYPE": MIME type used when storing this in data
	// table.
	values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
	values.put(Phone.NUMBER, phone);
	context.getContentResolver().insert(Data.CONTENT_URI, values);
}
 
Example #12
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * Factory method that creates a ContentValues containing the data
 * associated with a RawContact.
 */
private ContentValues makeRawContactData(String displayName,
                                         Uri rawContactUri) {
    ContentValues values = new ContentValues();
    values.put(Data.RAW_CONTACT_ID,
               ContentUris.parseId(rawContactUri));
    values.put(Data.MIMETYPE,
               StructuredName.CONTENT_ITEM_TYPE);
    values.put(StructuredName.DISPLAY_NAME,
               displayName);
    return values;
}
 
Example #13
Source File: ContactDetailFragment.java    From Contacts with MIT License 4 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args)
{
	String[] mSelectionArgs = { mLookupKey, StructuredName.CONTENT_ITEM_TYPE };
	return new CursorLoader(getActivity(), ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, mSelectionArgs, null);
}