views:

308

answers:

1

Problem 1.

I have this class:

public class ContactGroups {

    // Form an array specifying which columns to return.
    String[] projection = new String[] { Contacts.Groups._ID,
            Contacts.Groups._COUNT, Contacts.Groups.NAME, Contacts.Groups.NOTES };

    public Cursor getList(Activity act) {

        Uri contacts = Contacts.Groups.CONTENT_URI;
             // using the debugger code kills here
            Cursor managedCursor = act.managedQuery(contacts, projection, 
                null, 
                null 
             , null
                );
        return managedCursor;
    }

    public ArrayList<String> getColumnData(Cursor cur) {
        ArrayList<String> aa = new ArrayList<String>();
        if (cur.moveToFirst()) {

            String name;
            String notes;
            int nameColumn = cur.getColumnIndex(Contacts.Groups.NAME);
            int notesColumn = cur.getColumnIndex(Contacts.Groups.NOTES);

            do {
                // Get the field values
                name = cur.getString(nameColumn);
                notes = cur.getString(notesColumn);
                aa.add(name);
                // Do something with the values.

            } while (cur.moveToNext());

        }
        return aa;
    }

}

I am calling this as:

ContactGroups mGrp= new ContactGroups();
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,mGrp.getColumnData(mGrp.getList(this)));
myListView.setAdapter(aa);

And having:

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>

I get a Source not found error and a Logcat error

ERROR/DatabaseUtils(617): java.lang.IllegalArgumentException: Invalid column _count

Does somebody know why?

Problem 2.

Where do I create manually contact groups?

A: 

Contacts.Groups is deprecated. You should use ContactsContract.

And the constants you may be interested in are under ContactsContract.Groups, especially SUMMARY_COUNT for the count

ccheneson
I use sdk1.6 api level 4. They don't exists yet on it.
Pentium10