Android Context Get getContactDisplayNameByNumber(Context context, String number)

Here you can find the source of getContactDisplayNameByNumber(Context context, String number)

Description

get Contact Display Name By Number

License

Open Source License

Declaration

public static String getContactDisplayNameByNumber(Context context,
            String number) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

import android.provider.BaseColumns;
import android.provider.ContactsContract;

public class Main {
    public static String getContactDisplayNameByNumber(Context context,
            String number) {//from  w w  w . ja v  a2s .  c o m
        Uri uri = Uri.withAppendedPath(
                ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(number));
        String name = "?";

        ContentResolver contentResolver = context.getContentResolver();
        Cursor contactLookup = contentResolver.query(uri,
                new String[] { BaseColumns._ID,
                        ContactsContract.PhoneLookup.DISPLAY_NAME }, null,
                null, null);

        try {
            if (contactLookup != null && contactLookup.getCount() > 0) {
                contactLookup.moveToNext();
                name = contactLookup
                        .getString(contactLookup
                                .getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
                //String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID));
            }
        } finally {
            if (contactLookup != null) {
                contactLookup.close();
            }
        }

        return name;
    }
}

Related

  1. getCertificateFingerprint(Context ctx, String packageName)
  2. getCertificateFromSDCard(Context context)
  3. getChannelNo(Context context)
  4. getConnectedType(Context context)
  5. getConnectedType(Context context)
  6. getContactName(Context ctx, String phoneNumber)
  7. getCornerLightPaint(Context context)
  8. getCornerOffset(Context context)
  9. getCornerPaint(Context context)