fetch Contact Id From Phone Number from Contacts - Android Account

Android examples for Account:Contact ID

Description

fetch Contact Id From Phone Number from Contacts

Demo Code


//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 long fetchContactIdFromPhoneNumber(Context context,
            String phoneNumber) {
        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(phoneNumber));
        Cursor cursor = context.getContentResolver().query(uri,
                new String[] { PhoneLookup._ID }, null, null, null);

        long id = 0L;
        if (cursor.moveToFirst()) {
            id = cursor.getLong(cursor.getColumnIndex(PhoneLookup._ID));
        }/*www  . ja va2s .c o  m*/
        cursor.close();

        return id;

    }
}

Related Tutorials