4

有人可以解释一下如何为特定联系人 URi 打开联系人本机

我设法通过以下方式解析联系人URI:

Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(displayName));

然后我尝试这样做:

     Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
     intent.putExtra(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, "555");
     context.startActivity(intent);

但它只是打开本机通讯簿而没有任何解析

4

2 回答 2

3
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
intent.setData(uri);
context.startActivity(intent);

您可以通过使用以下方式浏览来检索contactId contentResolver

id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
name = cur.getString( cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Log.d(tag, "Id: "+ id+"\t Name: "+name);
于 2013-02-03T15:59:12.227 回答
1

在您获得cursor联系人和特定联系人的索引后,获取Uri并启动活动,其意图ACTION_VIEW如下:

cursor.moveToPosition(position); // or cursor.moveToFirst() if single contact was selected.
long id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(ContactsContract.Contacts.getLookupUri(id, lookupKey));
try {
    context.startActivity(intent);
} catch (Exception e) {
    e.printStackTrace();
}
于 2017-07-15T13:28:58.337 回答