user2254184
user2254184

Reputation: 43

Using an intent to open contacts?

I'm trying to link one of my buttons to an intent that will open up the contacts application on my device. Any help with how to use an intent or other method to open it up?

public class MainActivity extends Activity implements View.OnClickListener {
View v;
Button contacts;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getContacts();
    contacts.setOnClickListener(this);
}

private void getContacts() {
    // TODO Auto-generated method stub
    contacts = (Button) findViewById(R.id.bcontacts);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.bcontacts:
        intent contacts = new Intent \\this is where i dont know what to do
        break;
    }
}

}

Upvotes: 4

Views: 688

Answers (1)

hardartcore
hardartcore

Reputation: 17037

That should do the trick for you :

Intent intent= new Intent(Intent.ACTION_PICK,  Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);

Upvotes: 1

Related Questions