Get contact name from just the number
Posted
by
user1190019
on Stack Overflow
See other posts from Stack Overflow
or by user1190019
Published on 2012-04-07T17:26:34Z
Indexed on
2012/04/07
17:28 UTC
Read the original article
Hit count: 605
Say i have an edit text and a button. In the edit text you would type a number and then when you hit the button it will either show the contact information or return with the name of that contact.
I have tried all sorts of methods provided with no luck. The one i have successfully gotten the furthest with was the following... But i had no luck returning the name.
Cursor phoneCursor = null;
contactList = new HashMap<String,String>();
try{
Uri uContactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String strProjection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME;
phoneCursor = getContentResolver().query(uContactsUri, null, null, null, strProjection);
phoneCursor.moveToFirst();
String name = "";
String phoneNumber = "";
int nameColumn = phoneCursor.getColumnIndex(Phone.DISPLAY_NAME);
int phoneColumn = phoneCursor.getColumnIndex(Phone.NUMBER);
phoneCursor.moveToNext();
}
}
catch(Exception e){
Log.e("[SmsMain] getContactData", e.toString());
}
finally{
if(phoneCursor != null){
phoneCursor.close();
phoneCursor = null;
}
}
}
© Stack Overflow or respective owner