java - Speech recognition input screen same for all in android -


i have problem android app speech recognition.my problem want show same speech recognition input screen shown jellybean keyboard. if invoke speech recognition intent code, not keep listening , stops prematurely. there must simple way this, can't find it.

here code

package com.bsdcservices.recognitiontest;  import java.util.arraylist; import java.util.locale;  import android.os.bundle; import android.app.activity; import android.content.activitynotfoundexception; import android.content.context; import android.content.intent; import android.speech.recognizerintent; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.view.inputmethod.inputmethodmanager; import android.widget.button; import android.widget.edittext; import android.widget.toast;  public class mainactivity extends activity {  private final string tag = "recognitiontest"; private final int speechrecognition_resultcode = 0; private edittext edittext;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     edittext = (edittext) findviewbyid(r.id.textbox);     button recognize = (button) findviewbyid(r.id.recognize);     recognize.setonclicklistener(buttonclicklistener); }  public onclicklistener buttonclicklistener = new onclicklistener(){      @override     public void onclick(view v) {         startspeechrecognitionactivity();     }  };  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; }  void startspeechrecognitionactivity(){     //      myapplication.speechrecognitionactive = true;     //      main.startspeechrecognizer(tabspeak);     try{         intent intent = new intent(recognizerintent.action_recognize_speech);         intent.putextra(recognizerintent.extra_calling_package, getclass().getpackage().getname());         intent.putextra(recognizerintent.extra_language_model,recognizerintent.language_model_free_form);         intent.putextra(recognizerintent.extra_max_results, 1);         intent.putextra(recognizerintent.extra_language, locale.getdefault().tostring());         startactivityforresult(intent, speechrecognition_resultcode);     } catch (activitynotfoundexception error) {         toast.maketext(getbasecontext(), "speech recognition not supported device" , toast.length_long).show();     } catch( runtimeexception error ) {         toast.maketext(getbasecontext(), error.getmessage() , toast.length_long).show();         error.printstacktrace();     } } protected void onactivityresult(int requestcode, int resultcode, intent data) {     try     {         if (requestcode == speechrecognition_resultcode) {             if (resultcode == result_ok && null != data) {                 arraylist<string> text = data.getstringarraylistextra(recognizerintent.extra_results);                 edittext.append(text.get(0));             }         }     } catch( runtimeexception error ) {         toast.maketext(getbasecontext(), error.getmessage() , toast.length_long).show();         error.printstacktrace();     } } 

}


Comments