Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Contacts contract.Contacts.Entity IllegalArgumentException_Android_Android Contacts - Fatal编程技术网

Android Contacts contract.Contacts.Entity IllegalArgumentException

Android Contacts contract.Contacts.Entity IllegalArgumentException,android,android-contacts,Android,Android Contacts,我指的是这个。我想使用ContactsContract.Contacts.Entity URI获得更好的结果。APi级别为11,我的设备操作系统为4.0。我正在使用下面的代码。下面是我在日志中得到的例外。 请告知我使用ContactsContract.Contacts.Entity API的方式 原因:java.lang.IllegalArgumentException:URI:content://com.android.contacts/contacts/entities Cursor pho

我指的是这个。我想使用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();
Cursor=null;
ContentResolver cr=getContentResolver();
Uri phoneuri=Contacts.CONTENT\u Uri;
Uri phone\u Uri=phoneuri.withAppendedPath(phoneuri,Contacts contract.Contacts.Entity.CONTENT\u目录);
phones=cr.query(phone_uri,null,null,null,null);

对于(int i=0;i使用此代码从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);
希望这对你有帮助

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