Android examples for Account:Contact Name
fetch Contact Name From Phone Number from Contacts
//package com.java2s; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract.PhoneLookup; public class Main { public static String fetchContactNameFromPhoneNumber(Context context, String phoneNumber) { Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = context.getContentResolver() .query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); String displayName = null; if (cursor.moveToFirst()) { displayName = cursor.getString(cursor .getColumnIndex(PhoneLookup.DISPLAY_NAME)); }/*from w w w . ja v a 2s . co m*/ cursor.close(); return displayName; } }