我正在尝试实施Ok Google Voice Search integration。但是,当我说“在app_name上搜索Android”时,我无法深入链接到我的应用。相反,它只是搜索网络上的术语。
这是我做的:
<?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>
public class ExposedSearchActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String search = getIntent().getStringExtra(SearchManager.QUERY);
Log.wtf("", "q=" + search);
}
}
<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>
我可能忘记了哪些其他步骤?提前致谢。
经过大量的搜索,我找到了comment on Google+ by the author of the blog post, Jarek Wilkiewicz的答案。
是的,必须将应用程序发布到Play商店才能使该功能正常运行。帮助调试结束的一种方法是通过adb触发意图,例如:adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query foo
所以我在已经在Play商店中的应用程序上测试了这个功能,它运行完美。
我找到了针对Android应用程序的谷歌语音搜索命令的工作解决方案。
请参阅以下链接以使其有效:
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
正如上面的答案由Some Noob学生列出。我将进一步探讨如何使用调试apk在搜索查询中添加字符串进行测试?
在PC中打开命令提示符,然后更改adb路径的路径。然后执行以下命令。
注意:在执行以下命令之前关闭调试应用程序然后测试。
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