【发布时间】:2013-01-18 06:28:19
【问题描述】:
我正在处理电话联系人。我想在单击按钮时从联系人列表中选择一个联系人并获取所有联系信息,例如姓名、电子邮件和电话号码。我刚刚得到了联系人的电子邮件和姓名,但不能获取电话号码。我的代码如下。
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 {
}
}
}
在这里我可以得到所选用户的电子邮件和姓名。我需要得到所选用户的电子邮件、电话号码和姓名,请帮帮我。
【问题讨论】:
-
当我从联系人中选择时,是否可以获得一个人的电子邮件、姓名和电话
-
Android pick email intent 的可能重复项
标签: android email contacts phone-number