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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:58:15+00:00 2026-05-19T01:58:15+00:00

I am new to android. So I request you to be patient with me.

  • 0

I am new to android. So I request you to be patient with me. I am trying to write an application where on pressing a button the contacts API is opened. Then the user chooses the contact. Then I want to get the chosen contact in onAcitvityResult(int reqcode, int rescode, Intent data). Is there a way to do this without getting the Uri and querying for it through the whole database?
This is my code where the second activity starts:

public void onClick(View v) {

      Log.d(TAG, "contact button clicked");
      Toast.makeText(ctx, "Contact button clicked",
      Toast.LENGTH_SHORT).show();

      Intent contacts = new Intent(Intent.ACTION_GET_CONTENT,Contacts.CONTENT_URI);
      contacts.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);

      startActivityForResult(contacts,1);
}

Am I correct in using Contacts.CONTENT_URI and Intent.ACTION_GET_CONTENT?

Is the intent I am using correct?
I get the feeling that I should include email specifics here.

And this is where I deal with the result from activity:

protected void onActivityResult(int requestCode, int resultCode, Intent data){

    super.onActivityResult(requestCode, resultCode, data);
    String email=""; long id;
    if (requestCode == 1) {
        if (resultCode == Activity.RESULT_OK) {

            // get the contact ID
            Uri contacturi= data.getData();
            Cursor c= getContentResolver().query(contacturi,null,null,null,null);
            id = c.getLong(c.getColumnIndex(ContactsContract.Contacts._ID));
            c.close();

            // get the data package containing the email address for the contact
            c=getContentResolver().query(ContactsContract.Data.CONTENT_URI,
                    new String[]{Email.DATA1}, 
                    ContactsContract.Data.CONTACT_ID + "=? AND " + Email.MIMETYPE + "=?",
                    new String[]{String.valueOf(id), Email.CONTENT_ITEM_TYPE}, null);

            email=c.getString(c.getColumnIndex(Email.DATA1));
            Log.d(TAG, "email is" + email);
        }
    }
    else {
        Log.d(TAG, "requestCode is not 1");
    }

    EditText ctext= (EditText) findViewById(R.id.contacttxt);
    ctext.append(email);
    Log.d(TAG, "onActivityResult() ends");
}

I am getting a runtime exception saying that failure delivering result.
Should I include some setResult() method??
Thank you in advance.

  • 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-19T01:58:15+00:00Added an answer on May 19, 2026 at 1:58 am

    I got it 🙂
    You have to add c.moveToFirst(); two times, after the two initializations as the 2 cursors.
    But I am not getting why. Could anyone explain it?

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

Sidebar

Related Questions

I am new to Android platform and trying to establish a http request but
i am creating a new android application.i am using the table layout. I have
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
I'm doing an HTTP request in an Android application using this code: try {
I am creating an Android application that connects to the Fogbugz XML API (sends
I am new in Android. I am trying to make an RPC to fetch
So I am relatively new to Android and I am trying to parse a
I am new to android programming and trying to use webservice in this sample
I'm pretty new in Android programming. My problem is to write any information to
i am new to android development. i am trying to post data to server

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.