Ok....I have managed to do it.

For the benefit of others who may be looking for the same thing, i am
pasting the code below. In this code, i launch the contacts application, the
user picks a contact and i display the username of the picked contact:

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;




public final class ContactManager extends Activity
{
private final int PICK_CONTACT =1;

    /**
     * Called when the activity is first created. Responsible for
initializing the UI.
     */
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_manager);
 Intent i = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(i, PICK_CONTACT);
}

    private Cursor getContact(Uri uri) {
        // Run query
     Cursor c =  managedQuery(uri, null, null, null, null);

        return c;
}

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent
data)
    {
     super.onActivityResult(requestCode, resultCode, data);

        Cursor c = getContact(data.getData());
        if (c.moveToFirst())
        {
            String name =
c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
            System.out.println(name);
        }

    }

}

Best Regards

Indodroid

On Fri, Jan 29, 2010 at 4:11 PM, Android Development <[email protected]>wrote:

> Ok, i am able to start the Contacts application...and I pick a contact from
> there. Now this operation succeeds too (-1 Result Code).
>
> I use the following code:
>
> Intent i = new Intent(Intent.ACTION_PICK,
> ContactsContract.Contacts.CONTENT_URI);
>  startActivityForResult(i, PICK_CONTACT);
>
> I get a callback in the onActivityResult method which provides me with the
> data as an Intent as shown below:
>
>  @Override
>     protected void onActivityResult(int requestCode, int resultCode, Intent
> data)
>     {
>      super.onActivityResult(requestCode, resultCode, data);
>
>      if(resultCode==RESULT_OK)
>      System.out.println("a contact was picked..");
>      Uri uri = data.getData();
>
>      System.out.println(uri);
>
>     }
> I want to access the details of the contact that was picked (Display name,
> phone numbers etc) .
>
> I get a URI from the data received from the Contacts application. What does
> this URI point to ? Will i need to execute a DB query to get the actual user
> data for the contact ?
>
> Kindly guide..
>
> Help is appreciated.
>
> Thanks in advance
>
> Indodroid.
>
>
> On Fri, Jan 29, 2010 at 9:15 AM, Android Development 
> <[email protected]>wrote:
>
>> Hello,
>>
>> I wish to re-use the Contacts application in a way to enable the user to
>> pick a contact and return it to the parent activity (my application's
>> activity).
>>
>> For achieving this, I want to inquire about the kind of Intent that will
>> be needed to launch the contacts application.
>>
>> Intent i = new Intent(Intent.ACTION_GET_CONTENT, ???);
>> startActivityForResult(.....);
>>
>> What should be the second argument here ?
>>
>> In the deprecated Contacts API, I could use the following snippet, but not
>> sure about ContactsContract:
>>
>> Intent i= new Intent(Intent.ACTION_GET_CONTENT,People.CONTENT_URI);
>> startActivityForResult(i, reqCode);
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to