仅获取 SIM 卡和设备存储的联系人 [英] Get only sim and device stored Contacts
问题描述
我想显示一个列表,其中包含存储在设备和 SIM 中的联系人的姓名(GIVEN_NAME
、FAMILY_NAME
)(我想排除帐户联系人).
I want to display a list with the names (GIVEN_NAME
, FAMILY_NAME
) of contacts that are stored in the Device and in SIM (I want to exlcude Account contacts).
我现在要做的是:
1) 我在 accountTypesArray
2) 我查询不包括帐户的 RawContacts
2) I query RawContacts excluding the accounts
String where = ContactsContract.RawContacts.ACCOUNT_TYPE + " NOT IN (" + makePlaceholders(accountTypesArray.length) + ") ";String whereArgs[] = accountTypesArray;
return new CursorLoader(getActivity(),ContactsContract.RawContacts.CONTENT_URI,new String[]{ContactsContract.RawContacts._ID},在哪里,whereArgs, null);
3) 我用 mimeType 结构化名称查询 DATA
3) I query DATA
with mimeType structured name
String where = ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE +"' AND " + ContactsContract.Data.RAW_CONTACT_ID + " IN (" + makePlaceholders(contactIDsArray.length) + ") ";
return new CursorLoader(getActivity(),ContactsContract.Data.CONTENT_URI,投影,在哪里,联系人IDsArray,SORT_ORDER);
问题是当 contactIDsArray
大小大于 999 并且 SQLite 抛出过多 SQL 变量异常时.有没有更有效的方法?
The problem is when the contactIDsArray
size is greater that 999 and SQLite throws too many SQL variables Exception.
Is there a more efficient way?
提前致谢
推荐答案
这需要我们从调查不同设备中获得的魔法字符串.
This requires magic strings we've picked up from investigating different devices.
对于 SIM 联系人,请运行以下查询:
For SIM contacts run the following query:
String selection = RawContacts.ACCOUNT_TYPE + " IN ('vnd.sec.contact.sim', 'com.oppo.contacts.sim')";
String[] projection = { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY };
getContentResolver().query(RawContacts.CONTENT_URI, projection, selection, null, null);
对于设备联系人,请尝试以下操作:
For device contacts, try the following:
String selection = RawContacts.ACCOUNT_TYPE + " IN ('vnd.sec.contact.phone', 'com.htc.android.pcsc', 'com.sonyericsson.localcontacts', 'com.lge.sync', 'com.android.huawei.phone', 'Local Phone Account')";
String[] projection = { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY };
getContentResolver().query(RawContacts.CONTENT_URI, projection, selection, null, null);
这篇关于仅获取 SIM 卡和设备存储的联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!