============ Problem Description ============
private void getcontactpeople (String incomingnumber) { mytextview1.settextcolor (Color.Blue); contentresolver contentresolver = getcontentresolver (); cursor cursor = null; String[] projection = new String[] { ContactsContract.Contacts._ID, Contactscontract.contacts.display_name, contactscontract.commondatakinds.phone.number }; cursor = contentresolver.query ( contactscontract.commondatakinds.phone.content_uri, projection, ContactsContract.CommonDataKinds.Phone.NUMBER + "=?", new string[] { incomingNumber }, ""); if (Cursor.getcount () == 0) { mytextview1.settext ("Unknown number:" + incomingnumber); } else if (Cursor.getcount () > 0) { cursor.movetofirst (); string name = cursor.getstring (1 ); mytextview1.settext (name + ":" + incomingnumber); } }
The code is to query the name of the contact in the Address book based on the phone number. Contacts have Incomingnumber number of contacts, but Cursor.getcount () is equal to 0, ask what is the reason, the program should be how to change.
============ Solution 1============
I used your method to write a running program, share the code
http://download.csdn.net/detail/qianqucaicaizi/4276224
Please consult Daniel! Questions about how Android queries your contacts by phone number.