android 根據簡訊地址匹配聯絡人姓名
阿新 • • 發佈:2019-02-12
public static String getContactNameByAddr(Context context, String phoneNumber) { Uri personUri = Uri.withAppendedPath( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cur = context.getContentResolver().query(personUri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (cur.moveToFirst()) { int nameIdx = cur.getColumnIndex(PhoneLookup.DISPLAY_NAME); String name = cur.getString(nameIdx); cur.close(); return name; } return phoneNumber; }
解釋:該函式僅需要2個引數:context 和 手機號碼