Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch contacts using name as well as company (like in default android 2.3.3 contacts app)
    primarykey
    data
    text
    <p>I have developed a simple contacts application and also implemented search using name. But now I want to search using both name and company (just like how default android contacts app does). I am able to search separately using company but couldn't get other contact information because the contact id returned is different...I have pasted my code below.</p> <p><strong>Code to get contacts using name search :</strong> <em>(the search string is obtained from edittext using textchangedlistener)</em></p> <pre><code> private Cursor getContactsByName(String temp) { Uri uri = ContactsContract.Contacts.CONTENT_URI; String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, }; String selection = ContactsContract.Contacts.DISPLAY_NAME + " like '" + temp + "%'"; String[] selectionArgs = null; String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; return managedQuery(uri, projection, selection, selectionArgs, sortOrder); } </code></pre> <p><strong>Code to get contacts using company search :</strong> <em>(the search string is obtained from edittext using textchangedlistener)</em></p> <pre><code> private Cursor getContactsByCompany(String temp) { Uri uri = ContactsContract.Data.CONTENT_URI; String[] proj = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, Organization.COMPANY}; String selection3 = Data.MIMETYPE + "='" + Organization.CONTENT_ITEM_TYPE + "' AND " + Organization.COMPANY + " like '" + temp + "%'"; String[] selectionArgs = null; String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; return managedQuery(uri, proj, selection3, selectionArgs, sortOrder); } </code></pre> <p>In the first case (i.e. name search), I am getting a cursor with information like contact id, name. Using contact id, I display information of the contact like photo, email in view contact page.</p> <p>In the second case (i.e. company search), I get a cursor with information contact id, name and company. But here the contact id returned for the same contacts is different from that returned in the first case. So I cannot get other info of the contact like photo, email etc using this contact id. </p> <p>If the contact id of a contact is same in both case 1 and case 2, I can integrate the two searches into one by removing duplicates. But this is not the case here.</p> <p>So my question is how can I find contact information from the second case if contact id is different and how can i combine the two searches?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload