I am trying to pick contacts with phone number only.And I am following this code
static final int PICK_CONTACT_REQUEST = 1; // The request code
...
private
This works for me:
private void pickContact() {
Intent pickContactIntent = new Intent( Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI );
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
Edit:
Your onActivityResult()
should look like this:
@Override
public void onActivityResult( int requestCode, int resultCode, Intent intent ) {
super.onActivityResult( requestCode, resultCode, intent );
if ( requestCode == PICK_CONTACT_REQUEST ) {
if ( resultCode == RESULT_OK ) {
Uri pickedPhoneNumber = intent.getData();
// handle the picked phone number in here.
}
}
}
}
Use Uri.parse() instead. You can't instsntiate a Uri directly