调用GOOGLE语音

Activity中添加代码 protected void onCreate(Bundle savedInstanceState) { /* 下面是判断当前手机是否支持语音识别功能 */ PackageManager pm = mapIndex.curr.getPackageManager(); List list = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if(list.size()==0) { com.uumap.mapview.Map.tipShow("请安装google语音搜索"); }else{ Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); //设置为当前手机的语言类型 startActivityForResult(intent,REQUEST_CODE); } } 此方法返回搜索结果集合: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode==REQUEST_CODE&&resultCode==RESULT_OK) { try { yylist = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); if (yylist != null && yylist.size() > 0) { getPoiDialog().show(); } } catch (NullPointerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } super.onActivityResult(requestCode, resultCode, data); }

转载于:https://www.cnblogs.com/dive/archive/2012/08/27/2659051.html

你可能感兴趣的:(调用GOOGLE语音)