简体   繁体   English

从谷歌搜索或语音输入开始活动

[英]Start activity from google search or voice input

Task: do something in my app by command from android wear watch by speaking command. 任务:在我的应用程序中执行某些操作,通过android命令通过说出命令。 It the same as send command from google search (by speaking or writing command). 它与谷歌搜索发送命令相同(通过说或写命令)。

How-to described at http://developer.android.com/training/wearables/apps/voice.html "Declare App-provided Voice Actions" 如何在http://developer.android.com/training/wearables/apps/voice.html “声明应用提供的语音操作”中进行描述

I created two activities: 我创建了两个活动:

    <activity
        android:name=".MainActivity"
        android:label="speech test main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".SomeAction"
        android:label="speech test action" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Both activities can be launched from google search by command "start [android:label for activity]". 这两项活动都可以通过命令“start [android:label for activity]”从谷歌搜索启动。 Then I can do corresponding action at onResume(). 然后我可以在onResume()上做相应的动作。

But at system launcher icon is created for each activity! 但是在系统启动器图标是为每个活动创建的! I tried to change category to DEFAULT, icon disappears, but activity cannot be launched from google search. 我尝试将类别更改为DEFAULT,图标消失,但无法从Google搜索启动活动。 Seems to be google search can launch activities with LAUNCHER category only. 似乎是谷歌搜索只能启动与LAUNCHER类别的活动。

So, need to launch activity (or just send intent, if possible) from google search. 因此,需要从谷歌搜索启动活动(或只是发送意图,如果可能)。 Problem - extra icons on launcher. 问题 - 发射器上的额外图标。

You cannot use <action android:name="android.intent.action.LAUNCHER" /> twice because that would give 2 launch icons. 你不能两次使用<action android:name="android.intent.action.LAUNCHER" />因为这会产生2个启动图标。 Also, remove <category android:name="android.intent.category.DEFAULT" /> from both activities. 另外,从两个活动中删除<category android:name="android.intent.category.DEFAULT" /> Instead, just focus on having only one main launcher activity where the getIntent() is called, then resend whatever intent/extras/flags/other data that came with the intent into your second activity if necessary. 相反,只关注只有一个主要的启动器活动,其中调用了getIntent() ,然后在必要时将意图附带的任何intent / extras / flags /其他数据重新发送到第二个活动中。 Alternatively, process the intent in the main launcher activity, then call another method in the second activity. 或者,在主启动器活动中处理意图,然后在第二个活动中调用另一个方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM