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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:01:44+00:00 2026-05-15T11:01:44+00:00

I have a problem in querying phonebook contacts. What I need to do is

  • 0

I have a problem in querying phonebook contacts. What I need to do is get a list of contacts that have both phone and email entered or are of a specific type.

Basically like this:

public static final String SELECTION =
    "("+ContactsContract.Contacts.HAS_PHONE_NUMBER +"='1') OR " + RawContacts.ACCOUNT_TYPE + "='" + Constants.ACCOUNT_TYPE + "'";

Now, the problem is, that RawContacts.ACCOUNT_TYPE does not exist in the ContactsContract.Contacts.CONTENT_URI, which I use with my query. I’m guessing I’d need to join another table, but have no idea how to do so.

Can anyone help me here, please?

  • 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-05-15T11:01:45+00:00Added an answer on May 15, 2026 at 11:01 am

    The best way to read a raw contact along with all the data associated with it is by using the ContactsContract.RawContacts.Entity directory. If the raw contact has data rows, the Entity cursor will contain a row for each data row. If the raw contact has no data rows, the cursor will still contain one row with the raw contact-level information.

    Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
     Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
     Cursor c = getContentResolver().query(entityUri,
              new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1},
              null, null, null);
     try {
         while (c.moveToNext()) {
             String sourceId = c.getString(0);
             if (!c.isNull(1)) {
                 String mimeType = c.getString(2);
                 String data = c.getString(3);
                 //decide here based on mimeType, see comment later
             }
         }
     } finally {
         c.close();
     }
    

    You will have to filter the result based on the mimeType

    For example, if the mimeType is Phone.CONTENT_ITEM_TYPE, then the column DATA1 stores the phone number, but if the data kind is Email.CONTENT_ITEM_TYPE, then DATA1 stores the email address.

    This way you won’t have to use HAS_PHONE_NUMBER as you will directly iterate trough the items.

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

Sidebar

Related Questions

I have a problem for querying records into mysql explanation below The user could
I have problem with fancybox. I want to write a function that will run
i have problem with libhid . i found that there 2 way 4 accessing
I have a problem querying multiple tables in MySQL and am currently at my
I have a Java web service that is querying a SQLite database that contains
The situation I have is that I'm querying MongoDB with a string for a
I have a problem trying to get the count out of the following query:
I have this fragment that demonstrates the problem: <html> <head> <title>height query demo</title> <script
I am currently working on a problem that I have an inelegant solution for.
I have a simple problem when querying the SQL Server 2005 database. I have

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.