我试图获取我的设备中有条件的所有号码,该联系人包含至少1个电话号码。我试了一下,但它没有用。
selectionString = edtSearch.getText().toString() ;
String[] selectionArgs = { "%" + selectionString + "%", selectionString + "%", "%" + selectionString, "0"};
String selection = ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? OR "
+ ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? OR "
+ ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? AND "
+ ContactsContract.Contacts.HAS_PHONE_NUMBER + " NOT LIKE ?";
CursorLoader cursorLoader = new CursorLoader(ContactsActivity.this,
ContactsContract.Contacts.CONTENT_URI, // URI
null, // projection fields
selection, // the selection criteria
selectionArgs, // the selection args
ContactsContract.Contacts.DISPLAY_NAME + " ASC" // the sort order
);
return cursorLoader;
错误在哪里?
答案 0 :(得分:0)
更改selectionArgs和选择,如下所示,
String[] selectionArgs = { "%" + selectionString + "%", selectionString + "%", "%" + selectionString};
String selection = ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? OR "
+ ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? OR "
+ ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? AND "
+ ContactsContract.Contacts.HAS_PHONE_NUMBER + "='1'";