我知道如何在 Android 上获取所有联系人,但如果我选择联系人,我无法获得我想要的联系人。示例:我有 4 个联系人
joe have phone number 7889 987;
erick have phone number 8792 871;
nona phone number 3653 872 and 2345 907;
rina phone number 8796 235;
如果我选择 joe,我会得到 nona 的电话号码 = 2345 907 我不知道我的应用程序有什么问题。
这是我的代码
public void tambahPenerima ( View v ) {
Intent i = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
i.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(i, PICK_CONTACT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
Cursor cursor = null;
String name = "";
String number = "";
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
while(cursor.moveToNext()) {
name = cursor.getString(cursor.getColumnIndex((ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
if(cursor!=null) {
cursor.close();
}
Intent kirimPesan = new Intent();
kirimPesan.setClass(this, kirimPesan.class);
kirimPesan.putExtra("nama", name);
kirimPesan.putExtra("nomor", number);
kirimPesan.putExtra("chiper", chiper);
startActivity(kirimPesan);
}
}
有人请帮助我,我真的需要帮助。对不起我糟糕的英语。谢谢 ..