Question

In the contacts provider I'm building I want to create contacts group and then add the contacts to that group. This is my code for creating new group if one does not exist:

if (groupId == 0) {
        // Sample group doesn't exist yet, so create it
        final ContentValues contentValues = new ContentValues();
        contentValues.put(Groups.ACCOUNT_NAME, account.name);
        contentValues.put(Groups.ACCOUNT_TYPE, account.type);
        contentValues.put(Groups.TITLE, Constants.GROUP_NAME);
        contentValues.put(Groups.GROUP_IS_READ_ONLY, true);

        final Uri newGroupUri = resolver.insert(Groups.CONTENT_URI, contentValues);
        Log.d(TAG, newGroupUri.toString());
        groupId = ContentUris.parseId(newGroupUri);
    }

When I run this on android 4.0 or 4.1 it works, but when I run this on 2.3 newGroupUri is null. What is the problem with 2.3. I tried it both on emulator and phone

Was it helpful?

Solution

contentValues.put(Groups.GROUP_IS_READ_ONLY, true); is only available since api 11

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top