首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ContactsContract.Contacts.Entity IllegalArgumentException

ContactsContract.Contacts.Entity IllegalArgumentException
EN

Stack Overflow用户
提问于 2012-09-14 10:38:33
回答 2查看 1.5K关注 0票数 3

我指的是DIRECTORY。为了获得更好的结果,我希望使用ContactsContract.Contacts.Entity URI。APi级别为11,我的设备OS为4.0。我正在使用下面的代码。下面是我在日志中得到的例外。请建议我可以以何种方式使用ContactsContract.Contacts.Entity API。

由: content://com.android.contacts/contacts/entities:URI:引起的

代码语言:javascript
复制
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();
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-14 10:47:02

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

代码语言:javascript
复制
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);

希望这能帮到你。

票数 1
EN

Stack Overflow用户

发布于 2015-11-26 02:58:03

代码语言:javascript
复制
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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12422834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档