How can I get only some particular or selected contacts from my contact list?
-
15-04-2021 - |
题
How can I get only some particular or selected (multiple) contacts from my contact list and make a group with those selected contacts?
Intent intent1 = new Intent(Intent.ACTION_PICK, Contacts.Phones.CONTENT_URI);
startActivityForResult(intent1, PICK_CONTACT_RQCODE_OLD);
startActivity(intent1);
解决方案
Here get some part of code for idea
URI contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst())
{
name = c.getString(c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
no = c.getString(c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
here the Complete Example link
其他提示
I can't give you the full answer. I hope this is useful anyway.
To move your contact in a group you need to update or add a new entry for its group. The group is specified in a raw in the Data table with MIMETYPE = GroupMembership.CONTENT_ITEM_TYPE.
So you need to:
Find the raw_contact_id of your raw_contact
Look for a raw in the data table with
RAWCONTACT_ID=yourid MIMETYPE = GroupMembership.CONTENT_ITEM_TYPE
In case it exists you need to update it otherwise add it
For the way to do those things have a look to the SampleSyncAdapter
: it gives you a lot of clues.