i have a problem to start the speechRecognition using javascriptInterface. In this case, i have a button in my html page and when i click that button then the speechRecognition should startListening but when i clicked that nothing happen... can anyone explain why?
here the code i'm using :
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new listener());
WebView webView = (WebView) findViewById(R.id.webView1);
initWebView(webView);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
webView.loadUrl("file:///android_asset/index.html");
}
my javascriptInterface class
class WebAppInterface{
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void startListening(){
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"com.domain.package");
sr.startListening(intent);
}
}
0 comments:
Post a Comment