什么是默认帐户类型/名称在Android接触的应用联系人?帐户、联系人、名称、类型

2023-09-04 23:38:57 作者:迩乱了俄的夏天

我想读ContactsContract API只属于手机/ SIM卡,并想避免接触其他应用程序,如Facebook和Gmail同步联系人。我测试了我的code对模拟器并能正常工作,但在实际的设​​备不返回任何结果。

I would like to read contacts from ContactsContract API which belongs only to Phone / SIM and would like to avoid contacts synced from other apps like facebook and gmail. I tested my code on simulator and it works fine but on real devices it doesn't returns any result.

ContentResolver cr = AndroidContext.getContext()
                    .getContentResolver();
Cursor nativeContacts = cr.query(RawContacts.CONTENT_URI,
                    new String[] { RawContacts._ID, RawContacts.VERSION, RawContacts.CONTACT_ID },
                    RawContacts.DELETED + "<> 1 AND " + RawContacts.CONTACT_ID
                            + " IS NOT NULL AND " + RawContacts.ACCOUNT_NAME + " IS NULL AND "
                            + RawContacts.ACCOUNT_TYPE + " IS NULL", null, null);

我想对设备的帐户类型和名称默认帐户是不为空,该如何解决?

I guess on devices the account type and name for default account is not null, what is the solution?

推荐答案

为你做我做了同样的遭遇,只能建议两种解决方法:

I made the same experiences as you did and can only suggest two workarounds:

让用户作出的决定。比如给他的所有原材料的联系人列表,然后让他选择哪一个是电话簿联系人与SIM卡联系人。

Let the user make the decision. For example show him a list of all raw contacts and then let him choose which one is a phonebook contact vs. a sim contact.

我有三个不同设备的经验是,的AccountManager不知道用来存储那些phonecontacts的帐户。从的AccountManager像你一样。例如,当你获取帐户阵列( AccountManager.getAccounts())的com.htc.android.pcsc是的不是的列表中!但是你可以使用完全相同的事实,你的优势:排除所有已知的帐户类型/名称和你得到的名单应该是所有phonebookcontacts / simcontacts名单

My experience with three different devices is that the AccountManager is not aware of the account used to store those phonecontacts. For example when you fetch an account array from the AccountManager as you did (AccountManager.getAccounts()) the "com.htc.android.pcsc" is not in the list! But you can use exactly that fact to your advantage: Exclude all known account types/names and the list you get should be the list of all phonebookcontacts/simcontacts.

希望这些想法帮你:)我想了解这些解决方法您的想法,最终我错过了一些东西或者有一个更好的解决办法。

Hopefully those ideas helped you :) I would like to read your thoughts about those workarounds, eventually I missed something or there is a even better workaround.