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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:31:06+00:00 2026-06-10T07:31:06+00:00

From input box, I am throwing a dialog to pick up the contacts. My

  • 0

From input box, I am throwing a dialog to pick up the contacts. My code looks like below

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toContacts = (EditText)findViewById(R.id.To);
        toContacts.setOnClickListener(new EditText.OnClickListener(){public void onClick(View v){pickContacts();}});

    }

    public void pickContacts(){
        Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(intent, 1);
    }

    public void onActivityResult(int reqCode, int resultCode, Intent data){
        super.onActivityResult(reqCode, resultCode, data);
        String name = "";
          switch (reqCode) {
            case (1) :
              if (resultCode == Activity.RESULT_OK) {
                Uri contactData = data.getData();
                //@SuppressWarnings("deprecation")
                Cursor c = null;
                try{
                     //c =  managedQuery(contactData, null, null, null, null);
                     c = getContentResolver().query(contactData, null, Contacts.DISPLAY_NAME, null, null);
                     if (c.moveToFirst()) {
                          name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                          //String number = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                        }
                } catch(Exception e){
                    Log.e(DEBUG_TAG, "failed to get contacts data", e);
                } finally {
                    if(c != null){
                        c.close();
                    }
                    EditText toSendContact = (EditText) findViewById(R.id.To);
                    toSendContact.setText(name);
                }
              }
              break;
          }

    }

But it is not returning the selected result back in input box.

  • 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-10T07:31:08+00:00Added an answer on June 10, 2026 at 7:31 am

    Replace

    c = getContentResolver().query(contactData, null, Contacts.DISPLAY_NAME, null, null);
    

    with

    c = getContentResolver().query(contactData, new String[] { ContactsContract.Contacts.DISPLAY_NAME }, null, null, null);
    

    You have used selection instead projection.

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

Sidebar

Related Questions

I use this code to get value from an input box: var suggest_type =
i want to pass a string from an input box that after submition automatically
I am taking the amount from one input box and creating a for...each loop
I have a string value from a user input box. I have to figure
I'm new to jQuery and I want to have a input box from a
I have an input box that takes values from 0-100. I want to prevent
I'm trying to prevent certain keys from being entered into an input box, but
I want to assign a value from a select box to an input field
i try to get the value from a radio box in a input box
I have an input box like the following: <input type=text value= somethingSpecial=filename.txt id=myID class=box>

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.