Android 3.0 - 如何通过 ContactsContract 检索所有联系人
我正在开发一个 Android Honeycomb (v3.0) 应用程序,该应用程序需要显示设备上注册的 Google 帐户中存储的所有联系人。我遇到的问题之一是我只能检索“我的联系人”、“Android 中加星标”和“其他联系人”中可用的联系人。我还希望能够从“目录”中检索联系人。我相信“目录”部分是 Google 向希望向其他人提供其域内所有成员/员工目录的组织和公司提供的一项功能。请参阅下面的屏幕截图:
到目前为止,我的清单文件中有以下行:
<uses-permission android:name="android.permission.READ_CONTACTS" />
我已尝试使用此代码:
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}
cursor.close();
就我而言,“我的联系人”和“Android 中已加星标”为空。然而,获得了“其他联系人”中的(1)联系人。不过,“目录”包含数百个未检索到的联系人。
我的问题:有什么方法可以确保“目录”中的联系人也被检索到吗?我知道我可以简单地使用网络浏览器复制联系人,然后将它们同步到设备,但如果将新联系人添加到“目录”中,我每次都必须手动执行此操作,所以这对我来说不是一个很好的选择。请指教。
I am working on an Android Honeycomb (v3.0) application that has a requirement of displaying ALL contacts stored within the Google account that is registered on the device. One of the problems I am having is that I can only retrieve the contacts that are available within "My Contacts", "Starred in Android", and "Other Contacts". I would also like to be able to retrieve contacts from the "Directory". I believe that the "Directory" section is a feature provided by Google to organizations and companies who wish to provide a directory of all members/employees within their domains to others. Please see the screenshot below:
So far, I have the following line in my manifest file:
<uses-permission android:name="android.permission.READ_CONTACTS" />
I have tried using this code:
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}
cursor.close();
In my case, "My Contacts" and "Starred in Android" are empty. However, the (1) contact in "Other Contacts" is obtained. The "Directory" contains hundreds of contacts that are not retrieved, though.
My question: Is there any way to make sure that the contacts in the "Directory" are retrieved as well? I know that I can simply copy the contacts over using the web browser and then sync them to the device, but if a new contact is added to the "Directory", I would have to do this manually every time, so this is not a great choice for me. Please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看下面的代码
look at the following code