Android Context Get getContactName(Context ctx, String phoneNumber)

Here you can find the source of getContactName(Context ctx, String phoneNumber)

Description

get Contact Name

License

Apache License

Declaration

public static String getContactName(Context ctx, String phoneNumber) 

Method Source Code

//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;
    }
}

Related

  1. getCertificateFromSDCard(Context context)
  2. getChannelNo(Context context)
  3. getConnectedType(Context context)
  4. getConnectedType(Context context)
  5. getContactDisplayNameByNumber(Context context, String number)
  6. getCornerLightPaint(Context context)
  7. getCornerOffset(Context context)
  8. getCornerPaint(Context context)
  9. getCornerRadius(Context context)