Reputation: 33
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?
Upvotes: 2
Views: 1741
Reputation: 3080
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.
Upvotes: 2