Start activity from google search or voice input

1.6k views Asked by At

Task: do something in my app by command from android wear watch by speaking command. It the same as send command from google search (by speaking or writing command).

How-to described at http://developer.android.com/training/wearables/apps/voice.html "Declare App-provided Voice Actions"

I created two activities:

    <activity
        android:name=".MainActivity"
        android:label="speech test main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".SomeAction"
        android:label="speech test action" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Both activities can be launched from google search by command "start [android:label for activity]". Then I can do corresponding action at onResume().

But at system launcher icon is created for each activity! I tried to change category to DEFAULT, icon disappears, but activity cannot be launched from google search. Seems to be google search can launch activities with LAUNCHER category only.

So, need to launch activity (or just send intent, if possible) from google search. Problem - extra icons on launcher.

1

There are 1 answers

0
jackson95 On

You cannot use <action android:name="android.intent.action.LAUNCHER" /> twice because that would give 2 launch icons. Also, remove <category android:name="android.intent.category.DEFAULT" /> from both activities. Instead, just focus on having only one main launcher activity where the getIntent() is called, then resend whatever intent/extras/flags/other data that came with the intent into your second activity if necessary. Alternatively, process the intent in the main launcher activity, then call another method in the second activity.