In the Google CodeLabs example for the Voice Interaction API, an activity is defined with the following intent filter (see step 6):
<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
When using the "OK Google, take a selfie" voice command, the intent is fired with the android.intent.category.VOICE
category. This is shown in LogCat as:
02-26 15:32:42.423 779-6923/? I/ActivityManager: START u0 {act=android.media.action.STILL_IMAGE_CAMERA cat=[android.intent.category.VOICE] flg=0x18000000 pkg=com.example.android.voicecamera cmp=com.example.android.voicecamera/.TakePictureActivity (has extras)} from uid 10027 on display 0
In my own app, I have added the following intent filter to my voice-searchable Activity:
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
However, if I give the "OK Google, search for computers on [my app]", the voice category does not get added to the intent:
02-26 16:17:26.722 779-14786/? I/ActivityManager: START u0 {act=com.google.android.gms.actions.SEARCH_ACTION pkg=com.my.pkg cmp=com.my.pkg/.activity.VoiceSearchActivity (has extras)} from uid 10027 on display 0
Because this category is not set correctly in the Intent, Activity.isVoiceInteraction()
and Activity.isVoiceInteractionRoot()
are both returning false
.
Can anyone explain why this might be happening?
Thanks!
来源:https://stackoverflow.com/questions/35642854/ok-google-search-actions-causes-isvoiceinteraction-to-always-return-false