这个代码是我在网上拷的,我运行的时候一直提示找不到设备,请各位大侠帮忙看看package com.listen;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;public class listenActivity extends Activity {
/** Called when the activity is first created. */
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try
{
//通过Intent传递语音识别的模式,开启语音
Intent intent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//语言模式和自由模式的语音识别
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//提示语音开始
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "开始语音");
//开始语音识别
System.out.println("开始语音");
startActivityForResult(intent,VOICE_RECOGNITION_REQUEST_CODE);
System.out.println("执行完毕");
}catch(Exception ex){
ex.printStackTrace();
Toast.makeText(getApplicationContext(), "找不到语音设备", 1).show();
}
}
});
}
}
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;public class listenActivity extends Activity {
/** Called when the activity is first created. */
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try
{
//通过Intent传递语音识别的模式,开启语音
Intent intent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//语言模式和自由模式的语音识别
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//提示语音开始
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "开始语音");
//开始语音识别
System.out.println("开始语音");
startActivityForResult(intent,VOICE_RECOGNITION_REQUEST_CODE);
System.out.println("执行完毕");
}catch(Exception ex){
ex.printStackTrace();
Toast.makeText(getApplicationContext(), "找不到语音设备", 1).show();
}
}
});
}
}
解决方案 »
- Andriod调用SQLite数据库的问题
- ubuntu下安装repo下载源码,找不到repo命令
- NDK方式下openGL绑定纹理出错
- 通过time获取的系统时间为何总是197001000(格式:年月日时分秒)?
- android 能作屏幕录像吗?
- android在线播放mv的问题
- 请教:乐Phone手机如何把自己的程序切入后台
- [终于解决]eclipse3.6中android自动补全/提示卡机或假死
- 才踏入android开发之路,教材求辨别,求解答!
- 非技术问题:android方面,新人转正时,开发个什么apk比较合适?
- drawable-ldpi 内存泄露问题
- android 端使用zxing 扫描sdcard中的二维码图片的方法是什么?
List<ResolveInfo> list = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if(list.size() == 0) {
btn.setText("当前语音识别设备不可用...");
}
楼主在发送那个意图前,先加上这个逻辑,看看是不是你手机不支持语音识别。