代码之家  ›  专栏  ›  技术社区  ›  Pentium10

尝试获取合同组时出现问题~unknown url content://com.android.contacts

  •  1
  • Pentium10  · 技术社区  · 15 年前

    尝试获取时出现问题 合同组

    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"
        );
    

    有:

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

    我得到 ERROR/DatabaseUtils(198): java.lang.IllegalArgumentException: Unknown URL content://com.android.contacts

    2 回复  |  直到 15 年前
        1
  •  1
  •   Pentium10    15 年前

    你用错了 Uri 尝试 ContactsContract.Groups.CONTENT_URI 从我的角度来看,与联系人组合作相当困难,因此请仔细阅读文档

        2
  •  1
  •   AndroidRef.com    15 年前

    是的,错误的URI。以下是按名称查找的示例(从 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));
    ...
    

    杰伊