只有得到保存到手机或SIM卡的Andr​​oid通讯录 [英] Only get android contacts that are saved to the phone or sim

查看:144
本文介绍了只有得到保存到手机或SIM卡的Andr​​oid通讯录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索明确保存在Android设备上的联系人(即不是Gmail或Facebook和保存联系人形信息的其他应用程序返回的)。我一直在玩弄从PhoneGap的接触插件这种code座:

I am trying to retrieve contacts on an android device that are explicitly saved (i.e. not the ones returned by gmail or Facebook and other apps that save contact-like information). I have been playing around with this code block from the PhoneGap contacts plugin:

Cursor idCursor = mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
    new String[] { ContactsContract.Data.CONTACT_ID },
    whereOptions.getWhere(),
    whereOptions.getWhereArgs(),
    ContactsContract.Data.CONTACT_ID + " ASC");

我修改了各种争论,并试图查询基于 ContactsContract.RawContacts.ACCOUNT_TYPE 没有运气。如何修改上面的code座实现我需要什么?

I modified various arguments and tried querying based on ContactsContract.RawContacts.ACCOUNT_TYPE with no luck. How can I modify the code block above to achieve what I need?

推荐答案

无论是否接触出现在定期接触是由以下属性决定:

Whether or not the contacts appear in the regular contacts is determined by the following property:

ContactsContract.Contacts.IN_VISIBLE_GROUP

我修改了查询,考虑到这一点之一,它删除联系人返回的是不是真的接触(如Gmail历史,...等):

I modified one of the queries to account for this and it removed contacts returned that aren't really contacts (such as gmail history, ...etc):

options.setWhere("(" + ContactsContract.Contacts.IN_VISIBLE_GROUP + " = 1 AND " + ContactsContract.Data.CONTACT_ID + " LIKE ? )");

在原来的问题(从科尔多瓦接触插件)查询只是获取匹配所提供的搜索词的ID,修改查询是一个后来在插件code(更准确地对应 getWhere()功能进行了修改,占 IN_VISIBLE_GROUP 属性):

The query in the original question (from the cordova contacts plugin) simply gets the ids that match the provided search term, the query to modify is the one later in the plugin code (more accurately the corresponding getWhere() function was modified to account for the IN_VISIBLE_GROUP property):

Cursor c = mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
            columnsToFetch.toArray(new String[] {}),
            idOptions.getWhere(),
            idOptions.getWhereArgs(),
            ContactsContract.Data.CONTACT_ID + " ASC");

我主持的插件在我github上修改后的版本。请注意,我的版本只适用于在没有搜索字词的实例。

I hosted a modified version of the plugin on my github. Note that my version only works for instances where there is no search term.

这篇关于只有得到保存到手机或SIM卡的Andr​​oid通讯录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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