如何解决我用 Edittext 创建了一个 Serachview 并将麦克风Imagebutton设置为通过语音搜索,但是当麦克风只工作一次时
我的代码
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,"Voice searching...");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,Locale.getDefault());
startActivityForResult(intent,REQUEST_CODE);
}
/**
* Handle the results from the voice recognition activity.
*/
@
Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
{
// Populate the wordsList with the String values the recognition engine thought it heard
final ArrayList< String > matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (!matches.isEmpty())
{
String Query = matches.get(0);
ed.setText(Query);
speak.setEnabled(false);
}
super.onActivityResult(requestCode,resultCode,data);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。