Vinzee Vinzee - 1 year ago 73
Android Question

Contact Not Found on Intent with Contact Application

What I want is to go to the profile of the contact in the Contact application when I press an item on a list :

viewHolder.swipeLayout.setOnLongClickListener(new SwipeLayout.LongClickListener() {

public void onLongPress(View view) {

Intent goContactIntent = new Intent(Intent.ACTION_VIEW);
String contactID = mData.get(position).getId();
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactID);
Toast.makeText(mContext,"uri : "+uri, Toast.LENGTH_LONG).show();

I retrieve the list of all the contacts (name, phone number and ID) with the getContacts() when the application starts. At least the names and phone numbers work.

public ArrayList<Contact> getContacts() {
//Adress of the table in the database
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;

//Retrieve data
String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID};

//Initialize the cursor
Cursor people = getContentResolver().query(uri, projection, null, null, null);

int indexName = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int indexId = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID);

ArrayList<Contact> contacts = new ArrayList<Contact>();

//Shaping data
do {
String name = people.getString(indexName);
String number = people.getString(indexNumber);
String contactid = people.getString(indexId);

Contact contact1 = new Contact();



} while (people.moveToNext());

return contacts;

In the onLongPress function, when I toast, I get URIs like : "content://"
and a toast (I didn't implement) : "Contact not found"

I know how to go to the Contact application (I have code that works for that), but I can't go on a specific contact profile.

I have already looked over many solutions on the Internet including Stackoverflow but none of these solutions have worked...

Answer Source

The id you passed in the URI is wrong i think. I am using ContactsContract.RawContacts.CONTACT_ID and it works absolutely fine

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download