0

I am using the following code to get the name of the person from the contacts using his number but I am unable to import PhoneLookup?

 String contact=address;
 Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));  
 Cursor cs= context.getContentResolver().query(uri, new String[]{PhoneLookup.DISPLAY_NAME},PhoneLookup.NUMBER+"='"+address+"'",null,null);

 if(cs.getCount()>0)
 {
     cs.moveToFirst();
     contact=cs.getString(cs.getColumnIndex(PhoneLookup.DISPLAY_NAME));
 }
Franci Penov
  • 74,861
  • 18
  • 132
  • 169
Harinder
  • 11,776
  • 16
  • 70
  • 126

2 Answers2

1

It would help if you show us the exact import statement you are using. Based on ContactsContract.PhoneLookup documentation, your import should be:

import android.provider.ContactsContract.PhoneLookup;

Note also that PhoneLookup is available starting with API level 5 (Android OS 2.0), so if your target is lower than that, you won't be able to find that import.

For 1.6 you can use Contacts.Phones.CONTENT_LOOKUP_URL. Details here - How to look-up a contact's name from their phone number on Android?

Community
  • 1
  • 1
Franci Penov
  • 74,861
  • 18
  • 132
  • 169
1

You might be able to use the deprecated Contacts.Phones if PhoneLookup is unavailable.

Femi
  • 64,273
  • 8
  • 118
  • 148