我正在使用手機通訊錄。我想從聯繫人列表中選擇一個聯繫人,當我點擊該按鈕並獲取所有聯繫信息,如姓名,電子郵件和電話號碼。我剛收到電子郵件和聯繫人姓名,但無法獲得電話號碼。我的代碼如下。挑選號碼,電子郵件ID和聯繫人姓名android
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 {
}
}
}
在這裏我可以選擇user.i的電子郵件,姓名等需要獲得所選用戶的電子郵件,PHONENUMBER和名稱請幫助我。
是有可能得到一個人的電子郵件,姓名和電話號碼,當我從接觸 – jithu
可能重複選擇[Android的挑電子郵件的意圖(http://stackoverflow.com/questions/ 5855022/android-pick-email-intent) – Shubham