简体   繁体   English

如何将可搜索的活动与Ok Google语音搜索集成?

[英]How to integrate searchable Activity with Ok Google voice search?

I am trying to implement the Ok Google Voice Search integration . 我正在尝试实施Ok Google Voice Search集成 However, I am unable to deeplink into my app when I say "Search for Android on app_name." 但是,当我说“在app_name上搜索Android”时,我无法深入链接到我的应用。 Instead, it simply searches the term on the web. 相反,它只是搜索网络上的术语。

Here's what I did: 这是我做的:

  1. Create /res/xml/searchable.xml 创建/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 我的测试设备是运行Lollipop LPX13D的Nexus 5,带有谷歌搜索4.0.26.1499465.arm

What other steps might I have forgotten? 我可能忘记了哪些其他步骤? Thanks in advance. 提前致谢。

After lots of searching, I have found the answer in a comment on Google+ by the author of the blog post, Jarek Wilkiewicz . 经过大量搜索后,我在博客文章作者Jarek Wilkiewicz评论中找到了答案。

Yes, the app must be published to the Play Store in order for the feature to work. 是的, 必须将应用程序发布到Play商店才能使该功能正常运行。 One way to help debug your end is to trigger the intent via adb, for example: adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query foo 帮助调试结束的一种方法是通过adb触发意图,例如:adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query foo

So I tested this feature on an app that is already in the Play Store, and it works flawlessly. 所以我在已经在Play商店中的应用程序上测试了这个功能,它运行完美。

I have found working solution for this google voice search commands for our Android Application. 我找到了针对Android应用程序的谷歌语音搜索命令的工作解决方案。

Refer below links to make it works: 请参阅以下链接以使其有效:

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

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

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

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

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

As the above answer listed by Some Noob Student . 正如上面的答案由Some Noob学生列出。 i am going further for how to test it with debug apk with adding String in search query? 我将进一步探讨如何使用调试apk在搜索查询中添加字符串进行测试?

Open command prompt in your PC then change path to your adb path. 在PC中打开命令提示符,然后更改adb路径的路径。 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 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 2)adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query“Hello”app_package_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM