单击按钮时,我有一个语音识别器意图。
voiceSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak Now...");
startActivityForResult(intent, REQUEST_CODE);
}
catch (ActivityNotFoundException e) {
Log.v("Speech", "Could not find any Speech Recognition Actions");
}
}
});
在活动结果上,我的代码为
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("Request code++++++++++++++++++++++++++++"+requestCode);
System.out.println("Result Code+++++++++++++++++++++++++++++"+resultCode);
System.out.println("Data++++++++++++++++++++++++++++++++++++"+data);
System.out.println("Language"+data.getStringExtra(RecognizerIntent.EXTRA_LANGUAGE));
System.out.println("data.getDataString()"+data.getDataString());
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
if (data != null && data.getData() != null) {
String searchKey = data.getData().toString();
System.out.println("Search Key++++++++++++++++++++++++"+searchKey);
searchEditText.setText(searchKey);
webView.loadUrl(url+"searchKey");
}
}
}
我得到的输出是当我打印onActivityResult
时
我得到的请求代码1
我得到的结果代码-1
我得到的数据Intent { (has extras) }
语言data.getStringExtra(RecognizerIntent.EXTRA_LANGUAGE)
为null
.
Data.getDataString()
作为null
.
任何人都可以让我知道我在代码中可能出现的问题。
谢谢。