Why is my work contact not working?

I show a list of contacts and have a context menu for editing a contact, causing an intention. In some contacts it works fine, but in other cases the action "Edit contact" is empty. Any ideas?

Here is the cursor ...

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

Here is the code from my CursorAdapter.getView () ...

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

And here is the code from my 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);

I checked logcat and see

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 }

but no errors

+2
source share
1 answer

Try the following:

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

then

Intent i = new Intent(Intent.ACTION_EDIT);
Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, idContact); 
i.setData(contactUri);
+4
source

All Articles