Pergunta

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);
Foi útil?

Solução

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

Outras dicas

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:

  1. Find the raw_contact_id of your raw_contact

  2. Look for a raw in the data table with RAWCONTACT_ID=yourid MIMETYPE = GroupMembership.CONTENT_ITEM_TYPE

  3. 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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top