For one of my apps, I need the user to select one of his existing contacts or to create a new one. Picking one is clearly easy to do with the following code:
int INSERT_CONTACT_REQUEST=2;
i = new Intent(Intent.ACTION_INSERT,Contacts.CONTENT_URI);
startActivityForResult(i, INSERT_CONTACT_REQUEST);
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
if(requestCode == INSERT_CONTACT_REQUEST)
{
if (resultCode == RESULT_OK)
{
Toast.makeText().show(getApplicationContext(),"Added_Succesfully",Toast.LENGTH_SHORT);
}else if(resultCode == RESULT_CANCELED)
{
Toast.makeText().show(getApplicationContext(),"Contacts Adding Error",Toast.LENGTH_SHORT);
}
}
}