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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:07:32+00:00 2026-06-09T02:07:32+00:00

I’m trying to allows user to insert their number using a contact picker in

  • 0

I’m trying to allows user to insert their number using a contact picker in android. I am currently using the example from post 2 in Getting Number from Contacts Picker the contact picker appears and so but when i select a contact the contact number doesn’t affect inside my edittext.
There’s no logcat error or whatsoever.

My code:

public void doLaunchContactPicker(View view) {  
    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 = "";
            List<String> allNumbers = new ArrayList<String>();
            int phoneIdx = 0;
            try {  
                Uri result = data.getData();  
                String id = result.getLastPathSegment();  
                cursor = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id }, null);  
                phoneIdx = cursor.getColumnIndex(Phone.DATA);
                if (cursor.moveToFirst()) {
                    while (cursor.isAfterLast() == false) {
                        phoneNumber = cursor.getString(phoneIdx);
                        allNumbers.add(phoneNumber);
                        cursor.moveToNext();
                    }
                } else {
                    //no results actions
                }  
            } catch (Exception e) {  
               //error actions
            } finally {  
                if (cursor != null) {  
                    cursor.close();
                }
                final EditText phoneInput = (EditText) findViewById(R.id.mobileno);

                final CharSequence[] items = allNumbers.toArray(new String[allNumbers.size()]);
                AlertDialog.Builder builder = new AlertDialog.Builder(SIMMessageSenderActivity.this);
                builder.setTitle("Choose a number");
                builder.setItems(items, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        String selectedNumber = items[item].toString();
                        selectedNumber = selectedNumber.replace("-", "");
                        phoneInput.setText(selectedNumber);
                    }
                });
                AlertDialog alert = builder.create();
                if(allNumbers.size() > 1) {
                    alert.show();
                } else {
                    String selectedNumber = phoneNumber.toString();
                    selectedNumber = selectedNumber.replace("-", "");

                    phoneInput.setText(selectedNumber);
                }

                if (phoneNumber.length() == 0) {  
                    //no numbers found actions  
                }  
            }  
            break;  
        }  
    } else {
       //activity result error actions
    }  
}
  • 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-09T02:07:33+00:00Added an answer on June 9, 2026 at 2:07 am

    This below code is one I am using and it is working pretty fine for me. Try this one.

      if((requestCode == PICK_CONTACT) && (resultCode == RESULT_OK))
                { 
                     if (data != null) {
                         Uri contactData = data.getData();
    
                         try {
    
                             String id = contactData.getLastPathSegment();
                            String[] columns = {Phone.DATA,Phone.DISPLAY_NAME};
                             Cursor phoneCur = getContentResolver()
                                     .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                            columns ,
                                             ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                                     + " = ?", new String[] { id },
                                             null);
    
                             final ArrayList<String> phonesList = new ArrayList<String>();
                             String Name = null ;
                             if(phoneCur.moveToFirst())
                             {
                                 do{
                                     Name = phoneCur.getString(phoneCur.getColumnIndex(Phone.DISPLAY_NAME));
                                     String phone = phoneCur
                                     .getString(phoneCur
                                             .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA));
                                         phonesList.add(phone);
    
                                   }   while (phoneCur.moveToNext());
    
                             }
    
    
                             phoneCur.close();
    
                             if (phonesList.size() == 0) {
                                 Toast.makeText(
                                         this,"This contact does not contacin any number",
                                         Toast.LENGTH_LONG).show();
                             } else if (phonesList.size() == 1) {
                                 toET.setText(phonesList.get(0));
                             } else {
    
                                 final String[] phonesArr = new String[phonesList
                                         .size()];
                                 for (int i = 0; i < phonesList.size(); i++) {
                                     phonesArr[i] = phonesList.get(i);
                                 }
    
                                 AlertDialog.Builder dialog = new AlertDialog.Builder(
                                         MessageManagerActivity.this);
                                 dialog.setTitle("Name : "+Name);
                                 ((Builder) dialog).setItems(phonesArr,
                                         new DialogInterface.OnClickListener() {
                                             public void onClick(
                                                     DialogInterface dialog,
                                                     int which) {
                                                 String selectedEmail = phonesArr[which];
                                                 toET.setText(selectedEmail);
                                             }
                                         }).create();
                                 dialog.show();
                             }
                         } catch (Exception e) {
                             Log.e("FILES", "Failed to get phone data", e);
                         }
                     }
    
                }
    

    Create your edittext as a class variable.. so you can also apply a empty check, I am very much sure you are creating it again for that purpose..

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.