views:

721

answers:

2

Problem when trying to get Contracts Group

Uri contacts = ContactsContract.AUTHORITY_URI;
  //Log.v("23",contacts.toString());
  // Make the query.
  Cursor managedCursor = act.managedQuery(contacts, projection, // Which
    // columns
    // to
    // return
    null, // Which rows to return (all rows)
    null // Selection arguments (none)
    // Put the results in ascending order by name
    , ContactsContract.Groups.TITLE + " ASC"
    );

Having:

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

I get ERROR/DatabaseUtils(198): java.lang.IllegalArgumentException: Unknown URL content://com.android.contacts

A: 

You using wrong Uri try ContactsContract.Groups.CONTENT_URI Work with contacts groups is pretty tricky from my point of view so read documentation carefully

Nikolay Ivanov
A: 

Yes, wrong URI. Here's an example to find by name (from http://www.androidref.com/#MapLocation):

//
//  Find contact based on name.
//
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
    "DISPLAY_NAME = '" + NAME + "'", null, null);
if (cursor.moveToFirst()) {
    String contactId =
        cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
...

Jay

AndroidRef.com