6

嗨,我需要从组织的联系人那里获取公司名称我使用此代码获取组织详细信息

 String orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
            String[] orgWhereParams = new String[]{contactId,
                ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
            Cursor orgCur = cr.query(ContactsContract.Data.CONTENT_URI,
                        null, orgWhere, orgWhereParams, null);
            while (orgCur.moveToNext()) {
                String orgName = orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DATA));
                String title = orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE));
                System.out.println(orgName+title);
                companyname_one.add(orgName);
                System.out.println(companyname_one+"new");

            }
            orgCur.close();

使用此代码,我仅从联系人的最后一个联系人姓名中获取公司名称。如何获取所有联系人的公司详细信息?

4

1 回答 1

8

您已将查询限制为仅返回有关单个联系人的数据:

ContactsContract.Data.CONTACT_ID + " = ? AND …

删除该声明:

String orgWhere = ContactsContract.Data.MIMETYPE + " = ?";
String[] orgWhereParams = new String[]{
    ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
于 2012-08-08T08:24:33.353 回答