After checking the activity log, I found the following:
When you click on an app in Android Wear, it logs in:
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 launch the application using 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 lies in the cat or category parameter, which includes android.intent.category.LAUNCHER as the value.
The following code in the onCreate function will distinguish whether the application is launched by voice or by pressing a button.
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 application script and hope it works for others as well.
source share