类android.provider.ContactsContract.CommonDataKinds.StructuredName源码实例Demo

下面列出了怎么用android.provider.ContactsContract.CommonDataKinds.StructuredName的API类实例代码及写法,或者点击链接到github查看源代码。

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);
    }
}
 
源代码2 项目: tindroid   文件: ContactOperations.java
/**
 * 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;
}
 
源代码3 项目: tindroid   文件: ContactOperations.java
/**
 * 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;
}
 
源代码4 项目: mobilecloud-15   文件: InsertContactsCommand.java
/**
 * 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());
}
 
源代码5 项目: mobilecloud-15   文件: InsertContactsCommand.java
/**
 * 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());
}
 
源代码6 项目: coursera-android   文件: DisplayActivity.java
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());

}
 
源代码7 项目: coursera-android   文件: DisplayActivity.java
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());

}
 
源代码8 项目: SmartChart   文件: CommonUtils.java
/**
 * 往手机通讯录插入联系人
 *
 * @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);
    }
}
 
源代码9 项目: react-native-paged-contacts   文件: Name.java
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);
}
 
源代码10 项目: react-native-paged-contacts   文件: Name.java
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());
}
 
源代码11 项目: BigApp_Discuz_Android   文件: ContactUtils.java
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);
}
 
源代码12 项目: mobilecloud-15   文件: InsertContactsCommand.java
/**
 * 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;
}
 
源代码13 项目: Contacts   文件: ContactDetailFragment.java
@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);
}
 
 类所在包
 类方法
 同包方法