Unwanted suggestions from system when using SearchView with custom searchSuggestAuthority

182 views Asked by At

I have an android.widget.SearchView in the ActionBar of my app. When I start typing it shows results from my ContentProvider hooked to a Room database. This all works fine on the emulator, but on my real device when I touch the SearchView text field I see my results for an instant then the popup gets replaced with this weird popup showing two phone numbers (this are numbers known to me). If I start typing this box goes away and the proper results start showing up again.

search with weird popup

I'm at my wits end about what could be causing this. Here is the code related to the SearchView.

MainActivity.kt

override fun onCreateOptionsMenu(menu: Menu): Boolean {
    menuInflater.inflate(R.menu.bottom_nav_menu, menu)

    var searchItem = menu.findItem(R.id.ItemSearchView);
    var searchView : SearchView = searchItem.actionView as SearchView;
    val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
    val searchableInfo = searchManager.getSearchableInfo(componentName)

    searchView.setSearchableInfo(searchableInfo)
    searchView.isIconifiedByDefault = false
    searchView.maxWidth = 10000;
    searchView.onFocusChangeListener = View.OnFocusChangeListener { view, b ->
        Log.i(TAG, "SearchView focus is ${b}")
    }

    return super.onCreateOptionsMenu(menu)
}

searchable.xml

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
    android:hint="@string/honey_where"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:searchSuggestAuthority=
           "com.example.contentProviders.SearchSuggestionProvider"
    android:searchSuggestIntentAction="android.intent.action.VIEW"
    android:searchSuggestThreshold="0"
/>

bottom_nav_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:id="@+id/navigation_locationlist"
    android:iconTint="@color/colorPrimary"
    android:icon="@android:drawable/ic_menu_mapmode"
    android:title="@string/title_locations" />

<item
    android:id="@+id/ItemSearchView"
    android:icon="@drawable/ic_icon"
    android:iconTint="@color/colorAccent"
    android:iconifiedByDefault="false"
    android:queryHint="Search"
    android:theme="@style/AppSearchView"
    android:inputType="textAutoComplete"
    app:actionLayout="@layout/searchview"
    app:showAsAction="always"
    android:title="" />

<item
    android:id="@+id/navigation_settings"
    android:icon="@android:drawable/ic_menu_manage"
    android:title="@string/title_settings" />
</menu>

AndroidManifest.xml

  <provider
        android:name=".contentProviders.SearchSuggestionProvider"
        android:authorities=
            "com.example.contentProviders.SearchSuggestionProvider"
        android:enabled="true"
        android:exported="false"></provider>

   <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme"
        tools:ignore="LockedOrientationActivity">
        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
    </activity>

This is an example of the SearchView working normally after two characters. Touching it shows the weird popup, one character does nothing, two characters it starts acting normal, also this works fine in the emulator: SearchView acting normal

I've tried everything I can think of, but I'm completely stuck on this one. Any help anyone can provide, even just a hint in the right direction, would be most appreciated.

TL;DR I am trying to figure out the source of this popup which is overriding my custom search, knowing this will at least help me look for ways to get rid of it. And if anyone knows how to get rid of it that would be awesome.

UPDATE: May 29, 2020:

I've tried stepping through the SearchView source code to see what is happening, but the "swap" seems to happen after the SearchSuggestion has provided its suggestions. Is there somewhere "deeper" that might be activating here?

As a side note, this is on an OnePlus 6T in case they might have added some sort of custom code.

1

There are 1 answers

0
user2199860 On BEST ANSWER

I was finally able to resolve this by using the following:

searchView.importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS