Here you can find the source of getContactName(Context ctx, String phoneNumber)
public static String getContactName(Context ctx, String phoneNumber)
//package com.java2s; //License from project: Apache License import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract.PhoneLookup; public class Main { public static String getContactName(Context ctx, String phoneNumber) { final ContentResolver cr = ctx.getContentResolver(); final Uri uri = Uri.withAppendedPath( PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = null;//from w w w . j a v a2 s . c om String contactName = phoneNumber; try { cursor = cr.query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor == null) { return null; } if (cursor.moveToFirst()) { contactName = cursor.getString(cursor .getColumnIndex(PhoneLookup.DISPLAY_NAME)); } } finally { if (cursor != null && !cursor.isClosed()) { cursor.close(); } } return contactName; } }