使用Google即时语音搜索无法获取活动中所说的确切文字

时间:2018-11-09 10:39:16

标签: android google-now google-voice-search google-voice-actions

我将google now语音搜索集成到我的Android应用程序中。在这里,我会说“ Ok Google”来启动Google协助,它将监听我的自定义命令。然后,该帮助会将口头文字与使用操作进行的活动进行匹配:

  

com.google.android.gms.actions.SEARCH_ACTION

我的AndroidManifest的摘录:

 <activity android:name=".activities.GActivity"
        android:launchMode="singleTask">
        <intent-filter>
            <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>

然后在我的活动中,我检查动作和用户说的文字。像这样:

 import com.google.android.gms.actions.SearchIntents;

 public class GActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_g);

    // Get the intent
    Intent intent = getIntent();
    if (SearchIntents.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        Toast.makeText(this,
                query, Toast.LENGTH_SHORT).show();
    }

}
}

然后,在终端上,我使用以下命令触发了将要说出的示例文本的意图动作(在开发环境中,因为语音帮助仅在发布后才起作用)。

 adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION \
 --e query "TextToBeSpoken" my.package.name

我点击了android上的此链接

Support search queries from Google Voice Actions

Use Voice Search to integrate with Google Now

问题是我从终端发出命令后,我的活动成功启动,但是我无法从intent对象获取口头文字,该内容始终为空。

 String query = intent.getStringExtra(SearchManager.QUERY);

谁能告诉我上面的行为什么返回null?有任何解决方法吗?

0 个答案:

没有答案
相关问题