0
我想从联系人列表中获取电话号码。 我在全球能够做到这一点,但我有一个联系人有多个电话号码的问题。联系人列表只显示使用意图的一个电话号码ContactsContract
这里是我的问题:
- 在AVD(API21),联系人列表显示以及2个电话我接触
- 的在我的真实电话(android 5.0.2 => API21),它只显示第一个电话。不是所有的,因为它是在AVD。
你知道为什么AVD和我的真实手机的行为不同吗?
这里是我我打电话的意图:
Intent contactIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
contactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(contactIntent, PICK_CONTACT);
这里是我的OnActivity代码:
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
//Field to fill with the selected phone number
final EditText textPhone = (EditText) findViewById(R.id.Phone);
if (data != null) {
Uri uri = data.getData();
if (uri != null){
//Get the phone number id from the Uri
String id = uri.getLastPathSegment();
//Query the phone numbers for the selected phone number id
Cursor c = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone._ID + "=?",
new String[]{id}, null);
int phoneIdx = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
// get the only phone number
if (c.moveToFirst()) {
textPhone.setText(c.getString(phoneIdx));
} else {
//no result
Toast noResultFound = Toast.makeText(SendLocationInfoActivity.this, "No phone number found", Toast.LENGTH_SHORT);
noResultFound.show();
}
c.close();
}
}
}
请不要提出解决方案来显示联系人列表,并在单击具有多个电话的联系人时显示对话框列表。 我试过了,它可以工作,但是通过这种方法,联系人列表还显示了所有没有电话号码的联系人。 – Mario
这意味着,联系人显示在AVD中,但不在设备中。我对吗? –
其实AVD显示联系人+所有手机,真实设备只显示联系人+第一部手机。 – Mario