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 8223737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:49:14+00:00 2026-06-07T14:49:14+00:00

I am looking for a fast & efficient way to query the Android contacts

  • 0

I am looking for a fast & efficient way to query the Android contacts given an email address (basically, given an email address I want to find the matching contact if it exists). Currently I have a double While loop and it’s probably the most inefficient way to accomplish this.

I imagine that I have to do a custom SQLite join query, but I am unfamiliar with how to do this. Any help or pointers from other users would be appreciated!

  • 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-07T14:49:15+00:00Added an answer on June 7, 2026 at 2:49 pm

    After a little bit more research, there is no contract that handles this type of request and you can’t do any custom SQL query on any DB that you don’t own. I have come up with the best solution that I could. Please comment on this and let me know if there is a way to make this perform any better/faster/efficient.

    String incomingEmail = [EMAIL_WE_ARE_SEARCHING_FOR]...
    long contactID = -1;
    //Filter by email address first.
    final String[] emailProjection = new String[]{ContactsContract.CommonDataKinds.Email.CONTACT_ID, 
        ContactsContract.CommonDataKinds.Email.DATA};
    final String emailSelection = ContactsContract.CommonDataKinds.Email.DATA + "=?";
    final String[] emailSelectionArgs = new String[]{incomingEmail};
    final String emailSortOrder = null;
    Cursor emailCursor = context.getContentResolver().query(
            ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
            emailProjection,
            emailSelection, 
            emailSelectionArgs, 
            emailSortOrder);
    if(emailCursor.moveToFirst()){
        contactID = emailCursor.getLong(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.CONTACT_ID)); 
        //Query the specific contact if found.
        final String[] projection = new String[]{ContactsContract.Contacts._ID, 
            ContactsContract.Contacts.DISPLAY_NAME, 
            ContactsContract.Contacts.PHOTO_ID, 
            ContactsContract.Contacts.LOOKUP_KEY};
        final String selection = ContactsContract.Contacts._ID + "=?";
        final String[] selectionArgs = new String[]{String.valueOf(contactID)};
        final String sortOrder = null;
        Cursor contactCursor = context.getContentResolver().query(
                ContactsContract.Contacts.CONTENT_URI,
                projection, 
                selection, 
                selectionArgs, 
                sortOrder);             
        if(contactCursor.moveToFirst()){
            contactName = contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            String photoIDTmp = contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID)); 
            if(photoIDTmp != null){
                photoID = Long.parseLong(photoIDTmp);
            }
            lookupKey = contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
        }
        contactCursor.close();      
    }else{
        emailCursor.close();
        return null;                
    }
    emailCursor.close();
    //Return Contact ID, Contact Name, Contact Photo, Etc.
    

    Thanks!

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

Sidebar

Related Questions

I'm looking for a fast way in C# to find all dates in a
I'm looking for a fast IDE for Linux that has Find&Replace. I'm currently using
I'm looking for a fast & elegant way of converting my object IDs with
I am looking for a fast idea/algorithm letting me to find squares (as mark
I'm looking for a fast, clean, pythonic way to divide a list into exactly
I am looking for a fast way to calculate the size of a folder
Looking for a fast way to limit duplicates to a max of 2 when
I'm looking for a fast way to compute a 3D Morton number. This site
I'm looking for a fast way to turn an associative array in to a
I am looking for fast and good way to add - before every word

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.