Get information about an organization from a contact in android?

I need to get the company name from the contact from the organization, I use this code to get the details of the organization

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

using this code, I get only the company name from the last contact name from the contact. How can I get company information of all contacts?

+5
source share
1 answer

You have limited the request to return data for only one contact:

ContactsContract.Data.CONTACT_ID + " = ? AND …

Remove this statement:

String orgWhere = ContactsContract.Data.MIMETYPE + " = ?";
String[] orgWhereParams = new String[]{
    ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
+7
source

All Articles