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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:02:47+00:00 2026-05-27T02:02:47+00:00

ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if (cur.getCount()

  • 0
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0) {
    while (cur.moveToNext()) {
        String id = cur.getString(
        cur.getColumnIndex(ContactsContract.Contacts._ID));
        String name = cur.getString(
        cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

        if (name.equals(selected) && Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {

            Cursor pCur = cr.query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " =?", new String[] {
                id
            }, null);
            finalsend = ContactsContract.CommonDataKinds.Phone.NUMBER;
            while (pCur.moveToNext()) {

            }
            pCur.close();

        }

The code is supposed to look through contacts to find one that matches the “selected” variable which appears to work fine but then it is supposed to switch to the ContactsContract.CommonDataKinds.Phone.CONTENT_URI and find the same contact by matching up the ID’s and give me the phone number saved for that contact.

Every time it returns “Data1”, what am I doing wrong? It’s probably a stupid mistake but any help is 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-05-27T02:02:47+00:00Added an answer on May 27, 2026 at 2:02 am

    Following code snippet is working for me:

    String id , name;
    ContentResolver cr = getContentResolver();
    
         String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
    
         Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,  null, null, null, sortOrder);
    
    
    
          if (cur.getCount() > 0) {
    
    
                while (cur.moveToNext()) {
    
    
    
                    id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
    
                    name = cur.getString( cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    Log.i(tag, "Id is "+ id+"\t Name is"+name);
    
                if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0){                      
    
    
                            Cursor pCur = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
    
                                null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null);
    
    
    
                            while (pCur.moveToNext()) {
    
    
                    // Do something with phones
    
    
    
                           int phNumber = pCur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER);
    
                           String phn = pCur.getString(phNumber);
    
                           Log.i("phn number",  phn);
    
    
    
                        } 
    
                        pCur.close();
    
                    }
    
                    }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ContentResolver cr = getContentResolver(); Cursor cur = cr.query(Uri.parse(content://sms/conversations/), null,null,null, null); is not working why?
i wrote the simple code ContentResolver contentResolver = this.getContentResolver(); Uri uriSMSURI = Uri.parse(content://sms/); //
I would like to read contacts from ContactsContract API which belongs only to Phone
I am wondering if Android's ContentResolver supports using SQL functions over the columns when
I get records from the system by quering a ContentResolver. I maintain the order
What would be the correct way to add DISTINCT and/or GROUPBY to ContentResolver -based
I am having making my edittext field autocomplete for contacts phone numbers. I know
When looking at the Contact Groups on Google Contacts or in the People application
I am trying to read Android device contacts in VCard format using Android Api.
I am trying to get the contacts name and their types but getting this

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.