android - 如何通过说 OK Google 来启动特定 Activity ?

标签 android wear-os google-voice google-voice-actions

我想有两个 Activity 。 FirstActivity 应该从 启动器(通过点击图标)和 SecondActivity 应该通过语音启动 命令(通过说“OK Google,开始播放示例”)。

问题是对于我当前的配置只有 FirstActivity 是 开始了。此外,方法 isVoiceInteraction 返回 false。我也没有在 flags 中看到任何表明 Activity 是由语音启动的值。

这是 AndroidManifest.xml 的一部分:

<application android:label="play example">
    <activity android:name="com.example.FirstActivity" android:label="play example">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.example.EXAMPLE_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity android:name="com.example.SecondActivity" android:label="play example">
        <intent-filter>
            <action android:name="com.example.EXAMPLE_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.VOICE" />
        </intent-filter>
    </activity>
</application>

Here它指出:

To specify the text to say after "Start", specify a label attribute for the activtiy that you want to start.

但是当我为 SecondActivity 更改 label 时,它没有帮助。

我使用的是 API 版本 26。

如何设置配置来处理描述的行为?

最佳答案

AFAIK isVoiceInteraction 在使用“打开”语音命令打开应用程序时将始终返回 false。但是,您描述的场景应该可以实现另一个 Activity 来响应语音命令。

您唯一可能错过的是将操作 android.intent.action.MAIN 放在第二个 Activity 中。

关于android - 如何通过说 OK Google 来启动特定 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47403468/

相关文章:

android - CSS 和 JavaScript 在 Android WebView 中不起作用

android - 所有的安卓设备都有不可移动的外部存储吗?

python - 从 Python 中的字符串中删除引号

java - Google Voice 接收新来电通知

android - 根据两个或多个 EditText 字段中的输入启用/禁用按钮的优雅方式

每次 ScrollView 时,Android 将图像从 url 加载到 listView 中

android - 安装已签名的 APK 不会在 Android Wear 上安装应用

android - Android Wear 5.1.1 是否支持直接互联网连接?

android - 使用 DataMap 发送和接收数据 - Android 可穿戴设备

firebase - Google 版本的 amazon lex