Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the organisation details from contact in android?

hi i need to get the company name from the contact from the organisation i use this code to get the organisation details

 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 do i get the company detail of all contact?

like image 558
Ramz Avatar asked Aug 08 '12 08:08

Ramz


1 Answers

You have restricted the query to return data about single contact only:

ContactsContract.Data.CONTACT_ID + " = ? AND …

Remove that statement:

String orgWhere = ContactsContract.Data.MIMETYPE + " = ?";
String[] orgWhereParams = new String[]{
    ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
like image 198
StenaviN Avatar answered Oct 22 '22 00:10

StenaviN