Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8807547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:23:40+00:00 2026-06-14T02:23:40+00:00

I have developed a simple contacts application and also implemented search using name. But

  • 0

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.

Code to get contacts using name search :
(the search string is obtained from edittext using textchangedlistener)

    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 to get contacts using company search :
(the search string is obtained from edittext using textchangedlistener)

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

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.

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.

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.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:23:41+00:00Added an answer on June 14, 2026 at 2:23 am

    At last I have found the solution.

    The problem was with the contact id returned.

    So in the first case (that is search by name), we have to take ContactsContract.Contacts._ID as the id of the contact.

    and in the second case (that is search by company), since the Uri is different (in this case it is ContactsContract.Data.CONTENT_URI) and also the selection criteria Data.MIMETYPE is Organization.CONTENT_ITEM_TYPE, we have to use Organization.CONTACT_ID

    Similarly when you search using Email, you have to use ContactsContract.CommonDataKinds.Email.CONTACT_ID as the contact id.
    Similarly for other fields.

    Using these Contac ids we can combine the search by name and company. We can remove duplicates in the contact ids using Set concept.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed simple 2D games with AndEngine but now I want to make
I have developed a simple application using SDK(Android: 3.2[API-13]) for, to display Google banners.
I have developed a simple application for study of sql injection where i search
I have developed a simple django application using sqlite3. At first, I wanted to
I have developed an simple android application that says hello. Now i have transferred
I have developed a simple Apache-Axis java web service using Eclipse IDE and now
I have developed a simple location aware iPhone application which is functionally working very
I am new to rails and have developed a simple rails application on my
On Windows 7, VB.NET Express, I have developed a simple Forms application. I don't
I have developed a simple Cake application and after finishing coding of it, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.