如何搜索活动后单击确定谷歌语音搜索整合? [英] How to integrate searchable Activity with Ok Google voice search?

查看:199
本文介绍了如何搜索活动后单击确定谷歌语音搜索整合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现的好了谷歌语音搜索整合。但是,我无法deeplink到我的应用程序,当我说搜索为Android上APP_NAME。相反,它只是搜索网络上的术语。

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>
    

  • 我的测试设备是一台Nexus 5运行棒棒糖LPX13D与谷歌搜索4.0.26.1499465.arm

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

    推荐答案

    经过大量的搜索,我找到了答案中的通过博客文章的作者在Google+上发表评论,亚雷克Wilkiewicz

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

    应用程序必须发布到Play商店为了使   功能工作。帮助您的最终调试的方法之一是触发   通过亚行的意图,例如:亚行外壳上午开始-a   com.google.android.gms.actions.SEARCH_ACTION -e查询富

    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.

    这篇关于如何搜索活动后单击确定谷歌语音搜索整合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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