Android-往来:包Group添加到联系人

long groupId = Constant.createGroupId;
		ContentValues values = new ContentValues();
		for(int i=0,len=Constant.contactList.size();i<len;i++)
		{
			values.clear();
				values.put(Data.RAW_CONTACT_ID,
						queryForRawContactId(getContentResolver(), Constant.contactList.get(i).getContactId()));
				values.put(Data.MIMETYPE, GroupMembership.CONTENT_ITEM_TYPE);
				values.put(GroupMembership.GROUP_ROW_ID, groupId);
				getContentResolver().insert(Data.CONTENT_URI, values);
			}
		}

public static long queryForRawContactId(ContentResolver cr, long contactId) {
		Cursor rawContactIdCursor = null;
		long rawContactId = -1;
		try {
			rawContactIdCursor = cr.query(RawContacts.CONTENT_URI,
					new String[] { RawContacts._ID }, RawContacts.CONTACT_ID
							+ "=" + contactId, null, null);
			if (rawContactIdCursor != null && rawContactIdCursor.moveToFirst()) {
				// Just return the first one.
				rawContactId = rawContactIdCursor.getLong(0);
			}
		} finally {
			if (rawContactIdCursor != null) {
				rawContactIdCursor.close();
			}
		}
		return rawContactId;
	}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

你可能感兴趣的:(android)