伙计们,我正在尝试在 android 中制作语音识别应用程序,该应用程序有一个活动,我尝试在带有 Gingerbread OS 的三星手机上运行该应用程序,当按下语音按钮时显示连接错误,我搜索了以下页面关于错误语音识别连接错误,但它没有帮助,因为我的清单文件没有{ android:launchMode“singleTask”}代码如下所示。请帮助我。
package com.code.voice;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
public class VoiceActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button b;
ListView lv;
static final int check = 1111;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b = (Button)findViewById(R.id.bPress);
lv = (ListView)findViewById(R.id.lvReturnVoice);
b.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "You may begin ");
startActivityForResult(i, check);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode == check && resultCode == RESULT_OK)
{
ArrayList <String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results));
}
super.onActivityResult(requestCode, resultCode, data);
}
}