如果我理解你的问题,你可以使用JavaScript接口。
您应该创建类是这样的:
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();
}
}
这之后,您应在该接口连接到您的WebView这样的:
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
现在你可以从JS调用Java这样的代码:
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
或者像这样调用Java的JS代码:
webview.loadUrl("javascript:window.showAndroidToast(\"Hello, World!\")");
更多信息,请访问:https://developer.android.com/guide/webapps/webview.html
日Thnx的答复,但我面临的问题是如何自动刷新网页。移动应用程序也可以被另一个网页取代。 – KshitishSC
哦...对不起...我没有看标签,想过Android! –