I am trying to implement the 'Search using a specific app' functionality as per the android documentation. But I am unable to get it working. This is my query 'Ok google, search for xyz on helloapp'
Following is my implementation. I have added meta data which is not required, but did not work without it either.
Implementation
Manifest
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
</activity>
<activity
android:name=".SearchableActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:value=".SearchableActivity" />
</activity>
Searchable Activity
public class SearchableActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchlayout);
Intent intent = getIntent();
if(SearchIntents.ACTION_SEARCH.equals(intent.getAction())){
String query = intent.getStringExtra(SearchManager.QUERY);
Toast.makeText(getApplicationContext(), query, Toast.LENGTH_LONG).show();
}
}
}