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:
When you click on an app in the Android Wear, this is logged:
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.wearable.compass/.MainActivity} from uid 10002 on display 0
The difference is the cat
or category
parameter which includes android.intent.category.LAUNCHER
as a value.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With