如何启用Android Open Application语音交互 [英] How to enable Android Open Application voice interaction
问题描述
根据系统语音命令文档,您可以使用语音命令打开应用程序.例如OK Google - open foobar
.同样根据文档,此默认情况下有效;没有具体意图.
在我的示例开发应用程序中,这不起作用.我尝试将一些动作和类别排列组合添加到意图过滤器中,但到目前为止还没有运气.
我的目标是最低SDK为23,并在使用6.0.1的设备上进行测试.
According to the system voice command docs, you can open an application with a voice command. e.g. OK Google - open foobar
. Also according to the docs, this Works by default; no specific intent.
In my sample development app, this isn't working. I've tried adding a few combinations of action and category permutations to the intent-filter, but no luck so far.
I'm targeting a minimum SDK of 23, testing on a device with 6.0.1.
这项工作是否可行,如果可以的话,我需要启用一个新的空活动项目吗?
Should this work, and if so, what are the changes to a new empty activity project I need to enable it?
推荐答案
据我所知,Google会简单地遍历已安装的应用程序列表,并在找到完全匹配时打开相应的应用程序.
As far as I am aware, Google simply iterates over a list of installed applications and opens the corresponding application if it finds an exact match.
要对此进行测试,请使用以下意图
To test this, use the following Intent
final String PACKAGE_NAME_GOOGLE_NOW = "com.google.android.googlequicksearchbox";
final String GOOGLE_NOW_SEARCH_ACTIVITY = ".SearchActivity";
final String APP_NAME = "Open " +getString(R.string.app_name);
final Intent startMyAppIntent = new Intent(Intent.ACTION_WEB_SEARCH);
startMyAppIntent.setComponent(new ComponentName(PACKAGE_NAME_GOOGLE_NOW,
PACKAGE_NAME_GOOGLE_NOW + GOOGLE_NOW_SEARCH_ACTIVITY));
startMyAppIntent.putExtra(SearchManager.QUERY, APP_NAME);
startMyAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(startMyAppIntent);
} catch (final ActivityNotFoundException e) {
e.printStackTrace();
}
如果这会打开您的应用程序,则仅是您的应用程序名称的语音或Google解释您的发音的一种情况.
If this opens your application, then it is simply a case of the phonetics of your application name, or how Google interprets your pronunciation of it.
我确实认为应该有一个选项可以在应用程序的清单(或其他一些全球可用的配置文件)中添加语音应用程序标签",这样,如果唯一名称不够通用就无法生成,Google可以打开您的应用程序语音搜索结果.
I do think that there should be an option to add a 'phonetic app label' to the application's manifest (or some other globally available configuration file), so Google could open your application if the unique name is not common enough to generate a voice search result.
如果这不能打开您的应用程序,请检查您是否在清单中正确定义了应用程序名称,如下所示:
If this doesn't open your application, check that you are correctly defining your application name in the manifest as follows:
<application
android:label="@string/app_name"
这篇关于如何启用Android Open Application语音交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!