Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I make a BroadcastReceiver to receive Phone number of the person who call me

<intent-filter>
<action
    android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
  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 BroadcastReceiver ?
    When I try to do getContentResolver, it's not working because I'm on BroadcastReceiver and not inside Activity...

Thanks for your help

like image 518
NicoMinsk Avatar asked Aug 17 '10 18:08

NicoMinsk


People also ask

How can I get someone's phone number?

Whitepages is an easy-to-use online people search, background check search, and tenant screening tool. With the People Search feature, you can find a phone number of a person by entering their name and location. While it only works to find people in the US, Whitepages helps find landline and cell phone numbers.

How do I check what my phone number is?

On Android the most common path to finding your number is: Settings > About phone/device > Status/phone identity > Network. This slightly differs on Apple devices, where you can follow the path of Settings > Phone > My Number.


1 Answers

public boolean contactExists(Context context, String number) {
    // number is the phone number
    Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
    Cursor cur = context.getContentResolver().query(lookupUri, mPhoneNumberProjection, null, null, null);
    try {
        if (cur.moveToFirst()) {
            cur.close();
            return true;
        }
    } finally {
        if (cur != null)
            cur.close();
        }
   }

   return false;
}
like image 189
ekawas Avatar answered Oct 04 '22 13:10

ekawas