开发者

Unable to import PhoneLookup?

开发者 https://www.devze.com 2023-03-27 04:14 出处:网络
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?

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(Phone开发者_如何学运维Lookup.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));
 }


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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消