5

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" />
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Satya
  • 149
  • 1
  • 6
  • I believe Google guys in I/O said that you do not need to worry about the whole sentence, you will get the filtered/processed query. But I doubt, behaviour varies on different devices.. – skygeek Jul 16 '18 at 05:48
  • 1
    @skygeek / Satya I'm hitting the exact same issue, were you guys able to find any solution yet? – Anoop M Maddasseri Mar 17 '21 at 05:01

0 Answers0