2

我正在显示联系人列表,并有一个上下文菜单可通过调用意图来编辑联系人。在某些联系人上它工作正常,但在其他人的编辑联系人活动是空白的。有任何想法吗?

这是光标...

 projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone._ID};   
 uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
 cursor = getActivity().getContentResolver().query(uri, projection, null, null,    ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");

这是我的 CursorAdapter.getView() 中的代码...

textView.setText(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)) ;

这是我的 onContextItemSelected 中的代码...

cursor.moveToPosition(position);
String idContact = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(Uri.parse(ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + idContact));
parent.startActivity(i);

我检查了 logcat 并且可以看到

I/ActivityManager(  102): Starting activity: Intent { act=android.intent.action.EDIT dat=content://com.android.contacts/contacts/lookup/23356 cmp=com.android.htccontacts/.ui.EditContactActivity }

但没有错误消息

4

1 回答 1

4

试试这个:

Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor cursor = this.getContentResolver().query(uri, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
long idContact = cursor.getLong(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));

然后

Intent i = new Intent(Intent.ACTION_EDIT);
Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, idContact); 
i.setData(contactUri);
于 2012-11-20T17:14:55.420 回答