检测穿戴应用是否以语音命令或触摸输入启动 [英] detect whether wear app started with voice command or touch input
问题描述
在我的穿戴应用中,我想根据是通过语音命令还是通过触摸输入启动应用来显示不同的布局选项.但是我找不到在文档中执行此操作的任何方法.
In my wear app I would like to show different layout options based on whether app is started via a voice command or via a touch input. But I could not find any way to do this in docs.
我想到的唯一可能的方法是拥有两个发射器.但是,我正在寻找一种相当直接的解决方案,而不是创建多个启动器.
The only possible way I can think of is to have two launchers. But I am looking for rather direct solution than creating multiple launchers.
推荐答案
稍微检查一下活动日志后,我发现:
After checking the activity log a bit, I found this:
当您在Android Wear中单击某个应用时,将记录以下内容:
When you click on an app in the Android Wear, this is logged:
I/ActivityManager(446):从显示0的uid 10002开始u0 {act = android.intent.action.MAIN flg = 0x10000000 cmp = com.lge.wearable.compass/.MainActivity}
I/ActivityManager(446): START u0 {act=android.intent.action.MAIN flg=0x10000000 cmp=com.lge.wearable.compass/.MainActivity} from uid 10002 on display 0
使用语音命令启动应用程序时,将记录以下内容:
When you start the app with a voice command, this is logged:
I/ActivityManager(446):START u0 {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] flg = 0x10008000 pkg = com.lge.wearable.compass cmp = com.lge显示0的uid 10002中的.wearable.compass/.MainActivity}
I/ActivityManager(446): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10008000 pkg=com.lge.wearable.compass cmp=com.lge.wearable.compass/.MainActivity} from uid 10002 on display 0
区别是 cat
或 category
参数,其中包含 android.intent.category.LAUNCHER
作为值.
The difference is the cat
or category
parameter which includes android.intent.category.LAUNCHER
as a value.
onCreate
函数中的以下代码将区分应用是通过语音启动还是通过用户轻按来启动.
The following code in the onCreate
function will differentiate whether the app is started with voice or by a user tap.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
....
Set<String> categories = getIntent().getCategories();
if(categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) {
Log.i(LOGTAG, "app started via voice");
}else{
Log.i(LOGTAG, "app started with user tap");
}
....
}
这目前适用于我的应用程序场景,希望它也适用于其他应用程序.
This currently works for my app scenario and hope it works for others too.
这篇关于检测穿戴应用是否以语音命令或触摸输入启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!