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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:43:45+00:00 2026-06-07T05:43:45+00:00

I am trying to make an application on android that takes the contact name

  • 0

I am trying to make an application on android that takes the contact name as a string input and returns his phone number if that contact exists in the phone book…

I tried searching around but there is no clear tutorial as to how to do exactly that

input:contact name
outputs:the phone number

please help

      Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null); 


     while (cursor.moveToNext()) { 
         String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

         if(name.equalsIgnoreCase(token3)) {

        try{     ContentResolver cr = context.getContentResolver();
             Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { ContactsContract.CommonDataKinds.Phone._ID}, null);
             String lname = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

         Toast.makeText(context, "number is "+lname, Toast.LENGTH_LONG).show();
        }catch (Exception e) {
            // TODO: handle exception
        }

         }
           } 

it’s what I have so far. the piece of code in the try catch block always crashes.

  • 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-07T05:43:47+00:00Added an answer on June 7, 2026 at 5:43 am

    I wrote this method eventually to solve my problem

    public String get_Number(String name,Context context)
    
    {String number="";
    
    
    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection    = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                    ContactsContract.CommonDataKinds.Phone.NUMBER};
    
    Cursor people = context.getContentResolver().query(uri, projection, null, null, null);
    
    int indexName = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
    int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
    
    people.moveToFirst();
    do {
        String Name   = people.getString(indexName);
        String Number = people.getString(indexNumber);
        if(Name.equalsIgnoreCase(name)){return Number.replace("-", "");}
        // Do work...
    } while (people.moveToNext());
    
    
    if(!number.equalsIgnoreCase("")){return number.replace("-", "");}
    else return number;
    }
    

    it may not be very efficient but hey it works

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

Sidebar

Related Questions

im trying to make an android application that whenever a user conncects to a
I'm trying to make an OAuth 2.0 Provider and an Android application that is
I'm trying to make an Android application that will display a map of a
I am trying to make an Android/ Java application that needs to connect to
I have an html/javascript/css project that i am trying to make an Android application
I am trying to make an application for android that is based on IPAD
So im trying to make an adroid application that draws a stream of circles
I'm trying to make application for tablet with Android 2.3 with this kind of
I am trying to make simple notepad application for learning android development. So, to
I'm trying to make an application that changes the UI every minute, but I'm

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.