我有一个开发为在谷歌玻璃上运行的安卓应用程序。我使用 adb 运行它。是否可以配置语音命令,以便我可以通过说“Ok GLASS”+“我的命令”来触发它?
4 回答
更新 - XE16 更新后以下方法不起作用,新的解决方案在这里为什么 XE16 中的 ok glass 菜单中缺少我的语音命令?
你要做的是,
在清单文件中,在您希望通过语音命令触发的服务下添加这些标签。
<intent-filter> <action android:name="com.google.android.glass.action.VOICE_TRIGGER" /> </intent-filter> <meta-data android:name="com.google.android.glass.VoiceTrigger" android:resource="@xml/voice_trigger_start" />
您必须在 res 中创建一个名为 xml 的文件夹,并添加一个名为 .xml 的 xml 文件
voice_trigger_start.xml
。在里面添加这些行
<?xml version="1.0" encoding="utf-8"?> <trigger keyword="@string/its_me_amalan" />
打开文件夹内的 values 文件
res
夹并编辑strings.xml
,它看起来像这样<resources> <string name="app_name">Amalan</string> <string name="its_me_amalan">Hello Amalan</string> <string name="stop">Stop</string> </resources>
现在将应用程序安装到 Glass 上并说“ ok glass, Hello Amalan ”,应用程序就会打开。
参考: http: //pathofacoder.com/2013/11/20/google-glass-adding-your-own-voice-commands-to-your-apps/
昨天,谷歌发布了 XE12 固件更新,这让我们在所有自定义启动器上都遇到了麻烦。Launcher2.apk 和 Launchy 都停止为我工作,因此作为一种解决方法,我实施了一种方法,该方法也很好地回答了您的问题。看看这个页面http://divingintoglass.blogspot.com/
我在此提交中为使用 GDK 开发的 Glassware 应用程序执行了此操作: https ://github.com/luisdelarosa/HelloGlass/commit/c5038ed2ff019306becb32211354358833b6fafc
以下是该提交的逐步内容:
修改 AndroidManifest.xml 以在要通过语音启动的 Activity 或 Service 中添加 VoiceTrigger Intent。请注意,您也可以选择删除 Launcher Intent,因为 Glass 不像传统 Android 那样使用这些 Intent。
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/glass_voice_trigger" />
添加 VoiceTrigger 意图引用的 VoiceTrigger XML,其中应包含您希望用户激活您的应用程序的字符串。在这种情况下,我们称之为 res/xml/glass_voice_trigger.xml
<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/glass_voice_trigger"/>
或者,将上一步中的字符串放入 strings.xml 文件中。(您也可以将该字符串硬编码到 VoiceTrigger XML 中,作为触发器节点的关键字属性的值。)在这种情况下,它位于 res/values/strings.xml,我们的触发器是“say hello”。将此字符串替换为您希望用户说什么来启动您的应用程序。
<string name="glass_voice_trigger">say hello</string>
不要忘记使用 XE16 以来的权限:
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />