0

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();
        }

    }

}
Arun Abraham
  • 4,011
  • 14
  • 54
  • 75
  • I just read in http://stackoverflow.com/questions/26982653/how-to-integrate-searchable-activity-with-ok-google-voice-search that the app needs to be published to app store for the functionality to work. – Arun Abraham Jun 22 '15 at 05:00

1 Answers1

2

Figured out from this post, that the app has to be published first for the functionality to work. However, we can emulate this with the following adb shell command

adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query 'search for xyz on..' packagename
Community
  • 1
  • 1
Arun Abraham
  • 4,011
  • 14
  • 54
  • 75