gpt4 book ai didi

android - 通过帐户类型从android设备过滤器获取联系人

转载 作者:行者123 更新时间:2023-11-29 20:42:24 24 4
gpt4 key购买 nike

我写了一个应用程序联系人同步。它将联系人从服务器同步到设备。与用户haduy@lvsolution.vn完成同步后,我想获取所有联系人的haduy用户。但是它会将所有联系人联系到设备中,请勿由haduy用户过滤。我只想与haduy @ lvsolution帐户联系。

public void getContact()
{
String phone = null;
String name = null;
listContact.clear();
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);

if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
System.out.println("name : " + name + ", ID : " + id);
// get 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()) {
phone = pCur.getString(
pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println("phone" + phone);
}
Contact contact = new Contact(name,phone);
listContact.add(contact);
pCur.close();
}
}
}
}

最佳答案

您可以按照以下方式从account_typeRawContatcs获取联系人。

String yourAccountType="";//ex: "com.whatsapp"
Cursor c = getContentResolver().query(
RawContacts.CONTENT_URI,
new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY },
RawContacts.ACCOUNT_TYPE + "= ?",
new String[] { yourAccountType },
null);

ArrayList<String> contactList = new ArrayList<String>();
int contactNameColumn = c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY);
while (c.moveToNext())
{
// You can also read RawContacts.CONTACT_ID to read the
// ContactsContract.Contacts table or any of the other related ones.
contactList.add(c.getString(contactNameColumn));
}
c.close();

关于android - 通过帐户类型从android设备过滤器获取联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30836867/

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