android获取至少1个电话号码的联系人

时间:2016-04-25 14:52:15

标签: android android-cursorloader

我试图获取我的设备中有条件的所有号码,该联系人包含至少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;

错误在哪里?

1 个答案:

答案 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'";