How to connect OK Google voice queries to my app

折月煮酒 提交于 2019-12-21 21:39:09

问题


I want to my app to react to voice queries. I have setup "Ok Google" properly as described here.

It is working fine, but it does not seem to be connected to my app. Instead of opening my app it just performs a regular search!


回答1:


If you have a searchable Activity as described here then you just need to add these two lines to the <intent-filter /> tag of your Activity in your manifest:

<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>

After that you will receive the SEARCH_ACTION Intent in your app which you can handle just like the normal search Intent. You can access the query by getting the String extra with the key SearchManager.QUERY from the Intent.

But your users need to specify the app name in the verbal query for the Intent to reach your app! For example:

Ok Google, search [query] on [your app name]


You can find more information in the blog post here.



来源:https://stackoverflow.com/questions/30140594/how-to-connect-ok-google-voice-queries-to-my-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!