[英]Open contact intent DISPLAY_NAME
String exactname = "Joe Blogs"
I've searched high and low of a way to directly open the contact using DISPLAY_NAME not the _ID of the contact. 我一直在寻找一种使用DISPLAY_NAME而不是联系人的_ID直接打开联系人的方法。
EDIT: Joe Blogs is definitely a unique entry. 编辑:乔博客绝对是一个独特的条目。
From this answer 从这个答案
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
intent.setData(uri);
context.startActivity(intent);
Do I have to query the ID of Joe Blogs before I can open his contact with an intent similar to the above? 在打开与上述目的相似的联系人之前,是否需要查询Joe Blogs的ID? Or have I (hopefully) missed something?
还是我(希望)错过了什么?
Thanks in advance. 提前致谢。
Yes, you need to query your database with something like, 是的,您需要使用类似以下内容的查询数据库:
Cursor cur = getContentResolver().query(CONTENT_URI, null, DISPLAY_NAME + "=?", new String[] { "Joe Blogs" }, null);
Then retrieve the row returned by the Cursor
with, 然后使用以下命令检索
Cursor
返回的行:
if (!cur.moveToFirst()) {
// Then the cursor isn't empty. Get the contact's id.
contactId = cur.getInt(cur.getColumnIndex(CONTACT_ID));
}
This will return the contact id associated with the first record in the Cursor
. 这将返回与
Cursor
的第一个记录关联的联系人ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.