gpt4 book ai didi

android - 如何将可搜索 Activity 与 Ok Google 语音搜索集成?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:57:55 36 4
gpt4 key购买 nike

我正在尝试实现 Ok Google Voice Search integration .但是,当我说“在 app_name 上搜索 Android”时,我无法深入链接到我的应用程序。相反,它只是在网络上搜索该术语。

这是我做的:

  1. 创建/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. 创建一个新 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. 将 Intent 过滤器附加到可搜索 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. 我的测试设备是运行 Lollipop LPX13D 和 Google Search 4.0.26.1499465.arm 的 Nexus 5

我可能忘记了哪些其他步骤?提前致谢。

最佳答案

经过大量搜索,我在 comment on Google+ by the author of the blog post, Jarek Wilkiewicz 中找到了答案.

Yes, the app must be published to the Play Store in order for the feature to work. 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

因此,我在 Play 商店中已有的应用程序上测试了此功能,它可以完美运行。

关于android - 如何将可搜索 Activity 与 Ok Google 语音搜索集成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26982653/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com