I am using android leanback-assistant sample of google to enable google assistant support in my AndroidTV app. But in given code snippet the query() method of SearchContentProvider is not receiving the processed string what I get from uri.lastPathSegment(). e.g. if user says "play gravity movie", the content provider should receive only "gravity" as query but it receive complete string "play gravity movie". Is that an expected behaviour. What could be the solution if not?
class SearchContentProvider : ContentProvider() {
private val TAG = "SearchContentProvider"
private val AUTHORITY = "tv.example.sampleleanback"
// UriMatcher constant for search suggestions
private val SEARCH_SUGGEST = 1
private lateinit var mUriMatcher: UriMatcher
override fun onCreate(): Boolean {
mUriMatcher = buildUriMatcher()
return true
}
override fun query(uri: Uri?, p1: Array<out String>?, p2: String?, p3: Array<out String>?, p4: String?): Cursor {
if (uri != null && mUriMatcher.match(uri) == SEARCH_SUGGEST) {
Log.d(TAG, "Search suggestions requested.")
return search(uri.lastPathSegment)
} else {
Log.d(TAG, "Unknown uri to query: $uri")
throw IllegalArgumentException("Unknown Uri: $uri")
}
}...}
Here is the Searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_hint"
android:icon="@drawable/img_logo"
android:includeInGlobalSearch="true"
android:label="@string/search_label"
android:queryAfterZeroResults="true"
android:searchSettingsDescription="@string/settings_description"
android:searchSuggestAuthority="tv.example.sampleleanback"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:searchSuggestPath="search"
android:searchSuggestThreshold="0" />