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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:47:09+00:00 2026-05-26T16:47:09+00:00

I am trying to open my contacts inside my app and allow the user

  • 0

I am trying to open my contacts inside my app and allow the user to choose a contact, then the user will be able to choose the phone number they want to use. Right now the method I have allows me to select the proper contact and phone number, however I don’t know how to tell the user if the phone number is a home phone number, or cell phone number.

How do I mention next to the number if it is a cell, home, work ,etc

This is what I’m using now to get the phone number from the contacts. Thanks!enter image description here

protected void onActivityResult(final int requestCode, int resultCode,
        Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data != null) {
            Uri contactData = data.getData();

            try {

                String id = contactData.getLastPathSegment();
                Cursor phoneCur = getContentResolver().query(
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                + " = ?", new String[] { id }, null);

                final ArrayList<String> phonesList = new ArrayList<String>();
                while (phoneCur.moveToNext()) {
                    // This would allow you get several phone addresses
                    // if the phone addresses were stored in an array
                    String phone = phoneCur
                            .getString(phoneCur
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA));
                    phonesList.add(phone);
                }
                phoneCur.close();
                if (phonesList.size() == 0) {
                    Toast.makeText(this, "No Phone Number in Contact",
                            Toast.LENGTH_SHORT).show();
                } else if (phonesList.size() == 1) {
                    switch (requestCode) {
                    case (1):
                        edit1.setText(phonesList.get(0));
                        break;
                    case (2):
                        edit2.setText(phonesList.get(0));
                        break;
                    case (3):
                        edit3.setText(phonesList.get(0));
                        break;
                    }
                } 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(
                            Settings.this);
                    dialog.setTitle("Choose Phone Number");
                    ((Builder) dialog).setItems(phonesArr,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    String selectedEmail = phonesArr[which];
                                    switch (requestCode) {
                                    case (1):
                                        edit1.setText(selectedEmail);
                                        break;
                                    case (2):
                                        edit2.setText(selectedEmail);
                                        break;
                                    case (3):
                                        edit3.setText(selectedEmail);
                                        break;
                                    }
                                }
                            }).create();
                    dialog.show();
                }
            } catch (Exception e) {
                Log.e("FILES", "Failed to get phone data", e);
            }
        }
    }
  • 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-26T16:47:09+00:00Added an answer on May 26, 2026 at 4:47 pm
    ContentResolver contentResolver = getContentResolver();
    
        Cursor cursor = contentResolver.query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
            new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER,
                ContactsContract.CommonDataKinds.Phone.TYPE },
            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "="
                + contactId, null, null + " DESC");
    
        if (cursor.moveToFirst()) {
            do {
            int phoneNumberColumn = cursor.getColumnIndex(Phone.NUMBER);
            int phoneTypecolumn = cursor.getColumnIndex(Phone.TYPE);
    
            int phoneType = Integer.parseInt(cursor
                .getString(phoneTypecolumn));
    
            String phoneNumberType = "";
    
            if (phoneType == ContactsContract.CommonDataKinds.Phone.TYPE_HOME) {
                phoneNumberType = "Home";
            } else if (phoneType == ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE) {
                phoneNumberType = "Mobile";
            } .....//Similarly the other types could be obtained.
    
            } while (cursor.moveToNext());
        }
    

    Hope this would help.

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

Sidebar

Related Questions

Im trying to achieve something similar to Apples Contact.app. When the user press Edit
I'm trying to extend my current app(internal company phonebook) to be able to forward
I am trying open a new window using url.Action. And the new Window url
I am trying open a very large file in Emacs and it fails to
im trying to open a file using StreamReader and ive to set a Encoding,
I trying to open C: directly with FileStream without success: new FileStream(C:, FileMode.Open, FileAccess.Read,
I'm trying to open a folder in explorer with a file selected. The following
I'm trying to open a file and create a list with each line read
I'm trying to open a Microsoft Excel file in a C# program using the
I'm trying to open and read from a serial port using the System.IO.Ports.SerialPort class.

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.