Android How to - Use Intent to pick contact People








The following code shows how to Use Intent to pick contact People.

Example

Main Activity Java code

package com.java2s.myapplication4.app;
//from  w ww  .  j a  v a 2 s  . c om
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Contacts;
import android.view.Menu;

public class MainActivity extends Activity {

    private Intent contactIntent;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contactIntent = new Intent();
        contactIntent.setAction(Intent.ACTION_PICK);
        contactIntent.setData(Contacts.People.CONTENT_URI);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add("Contacts").setIntent(contactIntent);
        return true;
    }

}