2013-02-03 32 views
2
打開本地聯繫人卡片

是否有人可以解釋我如何打開接觸本地的特定聯繫人的URI如何通過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); 

但它只是打開本地地址簿沒有任何解決

回答

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); 

您可以通過使用contentResolver瀏覽檢索的ContactID:

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); 
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(); 
}