伙计们我想在android中创建一个语音识别应用程序,该应用程序有一个活动,我尝试在我的三星手机上使用Gingerbread OS运行应用程序,当按下语音按钮时显示连接错误,我搜索了以下有关错误Voice Recognition Connection Error的页面,但由于我的清单文件没有{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);
}
}