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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With