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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:30:22+00:00 2026-05-31T18:30:22+00:00

I managed to write add program that upon the user click a button, he

  • 0

I managed to write add program that upon the user click a button, he will be able to retrieve a phone number that will fill an editText box. The problem is that if a contact has multiple numbers, it will always take the top most number.

I have been reading another thread, Getting Number from Contacts Picker, there is an answer, but I don’t get it. As I am new to android programming,
I’ll appreciate if anyone out there could give me step by step instructions.

  • 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-31T18:30:24+00:00Added an answer on May 31, 2026 at 6:30 pm

    First, you may need to query all contact in phone book.

            // Run query
            Uri uri = ContactsContract.Contacts.CONTENT_URI;
            String[] projection = new String[] {
                    ContactsContract.Contacts._ID,
                    ContactsContract.Contacts.DISPLAY_NAME
            };
            String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
            String[] selectionArgs = null;
            String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
    
            // Build adapter with contact entries
            Cursor mCursor = managedQuery(uri, projection, selection, selectionArgs, sortOrder);
            //
            // Bind mCursor to to your Listview
            //
    

    After that, when user select a contact in your list view, you make a second query to get label and number of that contact.

        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {
            mCursor.moveToPosition(position);
            startManagingCursor(mCursor);       
            String contactID = mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts._ID));
    
            Cursor phoneNumCursor = getContentResolver().query(Phone.CONTENT_URI,  
                    null, Phone.CONTACT_ID + "=?", new String[] { contactID }, null); 
    
            phoneNumCursor.moveToFirst();
    
            Vector<String> phoneTypeList = new Vector<String>();
            Vector<String> phoneNumberList = new Vector<String>();
    
            while (!phoneNumCursor.isAfterLast()){
                int type = phoneNumCursor.getInt(phoneNumCursor.getColumnIndex(Phone.TYPE));
                phoneTypeList.add(String.valueOf(Phone.getTypeLabel(getResources(),type,"")));
                phoneNumberList.add(phoneNumCursor.getString(phoneNumCursor.getColumnIndex(Phone.NUMBER)));
                phoneNumCursor.moveToNext();
            }
            //
            // Feel free to show label and phone number of that contact. ^^
            //
    

    Updated:

    Below is an example if you want to use Contact Picker.

        private static final int CONTACT_PICKER_RESULT = 1001;
    
        protected void startContactPicker(){
            Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);  
            startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT); 
        }
    
        @Override  
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
            if (resultCode == RESULT_OK) {  
                switch (requestCode) {  
                case CONTACT_PICKER_RESULT:  
                    Cursor cursor = null;  
                    String phoneNumber = "";  
                    try {  
                        Uri result = data.getData();
                        String id = result.getLastPathSegment();
                        cursor = getContentResolver().query(Phone.CONTENT_URI,  
                                null, Phone.CONTACT_ID + "=?", new String[] { id }, null);  
    
                        int phoneIdx = cursor.getColumnIndex(Phone.DATA);  
                        if (cursor.moveToFirst()) {  
                            while (!cursor.isAfterLast()){
                                phoneNumber = cursor.getString(phoneIdx);
                                //
                                // this will go through all phoneNumber of selected contact.
                                //
    
                                cursor.moveToNext();
                            }   
                        }  
                    } catch (Exception e) {
                    } finally {  
                        if (cursor != null) {  
                            cursor.close();  
                        } 
                        numberView.setText(phoneNumber);
    
                    }  
    
                    break;  
                }        
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a managed library in C# that will act as an
I'd like to write an IE add-on that allows me to find a phone
So far I have managed to write some code that should print the source
I am looking for a managed code library/API or samples that let me write
I would like to write a small piece of program that launches threads, consumes
I'm a limited user, and I need to write an Outlook macro that exposes
I want to write script in SQL that will copy these 2 tables(A,B) to
Can .NET (managed code) read and write to CouchDB? I would like to build
I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
I want to write a unit test for a Django manage.py command that does

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.