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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:08:13+00:00 2026-06-01T16:08:13+00:00

Say i have an edit text and a button. In the edit text you

  • 0

Say i have an edit text and a button. In the edit text you would type a number and then when you hit the button it will either show the contact information or return with the name of that contact.

I have tried all sorts of methods provided with no luck. The one i have successfully gotten the furthest with was the following… But i had no luck returning the name.

Cursor phoneCursor = null;
    contactList = new HashMap<String,String>();

  try{
       Uri uContactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;

      String strProjection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME;

      phoneCursor = getContentResolver().query(uContactsUri, null, null, null, strProjection);
      phoneCursor.moveToFirst();

      String name = "";
      String phoneNumber = "";

       int nameColumn = phoneCursor.getColumnIndex(Phone.DISPLAY_NAME);
       int phoneColumn = phoneCursor.getColumnIndex(Phone.NUMBER);



           phoneCursor.moveToNext();

        }
    }
    catch(Exception e){
        Log.e("[SmsMain] getContactData", e.toString());
    }
    finally{
       if(phoneCursor != null){
          phoneCursor.close();
          phoneCursor = null;
       }
    }
}
  • 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-01T16:08:14+00:00Added an answer on June 1, 2026 at 4:08 pm

    Use the below method to get contact name and if number doesnot exist the instead of name the same number is returned.

    private String getContactNameFromNumber(String number) {
            // define the columns I want the query to return
            String[] projection = new String[] {
                    Contacts.Phones.DISPLAY_NAME,
                    Contacts.Phones.NUMBER };
    
            // encode the phone number and build the filter URI
            Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(number));
    
            // query time
            Cursor c = getContentResolver().query(contactUri, projection, null,
                    null, null);
    
            // if the query returns 1 or more results
            // return the first result
            if (c.moveToFirst()) {
                String name = c.getString(c
                        .getColumnIndex(Contacts.Phones.DISPLAY_NAME));
                return name;
            }
    
            // return the original number if no match was found
            return number;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have something like an ASP.NET ASP:DetailsView to show and edit a single
Lets say i have an application which has three text-fields, and i can type
Say I have two fields in a new or edit form: <%= f.text_field :email
I have editable grid view, If I click on edit in any row say
Lets say have this immutable record type: public class Record { public Record(int x,
Say I have multiple EditTexts in an application. When I click a Button, I
To use as an example: lets say that I have 2 EditText s and
Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say we have the following method: private MyObject foo = new MyObject(); // and
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If

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.