gpt4 book ai didi

安卓联系人选择器 : pick phone or email

转载 作者:搜寻专家 更新时间:2023-11-01 09:46:15 25 4
gpt4 key购买 nike

Android 联系人选择器是否可以显示电话号码和电子邮件地址列表,并且用户可以选择电话或电子邮件。

我尝试了以下 Intent :

Intent.ACTION_PICK, Contacts.CONTENT_URI // - selects the entire contact
Intent.ACTION_PICK, Phone.CONTENT_URI // - select only phones
Intent.ACTION_PICK, Email.CONTENT_URI // - select only emails

最佳答案

已经有人回答了:Link to answer但我只会在这里发布代码

private void contactPicked(Intent data) {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
cur.moveToFirst();
try {
// getData() method will have the Content Uri of the selected contact
Uri uri = data.getData();
//Query the content uri
cur = getContentResolver().query(uri, null, null, null, null);
cur.moveToFirst();
// column index of the contact ID
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
// column index of the contact name
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
txtNombreContacto.setText(name); //print data
// column index of the phone number
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phone = pCur.getString(
pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
txtTelefono.setText(phone); //print data
}
pCur.close();
// column index of the email
Cursor emailCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
new String[]{id}, null);
while (emailCur.moveToNext()) {
// This would allow you get several email addresses
// if the email addresses were stored in an array
String email = emailCur.getString(
emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
txtMailContacto.setText(email); //print data
}
emailCur.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

关于安卓联系人选择器 : pick phone or email,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37957689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com