I have started the contact picker activity
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, enumRequestCode.PICK_CONTACT.ordinal());
Then in onActivityResult i have this code to get phone number (And display_name, but that is not good, enough... i need firstname and surname to be able to support different country inputs):
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(enumRequestCode.PICK_CONTACT.ordinal() == requestCode){
if (resultCode == Activity.RESULT_OK) {
Cursor cursor = managedQuery(data.getData(), null, null, null, null);
while (cursor.moveToNext())
{
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
String phoneNumber = "";
int hasPhone = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
String firstName = "";
String surName = "";
if (hasPhone >= 1){
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
phones.moveToNext();
phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
phones.close();
}
I've tried with:
// String firstName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
// String surName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
But that didn't work out very well.
I've seen this one, but it didn't really help me alot: How to get the first name and last name from Android contacts?
Anyone can help me with this one?
thanks in advance!