package ee.ioc.phon.android.speak.demo; import android.app.Activity; import android.content.Context; import android.os.Build; import android.os.Bundle; import android.webkit.JavascriptInterface; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.Toast; import ee.ioc.phon.android.speak.R; public class FormDemoActivity extends Activity { public class WebAppInterface { Context mContext; /** * Instantiate the interface and set the context */ WebAppInterface(Context c) { mContext = c; } /** * Show a toast from the web page */ @JavascriptInterface public void showToast(String toast) { Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WebView webview = new WebView(this); setContentView(webview); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); // addJavascriptInterface has security issues below API 17 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { webview.addJavascriptInterface(new WebAppInterface(this), "Android"); } webview.loadUrl(getString(R.string.fileFormDemo)); } }