解决方法
一个较短的版本;
你仍然需要这个权限(android.permission.READ_CONTACTS)
你仍然需要这个权限(android.permission.READ_CONTACTS)
public String getPhoneNumber(String name,Context context) { String ret = null; String selection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME+" like'%" + name +"%'"; String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER}; Cursor c = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,projection,selection,null,null); if (c.moveToFirst()) { ret = c.getString(0); } c.close(); if(ret==null) ret = "Unsaved"; return ret; }