【发布时间】:2012-05-15 09:58:07
【问题描述】:
我正在尝试从我的 web 视图中的 javascript 界面启动一项活动。 该示例显示吐司。我怎么能叫班级而不是敬酒呢?
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
这个用于 html 页面。
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
【问题讨论】:
-
我没有足够的经验来回答,但你读过这个吗:developer.android.com/guide/webapps/…
-
好吧,我只是没有看到你在 webview 中启用了 javascript 的任何地方,尽管它是相关的。
-
你没有得到我的问题,我想调用一个意图而不是敬酒。我已经使敬酒的示例起作用了。还是谢谢
-
我想在没有任何 webview 的情况下这样做。只是在内部是可能的。
标签: javascript android webview