【发布时间】:2015-01-14 22:52:18
【问题描述】:
我正在尝试实现Ok Google Voice Search integration。但是,当我说“在 app_name 上搜索 Android”时,我无法深度链接到我的应用。相反,它只是在网络上搜索该词。
这就是我所做的:
-
创建/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> -
创建一个新的活动
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> 我的测试设备是运行 Lollipop LPX13D 和 Google Search 4.0.26.1499465.arm 的 Nexus 5
我可能忘记了哪些其他步骤?提前致谢。
【问题讨论】:
-
@1,感谢您的意见。不幸的是,我尝试了这两种方法都无济于事。 T___T
-
@SomeNoobStudent 您的应用是否在 Play 商店中发布?它需要在该功能起作用之前。
-
@4,确实!那是缺失的环节。看来我们目前只能通过 adb 命令进行测试。
-
我喜欢 Log.wtf() 非常有帮助:)