Android 联系人应用程序上联系人的默认帐户类型/名称是什么? [英] What is the default Account Type / Name for contacts on Android Contact Application?

查看:28
本文介绍了Android 联系人应用程序上联系人的默认帐户类型/名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从仅属于电话/SIM 卡的 ContactsContract API 读取联系人,并希望避免从其他应用程序(如 facebook 和 gmail)同步联系人.我在模拟器上测试了我的代码,它运行良好,但在真实设备上它不返回任何结果.

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:

  1. 让用户做出决定.例如,向他展示所有原始联系人的列表,然后让他选择哪个是电话簿联系人还是 SIM 联系人.

  1. 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 不知道用于存储这些电话联系人的帐户.例如,当您从 AccountManager 获取帐户数组时 (AccountManager.getAccounts()) 列表中的com.htc.android.pcsc"not!但是您可以完全利用这一事实:排除所有已知的帐户类型/名称,您获得的列表应该是所有电话簿联系人/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.

这篇关于Android 联系人应用程序上联系人的默认帐户类型/名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆