访问内部地址簿
两天多来,我一直在尝试从内部地址簿(没有 facebook、gmail 或 twitter 联系人)中获取所有联系人的列表以及他们的家人和名字。
我设法获得了包含所有联系人(包括社交联系人)的列表。所以我查看了 account_types,发现在我的 HTC Desire 上,所有内部地址簿联系人都来自“com.htc.android.pcsc”,我当时想“太棒了,我只需过滤整个列表”。但是,如果我对此过滤器进行硬编码,那么所有拥有非 htc android 手机的人都将无法使用我的应用程序。
下一个想法是让用户选择他想要使用的帐户,但不幸的是“com.htc.android.pcsc”没有出现在我从 AccountManager 获得的列表中?!?
所以我的问题是: 有没有标准化的方法来访问内部地址簿?我真的很坚持这一点,非常感谢任何提示!
/编辑:也许我的自我表达不够清楚。 我可以通过 ContactsContract API 获取联系人列表:
ArrayList phoneContacts = new ArrayList();
String[] projection = new String[] {
Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME
};
String selection = Data.MIMETYPE+" = '"+ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE+"'";
Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, selection, null, null);
while (cursor.moveToNext()) {
phoneContacts.add(...);
}
cursor.close();
但是我有来自所有不同帐户类型的联系人,例如 com.google / com.htc.socialnetwoork.facebook 等。
我的问题是:如何我可以过滤掉所有这些社交网络和 gmail 联系人,这样我就有了一个仅来自我的内部地址簿的联系人列表吗?
/edit2:我找到了一个例子来描述我遇到的同样的困难: http://forum.synthesis.ch/showthread.php?t=2057 Synthesis AG 的 SyncML 也有同样的问题,人们抱怨他们无法仅通过 gmail、facebook 等与内部地址簿/电话簿同步。 但他们设法将内部地址簿与所有其他帐户类型分开。所以一定有办法解决这个问题,但我不知道如何解决。请帮忙!
For more than two days now, I'm trying to grab a list of all contacts, from the internal addressbook (no facebook-, gmail- or twittercontacts) with their family- and givenname.
I managed to get a list with all contacts, socialcontacts included. So I looked at the account_types and saw that on my HTC Desire all the internal addressbook-contacts were from "com.htc.android.pcsc" and I was like "Great, I just have to filter the whole list". But then all people with non-htc android cellphones would be unable to use my app, if I would hardcode this filter.
Next idea was to let the user choose which account he wants to use, but unfortunately the "com.htc.android.pcsc" didn't appear in the list I got from the AccountManager?!?
So my question is:
Is there any standardized way to access the internal adressbook? I'm really stuck with that and any hint is highly appreciated!
/edit: Maybe i didn't make my self clear enough.
I can grab a contactlist, via the ContactsContract API:
ArrayList phoneContacts = new ArrayList();
String[] projection = new String[] {
Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME
};
String selection = Data.MIMETYPE+" = '"+ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE+"'";
Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, selection, null, null);
while (cursor.moveToNext()) {
phoneContacts.add(...);
}
cursor.close();
But then I have contacts from all the different accounttypes, like com.google / com.htc.socialnetwoork.facebook, etc.
And my question is: How can I filter all these socialnetwork- and gmailcontacts out, so I have a list with contacts, which are only from my internal addressbook?
/edit2: I found an example which describe the same difficulty I have:
http://forum.synthesis.ch/showthread.php?t=2057
Synthesis AG had the same problem with their SyncML, that people complaining that they can't sync with their internal addressbook/phonebook only with gmail, facebook, etc.
But they managed to seperate the internal addressbook from all these other accounttypes. So there must be a way to solve this problem, but I can't figure out how. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该问题已在另一个线程中得到回答: Android 联系人应用程序上联系人的默认帐户类型/名称是什么?
The question has been answerd in another thread: What is the default Account Type / Name for contacts on Android Contact Application?
您真的需要关心帐户类型吗?
只需检索聚合的顶级联系人(而不是每个单独的原始联系人)并将其用作您的联系人列表。
例如,我有许多联系人,它们链接在一起形成一个联系人条目,即使存在多个底层原始联系人条目(例如,来自我的 Google 帐户或 Facebook 等)。
如果您从我的电话簿中过滤掉所有单独的 Google 和 Facebook 联系人,您将一无所有。或者,如果您列出所有原始联系人,则会有 90 个联系人,其中有很多重复项,而不是只有 50 个实际联系人。
因此,如果您只是检索聚合联系人,则帐户类型并不重要。
Do you actually have to care about the account types?
Just retrieve the aggregated top-level contacts — rather than each individual raw contact — and use that as your contact list.
For example, I have many contacts who are linked together into one contact entry, even although there are multiple underlying raw contact entries (e.g. from my Google Account, or Facebook etc.).
If you filtered out all the individual Google and Facebook contacts from my phonebook, you'd be left with nothing. Or if you listed all raw contacts, you'd have 90 contacts, with many duplicates, instead of just 50 actual people.
So, the account type shouldn't matter if you just retrieve aggregated contacts.
当您将联系人添加到手机通讯录时,您必须将
ACCOUNT_NAME
和ACCOUNT_TYPE
设置为null
。但是设备会将这些值更改为一些适当的名称和类型,并且这些值对于不同的制造商来说并不相同。我不知道有什么真正好的方法来过滤除地址簿帐户之外的所有帐户。我只看到实现这种行为的方法,但它们似乎都不太好:
When you add a contact to your phone's address book, you have to set
ACCOUNT_NAME
andACCOUNT_TYPE
tonull
. But device changes these values to some appropriate name and type and these values aren't the same for different manufactures.I don't know any really good way to filter out all accounts except the address book account. I see only to ways to implement such behavior, but both of them seems to be not so good:
"com.anddroid.contacts.sim"
account type must be filtered out too.