我需要在
Android(API 1.6)甜甜圈中做到这一点
解决方法
尝试这段代码,对我来说很好……
ContentResolver contentResolver = context.getContentResolver();
Uri uri = Uri.withAppendedpath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,Uri.encode(phoneNumber));
String[] projection = new String[] {ContactsContract.PhoneLookup.disPLAY_NAME,ContactsContract.PhoneLookup._ID};
Cursor cursor =
contentResolver.query(
uri,projection,null,null);
if(cursor!=null) {
while(cursor.movetoNext()){
String contactName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup.disPLAY_NAME));
String contactId = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID));
Log.d(LOGTAG,"contactMatch name: " + contactName);
Log.d(LOGTAG,"contactMatch id: " + contactId);
}
cursor.close();
}