android - how to open an activity from a speech to text output -
here code:
public void promptspeechinput(){ intent = new intent(recognizerintent.action_recognize_speech); i.putextra(recognizerintent.extra_language_model, recognizerintent.language_model_free_form); i.putextra(recognizerintent.extra_language, locale.getdefault()); i.putextra(recognizerintent.extra_prompt, "say something!"); try{ startactivityforresult(i, 100); } catch(activitynotfoundexception a){ toast.maketext(voicesearch.this, "sorry! device doesn't support speech language!", toast.length_long).show(); } } public void onactivityresult(int request_code, int result_code, intent i){ super.onactivityresult(request_code,result_code,i); switch(request_code){ case 100: if(result_code == result_ok && != null){ arraylist<string> result = i.getstringarraylistextra(recognizerintent.extra_results); resulttext.settext(result.get(1)); string text = string.valueof(result); toast.maketext(getapplicationcontext(),text, toast.length_long).show(); if (text.equals("speedometer") ){ getwindow().setexittransition(new explode()); intent intent = new intent(getapplicationcontext(), speedometertest.class); startactivity(intent, activityoptions.makescenetransitionanimation(this).tobundle()); } } break; } }
and don't know if 'if' statement working!
string s = result.get(0); if (s.equals("speedometer") ){ intent intent = new intent(getapplicationcontext(), speedometertest.class); startactivity(intent, activityoptions.makescenetransitionanimation(this).tobundle()); }
hope works.
Comments
Post a Comment