【问题标题】:ContactsContract.Contacts.Entity IllegalArgumentExceptionContactsContract.Contacts.Entity IllegalArgumentException
【发布时间】:2012-09-14 10:38:33
【问题描述】:

我指的是https://developer.android.com/reference/android/provider/ContactsContract.Contacts.Entity.html#CONTENT_DIRECTORY。我想使用 ContactsContract.Contacts.Entity URI 来获得更好的结果。 APi 级别为 11,我的设备操作系统为 4.0。我正在使用下面的代码。下面是我在日志中遇到的异常。 请告知我可以通过哪种方式使用 ContactsContract.Contacts.Entity API。

原因:java.lang.IllegalArgumentException:URI:content://com.android.contacts/contacts/entities

Cursor phones=null;
ContentResolver cr = getContentResolver();     
Uri phoneuri = Contacts.CONTENT_URI;
Uri phone_uri =  phoneuri.withAppendedPath(phoneuri,  ContactsContract.Contacts.Entity.CONTENT_DIRECTORY);
phones = cr.query(phone_uri, null, null, null, null);
for(int i=0;i<phones.getCount();i++)
{
    Log.e("int","f_name="+phones.getColumnName(i));
}
phones.close();

【问题讨论】:

    标签: android android-contacts


    【解决方案1】:

    使用此代码从 android 获取所有联系人:

    ContentResolver cr = getContentResolver();
    String[] projection = { ContactsContract.Contacts.DISPLAY_NAME,
                            ContactsContract.Contacts._ID };
    Cursor contacts = cr.query(ContactsContract.Contacts.CONTENT_URI,
                                    projection, null, null, "UPPER("
                                    + ContactsContract.Contacts.DISPLAY_NAME + ") ASC");
    startManagingCursor(contacts);
    

    希望这会对你有所帮助。

    【讨论】:

      【解决方案2】:
      int contactId = 111;//one contact's id
      Uri contactsUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
      Uri entityUri = Uri.withAppendedPath(contactsUri, Contacts.Entity.CONTENT_DIRECTORY);
      Cursor c = getContentResolver().query(entityUri,
               null,null, null, null);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-10
        相关资源
        最近更新 更多