我正在显示联系人列表,并通过调用意图来编辑联系人的上下文菜单。在某些联系人上它可以正常工作,但在其他联系人上,编辑联系人活动是空白有什么想法吗?
这是光标......
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 }
但没有错误消息
答案 0 :(得分: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);