android - How to get contact id by phone number -


i query phone's calllog listview. when user long clicks item, dialog comes options, including "view contact". able view contact intent needs contact id. problem not see right contact. click on peter, , peter's contact sheet comes up. click on sarah, , jason's contact sheet comes up.

i must have been using code wrong way. please help.

contentresolver contentresolver = getcontentresolver();  uri uri = uri.withappendedpath(contactscontract.phonelookup.content_filter_uri, uri.encode(phone));  cursor cursor =  contentresolver.query(uri, new string[] {phonelookup.display_name, phonelookup._id}, null, null, null);  if(cursor!=null) {       while(cursor.movetonext())       {         string contactname = cursor.getstring(cursor.getcolumnindexorthrow(phonelookup.display_name));         contactid2 = cursor.getstring(cursor.getcolumnindexorthrow(phonelookup._id));         }         cursor.close(); }  intent intent_contacts = new intent(intent.action_view, uri.parse("content://contacts/people/" + contactid2));  startactivity(intent_contacts); 

maybe need not phonelookup._id, other id.

i tried felipe's answer here, same happens.

edit:

  • on htc desire hd (2.3.5) proper contacts in 99% of cases.
  • on zte blade (2.2) proper contacts in 60% of cases.
  • on samsung galaxy ace (2.3.3) proper contacts in 5% of cases.

what hell going on???

after digging myself theme, found sven's on googlegroups. problem was using depracated intent. read through many pages on developer site, must have missed somehow.

i post full code.

contactid26 = null;                  contentresolver contentresolver = getcontentresolver();                  uri uri = uri.withappendedpath(contactscontract.phonelookup.content_filter_uri, uri.encode(phonenumintolist));                  cursor cursor =                      contentresolver.query(                         uri,                          new string[] {phonelookup.display_name, phonelookup._id},                          null,                          null,                          null);                  if(cursor!=null) {                   while(cursor.movetonext()){                     string contactname = cursor.getstring(cursor.getcolumnindexorthrow(phonelookup.display_name));                    contactid26 = cursor.getstring(cursor.getcolumnindexorthrow(phonelookup._id));                    }                   cursor.close();                 }                 if (contactid26 == null)                     {                         toast.maketext(detailedcallhistory.this, "no contact found associated number", toast.length_short).show();                     }                     else                     {                         intent intent_contacts = new intent(intent.action_view, uri.withappendedpath(contactscontract.contacts.content_uri, string.valueof(contactid26)));                         //intent intent_contacts = new intent(intent.action_view, uri.parse("content://contacts/people/" + contactid26));                         startactivity(intent_contacts);                     } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -