2

Want to create a new group in contacts programmatically

I referred the above link but was not able to create group.

Should I create a database such that it should show only the groups which I created.

Do we have any other way in android?

Community
  • 1
  • 1

1 Answers1

2

Here is a function that works for me to create a group:

private void creategroup()
{
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ops.add(ContentProviderOperation
         .newInsert(ContactsContract.Groups.CONTENT_URI)
         .withValue(ContactsContract.Groups._ID, ANY LONG UNIQUE VALUE)
         .withValue(ContactsContract.Groups.TITLE, GROUP NAME).build());

    try {
        getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
    } 
    catch (Exception e) {
        Log.e("Error", e.toString());
    }
}

Hope it will help you.

Rushabh Patel
  • 3,052
  • 4
  • 26
  • 58