im creating application that can retrieve contact name from number. while i googling , i got this block of code from this post
Getting contact name from number in Android 2.3.4
public static String getContactName(String num, ContentResolver cr) {
Uri u = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI Uri.encode(num));
String[] projection = new String[] { ContactsContract.Contacts.DISPLAY_NAME};
Cursor c = cr.query(u, projection, null, null, null);
try {
if (!c.moveToFirst())
return number;
int index = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
return c.getString(index);
} finally {
if (c != null)
c.close();
}
}
i m successfully able to send Number as String num in the function
but do not know how to store contact name into String. I m not familiar with Cursor in android
if i m wrong please correct me,
help will be appreciated , thanks in Advance
Aucun commentaire:
Enregistrer un commentaire