从自定义列表android获取电话簿联系人详细信息页面

时间:2012-03-06 12:44:15

标签: android contacts

我制作了一个自定义列表,其中我收到所有电话簿联系人,并在我自己的列表中显示自定义视图。我将所有联系人(包含联系人ID)保存在一个arraylist中。当我点击列表时,我希望它以默认的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 个答案:

答案 0 :(得分: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

中打开联系人卡片