String number = "0877777777";
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{ PhoneLookup._ID, PhoneLookup.DISPLAY_NAME };
Cursor cur = getContentresolver().query(uri, projection, null, null, null);
if (cur != null) {
while (cur.moveToNext()) {
Long id = cur.getLong(0);
String name = cur.getString(1);
Log.d("My Contacts", "found: " + id + " - " + name);
}
cur.close();
}
UPDATE
要在股票联系人应用程序中打开联系人的个人资料,您需要首先获取联系人的CONTACT_ID ,然后在Intent中将其用于外部应用程序:
String number = "0877777777";
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{ PhoneLookup._ID };
Cursor cur = getContentresolver().query(uri, projection, null, null, null);
// if other contacts have that phone as well, we simply take the first contact found.
if (cur != null && cur.moveToNext()) {
Long id = cur.getLong(0);
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(id));
intent.setData(contactUri);
context.startActivity(intent);
cur.close();
}