如何将可搜索活动与 Ok Google 语音搜索集成? [英] How to integrate searchable Activity with Ok Google voice search?

查看:20
本文介绍了如何将可搜索活动与 Ok Google 语音搜索集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施 Ok Google 语音搜索集成.但是,当我说在 app_name 上搜索 Android"时,我无法深层链接到我的应用.相反,它只是在网络上搜索该字词.

I am trying to implement the Ok Google Voice Search integration. However, I am unable to deeplink into my app when I say "Search for Android on app_name." Instead, it simply searches the term on the web.

这是我所做的:

  1. 创建/res/xml/searchable.xml

  1. Create /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>

  • 创建一个新的活动

  • 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);
        }
    }
    

  • 将意图过滤器附加到可搜索活动

  • 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>
    

  • 我的测试设备是运行 Lollipop LPX13D 和 Google Search 4.0.26.1499465.arm 的 Nexus 5

  • My test device is a Nexus 5 running Lollipop LPX13D with Google Search 4.0.26.1499465.arm

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

    What other steps might I have forgotten? Thanks in advance.

    推荐答案

    经过大量搜索,我在 博文作者 Jarek Wilkiewicz 对 Google+ 的评论.

    After lots of searching, I have found the answer in a comment on Google+ by the author of the blog post, Jarek Wilkiewicz.

    是的,应用必须发布到 Play 商店功能来工作.帮助调试结束的一种方法是触发意图通过 adb,例如: adb shell am start -acom.google.android.gms.actions.SEARCH_ACTION -e 查询 foo

    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 商店中已有的应用上测试了此功能,并且运行良好.

    So I tested this feature on an app that is already in the Play Store, and it works flawlessly.

    这篇关于如何将可搜索活动与 Ok Google 语音搜索集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆