NicoMinsk NicoMinsk - 1 year ago 89
Android Question

Android : Check phone number present in Contact List ? (Phone number retrieve from phone call)

I make a

to receive Phone number of the person who call me

android:name="android.intent.action.PHONE_STATE" />

  1. How to check if the phone number receive is on my contact list ?

    Do you have a tip to know if this phone number exist on contact list with out loading contact list ?

    I don't want more information, just if this phone number exist.

  2. If it's not possible, and I must load contact list, how to do it on

    When I try to do
    , it's not working because I'm on
    and not inside

Thanks for your help

Answer Source
public boolean contactExists(Context context, String number) {
/// number is the phone number
Uri lookupUri = Uri.withAppendedPath(
String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
Cursor cur = context.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);
try {
   if (cur.moveToFirst()) {
      return true;
} finally {
if (cur != null)
return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download