[英]Open contact intent DISPLAY_NAME
String exactname = "Joe Blogs"
我一直在寻找一种使用DISPLAY_NAME而不是联系人的_ID直接打开联系人的方法。
编辑:乔博客绝对是一个独特的条目。
从这个答案
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 Blogs的ID? 还是我(希望)错过了什么?
提前致谢。
是的,您需要使用类似以下内容的查询数据库:
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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.