Sam*_*rsh 11 android google-voice-actions
在语音交互API的Google CodeLabs示例中,使用以下intent过滤器定义了一个活动(请参阅步骤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>
Run Code Online (Sandbox Code Playgroud)
当使用"OK Google,采取自拍"语音命令时,会使用该android.intent.category.VOICE类别触发意图.这在LogCat中显示为:
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
Run Code Online (Sandbox Code Playgroud)
在我自己的应用程序中,我已将以下intent过滤器添加到我的语音搜索活动中:
<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>
Run Code Online (Sandbox Code Playgroud)
但是,如果我提供"确定Google,在[我的应用]上搜索计算机",则语音类别不会添加到意图中:
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
Run Code Online (Sandbox Code Playgroud)
因为此类别未在Intent中正确设置,Activity.isVoiceInteraction()并且Activity.isVoiceInteractionRoot()都返回false.
任何人都可以解释为什么会发生这种情况?
谢谢!
| 归档时间: |
|
| 查看次数: |
1028 次 |
| 最近记录: |