gpt4 book ai didi

android - 阅读所有联系人(包括从 facebook 等导入的)

转载 作者:行者123 更新时间:2023-11-29 18:16:15 25 4
gpt4 key购买 nike

根据这个示例:http://developer.android.com/resources/samples/ContactManager/index.html我写了一个简单的函数来获取所有联系人:

 Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME
};
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
(mShowInvisible ? "0" : "1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

它运行良好,但不会返回使用 Facebook 应用程序导入的联系人(但它们在联系人应用程序中可见)。知道如何像在“联系人”应用程序中那样读取所有联系人吗?

谢谢

最佳答案

我认为您需要查看 RawContacts 才能找到该信息。

Android Contacts 是这样的文档说:

A row in the RawContacts table represents the set of Data and other information describing a person and associated with a single contacts source. For example, a row might define the data associated with a person's Google or Exchange account or Facebook friend. For more information, see ContactsContract.RawContacts.

RawContacts文档说:

The best way to read a raw contact along with all the data associated with it is by using the ContactsContract.RawContacts.Entity directory. If the raw contact has data rows, the Entity cursor will contain a row for each data row. If the raw contact has no data rows, the cursor will still contain one row with the raw contact-level information.

那里还有一些示例代码:

 Uri rawContactUri = 
ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);

Uri entityUri =
Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);

Cursor c =
getContentResolver().query(entityUri,
new String[]{RawContacts.SOURCE_ID,
Entity.DATA_ID,
Entity.MIMETYPE,
Entity.DATA1},
null,
null,
null);
try
{
while (c.moveToNext())
{
String sourceId = c.getString(0);

if (!c.isNull(1))
{
String mimeType = c.getString(2);
String data = c.getString(3);
...
}
}
}
finally
{
c.close();
}

关于android - 阅读所有联系人(包括从 facebook 等导入的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7946766/

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