Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate searchable Activity with Ok Google voice search?

Tags:

android

search

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:

  1. 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>
    
  2. 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);
        }
    }
    
  3. 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>
    
  4. 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.

like image 734
Some Noob Student Avatar asked Nov 17 '14 21:11

Some Noob Student


People also ask

What is hands free searching using Google voice?

Turn On Voice Access. Google's Voice Access feature improves accessibility by allowing you to navigate your phone, open and use apps, and enter text just by using your voice.

Why Google Voice Search is not supported on your device?

Basically you are saying that Google voice search is not working on your device. Open the Google app and then its main menu, then go to Settings > Voice (under search) > "Voice Match" detection. From there, toggle the feature on. Hope it helps.


1 Answers

I have found working solution for this google voice search commands for our Android Application.

Refer below links to make it works:

1) https://gist.github.com/raveeshbhalla/186325d1bb25d13bd7a0

2) https://github.com/google/search-samples/issues/24

3) https://antonioleiva.com/voice_search_google_now/

4) https://developers.google.com/voice-actions/system/

5) https://developer.android.com/guide/components/intents-common#java

As the above answer listed by Some Noob Student. i am going further for how to test it with debug apk with adding String in search query?

Open command prompt in your PC then change path to your adb path. then execute below commands.

Note: before executing below commands close your debug app then test.

1) adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query app_package_name

2)adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query "Hello" app_package_name

like image 69
viral 9966 Avatar answered Oct 11 '22 08:10

viral 9966