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

The Archive Base Latest Questions

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

I got a code from internet, the code below is picking the contact and

  • 0

I got a code from internet, the code below is picking the contact and displaying it.
I want to display the Name and Phone no: of the person in next ACTIVITY. Could u please help me with this….

import android.app.Activity;

import android.content.Intent;

import android.database.Cursor;

import android.net.Uri;

import android.os.Bundle;

import android.provider.ContactsContract;

import android.widget.TextView;

 public class Contacts_PickerActivity extends Activity

 {

 private TextView tv;

 private static final int CONTACT_PICKER = 1;

 public void onCreate(Bundle savedInstanceState)

 {

 super.onCreate(savedInstanceState);

 tv = new TextView(this);

 setContentView(tv);

 Intent intent = new Intent(Intent.ACTION_PICK,

 ContactsContract.Contacts.CONTENT_URI);

startActivityForResult(intent, CONTACT_PICKER);

}

 public void onActivityResult(int reqCode, int resultCode, Intent data)

 {

super.onActivityResult(reqCode, resultCode, data);

 switch (reqCode)

 {

case CONTACT_PICKER:

if (resultCode == Activity.RESULT_OK)

 {

 StringBuilder sb = new StringBuilder();

 Uri contactData = data.getData();

 Cursor contactsCursor = managedQuery(contactData, null, null, null, null);

if (contactsCursor.moveToFirst())

 {

String id = contactsCursor.getString(contactsCursor

.getColumnIndexOrThrow(ContactsContract.Contacts._ID));

String name = contactsCursor.getString(contactsCursor

.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));

String hasPhoneNumber = contactsCursor.getString(contactsCursor

.getColumnIndexOrThrow(ContactsContract.Contacts.HAS_PHONE_NUMBER));

sb.append("You picked: " + name + "\n");


if (Integer.parseInt(hasPhoneNumber) > 0) 

{

Uri myPhoneUri = Uri.withAppendedPath(

ContactsContract.CommonDataKinds.Phone.CONTENT_URI, id);

Cursor phoneCursor = managedQuery(

myPhoneUri, null, null, null, null);

for (phoneCursor.moveToFirst(); !phoneCursor.isAfterLast(); phoneCursor.moveToNext())

 {

String phoneNumber = phoneCursor.getString(phoneCursor

.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));

sb.append("Phone: " + phoneNumber + "\n");

}

}

 else

{

sb.append("This contact doesn't have a phone number");

}

tv.setText(sb.toString());

}

}

break;

}

}

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

    In the onActivityResult method, the name and phone number are pulled from the Intent data as Strings. You can pass them on to the next Activity as extras on the Intent you create to launch the Activity.

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

Sidebar

Related Questions

I got this javascript code from off the internet. It's a script that changes
I got below code from http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx for adding custom property in webpart tool pane.
I got this code from someone and it works very well, I just want
i made check box in wpf ,Got it from Internet.I want to see which
Am working with web service. Got some sample code from internet. Got some error
I got this application from the internet and I want to add some modifications.
I got this code from the wordpress <head profile=http://gmpg.org/xfn/11> What does this means? what
I got this code from someone, it's almost perfect to create a dynamic breadcrumb,
Hey. I've got some code from Agile Web Development that wraps some HTML around
I am trying to create a countdown using javascript. I got some code from

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.