我正在通过查询检索联系人详细信息(特别是他们的邮政地址)ContactsContract
。关键是我想跳过从 WhatsApp、LinkedIn、Skype 等其他应用程序同步的联系人......
我的代码是:
Uri uri = StructuredPostal.CONTENT_URI;
String[] sqlSelect = new String[] { StructuredPostal.FORMATTED_ADDRESS, StructuredPostal.DISPLAY_NAME, StructuredPostal.STREET, StructuredPostal.CITY, StructuredPostal.POSTCODE, StructuredPostal.COUNTRY };
String sqlWhere = StructuredPostal.MIMETYPE + "=?" + " AND " +
"(" + StructuredPostal.STREET + " LIKE '%" + queryString + "%'" + " OR " +
StructuredPostal.CITY + " LIKE '%" + queryString + "%'" + " OR " +
StructuredPostal.POSTCODE + " LIKE '%" + queryString + "%'" + " OR " +
StructuredPostal.COUNTRY + " LIKE '%" + queryString + "%')";
String[] sqlWhereParams = new String[]{ StructuredPostal.CONTENT_ITEM_TYPE };
String sortOrder = StructuredPostal.STREET + " ASC";
Cursor cursor = this.getContentResolver().query(uri, sqlSelect, sqlWhere, sqlWhereParams, sortOrder);
if (cursor.moveToFirst()) {
do {
String formattedAddress = cursor.getString(cursor.getColumnIndex(StructuredPostal.FORMATTED_ADDRESS));
String displayName = cursor.getString(cursor.getColumnIndex(StructuredPostal.DISPLAY_NAME));
String street = cursor.getString(cursor.getColumnIndex(StructuredPostal.STREET));
String city = cursor.getString(cursor.getColumnIndex(StructuredPostal.CITY));
String postcode = cursor.getString(cursor.getColumnIndex(StructuredPostal.POSTCODE));
String country = cursor.getString(cursor.getColumnIndex(StructuredPostal.COUNTRY));
Log.d(TAG, formattedAddress + " " + displayName + " " + street + " " + city + " " + postcode + " " + country);
} while (cursor.moveToNext());
}
LogCat
输出正确打印了我在地址簿中手动添加的联系人:
<postal_address> <contact_full_name> <street> <city> <postcode> <country>
但是从第三方应用程序导入的应用程序正在打印(LinkedIn):
<email> <contact_full_name> <email> null null null
它应该在哪里(如果邮政地址不可用):
null <contact_full_name> null null null null
第三方应用程序是否错误地使用了联系人?有没有办法跳过第三方同步联系人?