public static String getContactName(Context context,String number) {
if (TextUtils.isEmpty(number)) {
return null;
}
final ContentResolver resolver = context.getContentResolver();
Uri lookupUri = null;
String[] projection = new String[] { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.DISPLAY_NAME };
Cursor cursor = null;
try {
lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
cursor =resolver.query(lookupUri, projection, null, null, null);
} catch (Exception ex) {
ex.printStackTrace();
try {
lookupUri = Uri.withAppendedPath(android.provider.Contacts.Phones.CONTENT_FILTER_URL,
Uri.encode(number));
cursor = resolver.query(lookupUri, projection, null, null, null);
} catch (Ex
android 根据手机号码获取姓名
最新推荐文章于 2021-09-10 14:12:41 发布
本文介绍如何在Android应用中,利用编程方式从设备的通讯录中查找并获取指定手机号码对应的联系人姓名。详细讲解了相关API的使用和权限申请步骤,帮助开发者实现这一功能。
摘要由CSDN通过智能技术生成