String exactname = "Joe Blogs"
我搜索了使用DISPLAY_NAME而不是联系人_ID直接打开联系人的方式的高低。
编辑:Joe Blogs绝对是一个独特的条目。
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
intent.setData(uri);
context.startActivity(intent);
在我打开与上述类似的意图之前,我是否必须查询Joe博客的ID?或者我(希望)错过了什么?
提前致谢。
答案 0 :(得分:1)
是的,您需要使用类似的内容查询数据库
Cursor cur = getContentResolver().query(CONTENT_URI, null, DISPLAY_NAME + "=?", new String[] { "Joe Blogs" }, null);
然后使用
检索Cursor
返回的行
if (!cur.moveToFirst()) {
// Then the cursor isn't empty. Get the contact's id.
contactId = cur.getInt(cur.getColumnIndex(CONTACT_ID));
}
这将返回与Cursor
中的第一条记录关联的联系人ID。