【问题标题】:Get Phonebook contacts Detail page from custom list android从自定义列表android获取电话簿联系人详细信息页面
【发布时间】:2012-03-06 21:34:57
【问题描述】:

我创建了一个自定义列表,其中获取了所有电话簿联系人,并在我自己的列表中以自定义视图显示它们。我将所有联系人(包括联系人 ID)保存在数组列表中。当我单击一个列表时,我希望它以默认的 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();

【问题讨论】:

  • 顺便说一句,您可以使用联系人选择器来执行类似的功能。查看tutorials-android.blogspot.in/2011/11/…
  • 我的自定义列表中有联系人。当有人点击联系人并显示联系人详细信息时,我想打开默认视图。

标签: android contacts


【解决方案1】:

试试这个

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 中打开联系人卡片

【讨论】:

  • 你会得到 androidruntimeexception:“从 Activity 上下文之外调用 startActivity() 需要 FLAG_ACTIVITY_NEW_TASK 标志。这真的是你想要的吗?”要修复它,请插入:intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
猜你喜欢
  • 1970-01-01
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多