I am trying to implement the Ok Google Voice Search integration. However, I am unable to deeplink into my app when I say "Search for Android on app_name." Instead, it simply searches the term on the web.
Here's what I did:
Create /res/xml/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/search_hint"> </searchable>
Create a new Activity
public class ExposedSearchActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String search = getIntent().getStringExtra(SearchManager.QUERY); Log.wtf("", "q=" + search); } }
Attach intent filters to the searchable activity
<activity android:name=".search.ExposedSearchActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:screenOrientation="fullSensor"> <!--Deeplink from google now--> <intent-filter> <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> <!--Making it searchable--> <intent-filter> <action android:name="android.intent.action.SEARCH"/> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/> </activity>
My test device is a Nexus 5 running Lollipop LPX13D with Google Search 4.0.26.1499465.arm
What other steps might I have forgotten? Thanks in advance.