簡體   English   中英

開啟聯絡人意向DISPLAY_NAME

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM