2012-03-06 22 views
0

我已經制作了一個自定義列表,在該列表中,我獲取了所有電話簿聯繫人並使用自定義視圖在我自己的列表中顯示它們。我將所有聯繫人(包括聯繫人ID)保存在一個數組列表中。當我點擊一個列表時,我希望它以默認的Android方式打開該聯繫人的所有細節。請有人告訴我這是否可能。獲取電話簿聯繫人自定義列表中的詳細信息頁面android

我的代碼如下保存在我自己的列表中的聯繫人:

arraylist = new ArrayList<PhoneBookUserEntity>(); 
    Cursor cursor = getContentResolver().query(
      ContactsContract.Contacts.CONTENT_URI, null, null, null, Phone.DISPLAY_NAME + " ASC"); 
    if (cursor.getCount() > 0) 
    { 
     while (cursor.moveToNext()) 
     { 

      PhoneBookUserEntity user = new PhoneBookUserEntity(); 
      // Pick out the ID, and the Display name of the 
      // contact from the current row of the cursor 
      user.setId(cursor.getString(cursor.getColumnIndex(BaseColumns._ID))); 
      user.setPhoneBookName(cursor.getString(cursor.getColumnIndex(
        ContactsContract.Contacts.DISPLAY_NAME))); 

      String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); 
      // if (Boolean.parseBoolean(hasPhone)) { 
      Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ user.getId(), null, null); 
      while (phones.moveToNext()) { 
       user.sePhoneNumber(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));     
      } 
      phones.close(); 
      //} 
      // user.sePhoneNumber(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))); 

      Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + user.getId(), null, null); 
      while (emails.moveToNext()) { 
       // This would allow you get several email addresses 
       user.setEmailAddress(emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA))); 
      } 
      emails.close(); 
      user.setImageURI(getPhotoUri(user.getId())); 
      arraylist.add(user); 
      // Do something with the values you have, 
      // such as print them out or add to a list 
      //System.out.println("Current contact on this iteration is : " + name); 

      // This is where we query for Emails, Addresses etc 
      // Add snippets below into here, depending on what you need 
     } 

    } 
    cursor.close(); 
+1

打開聯繫人卡片BTW,你可以使用聯繫人選擇器來執行類似的功能。退房http://tutorials-android.blogspot.in/2011/11/how-to-call-android-contacts-list.html – Soham 2012-03-06 12:58:32

+0

我有我的自定義列表中的聯繫人。我想打開默認視圖,當有人點擊一個聯繫人,他們會顯示聯繫人的詳細信息。 – SoH 2012-03-06 13:02:09

回答

0

試試這個

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

這應該在android系統

+0

您將獲得androidruntimeexception: 「從Activity上下文外部調用startActivity()需要FLAG_ACTIVITY_NEW_TASK標誌,這真的是你想要的嗎?」 要修復它,請插入: intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); – 2014-09-17 16:48:34

相關問題