I am working with phone contacts. I want to pick a contact from the contact list when i click the button and get all the contact information like name,email and phone number.i just got email and name of the contact ,but can't get the phone number.my code is give below.
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, PICK_CONTACT);
}
});
}
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (reqCode)
{
case PICK_CONTACT:
Cursor cursor = null;
String email = "", name = "";
try {
Uri result = data.getData();
//Log.v(DEBUG_TAG, "Got a contact result: " + result.toString());
// get the contact id from the Uri
String id = result.getLastPathSegment();
// query for everything email
cursor = getContentResolver().query(Email.CONTENT_URI, null, Email.CONTACT_ID + "=?", new String[] { id }, null);
int nameId = cursor.getColumnIndex(Contacts.DISPLAY_NAME);
int emailIdx = cursor.getColumnIndex(Email.DATA);
if (cursor.moveToFirst()) {
email = cursor.getString(emailIdx);
name = cursor.getString(nameId);
} else {
// Log.w(DEBUG_TAG, "No results");
}
} catch (Exception e) {
// Log.e(DEBUG_TAG, "Failed to get email data", e);
} finally {
if (cursor != null) {
cursor.close();
}
System.out.println(email);
System.out.println(name);
if (email.length() == 0 && name.length() == 0)
{
Toast.makeText(this, "No Email for Selected Contact",Toast.LENGTH_LONG).show();
}
}
break;
}
} else {
}
}
}
here i can get email and name of the selected user.i need to get email,phonenumber and name of the selected user help me please.