Android - 在 phone 号码喜欢正在输入的内容的情况下取得联系

Android - get contact where phone number LIKE something being typed

我一直在尝试通过号码获取联系人,与您在股票拨号器上拨打号码时 Android 实施的方式相同。如果您很熟悉,就会知道当您拨号时,它会开始显示包含这些号码的匹配项(例如,拨打 3412 时会匹配 913284912)。 (不确定这种搜索方式是否只在 5.x+ 上实施)

我成功了,但只有当号码与使用以下代码的联系人号码完全相同时才有效:

private Cursor getContacts(String number) {
    // Run query
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number.trim()));
    String[] projection = new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME,
            ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI, ContactsContract.PhoneLookup._ID};
    return getContext().getContentResolver().query(
            uri,
            projection,
            null,
            null,
            null
    );
}

我很难找到解决方案,因为每个人都用它来联系。但是因为我不想要完全匹配,所以这对我来说不合适。

提前致谢。

您可以将适配器与过滤器一起使用。可以找到一些示例:Filtering ListView with custom (object) adapter or even better Custom Listview Adapter with filter Android