有人可以解释一下如何为特定联系人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);
但它只打开原生地址簿而没有任何解析
答案 0 :(得分:4)
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
intent.setData(uri);
context.startActivity(intent);
您可以使用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);
答案 1 :(得分:0)
获得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();
}