То, что я хотел бы, чтобы общаться с HTML внутри веб-просмотра, что событие сделано
WebView web = (WebView) findViewById(R.id.view1);
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
web.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
}
});
web.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
});
web.getSettings().setJavaScriptEnabled(true);
web.addJavascriptInterface(new WebAppInterface(this,this), "Android");
web.loadUrl(MyUrl);
public class WebAppInterface {
Context mContext;
Activity mActivity;
/** Instantiate the interface and set the context */
WebAppInterface(Context c, Activity a) {
mContext = c;
mActivity = a;
}
/** Show a toast from the web page */
@JavascriptInterface
public void Method1(String str) {
//Started, event ended
return "Alert me in javaScript";
}
}
javascript
function JavaScriptStartAndroidMethod1(){
Android.method1(String str);
}
Я хотел бы, чтобы HTML получил ответ отМетод интерфейса 1 ()