将数据从java类传递到Web View html [英] Passing data from java class to Web View html

查看:27
本文介绍了将数据从java类传递到Web View html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的 webView

@mail.25c0c425c6&安培;图= ATT&安培; TH = 138db54ff27ad34b&安培; attid = 0.1&安培; DISP =直列&安培; realattid = f_h5ahtmbe0&安培;安全= 1&安培; ZW&安培; saduie = AG9B_P9YNooGjsk_jLefLptQ9q15&安培; sadet = 1343790299575&安培; SADS = -yBVsLKP_2mh7zMfYLCF7sL1u-W

现在我想做的是填充来自我的java类变量的html中的文本框,然后自动点击提交.

Now what I want to do is to fill the textbox in the html that came from my java class variable and then automatically hit submit.

但我不知道该怎么做.

任何想法将不胜感激.

推荐答案

首先,您的 URL 似乎不可用.

First, your URL seems not available.

如果你想在安卓应用和你的网络应用/网页之间进行数据交换,你可以通过javascript来实现.

If you want to do data exchange between android app and your web app/web page you can achieve this via javascript.

以下是来自 Android 官方网站的示例:

Here is an example from Android official site:

创建一个这样的类:

public class JavaScriptInterface {
    Context mContext;

    /** Instantiate the interface and set the context */
    JavaScriptInterface(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 webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");

在您的网页中:

<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />

<script type="text/javascript">
    function showAndroidToast(toast) {
        Android.showToast(toast);
    }
</script>

如果你想向你的网页传递一些东西,只需调用相应的javascript函数:

If you wanna pass something to your webpage, just calling corresponding javascript function:

String str = "xxx";
myWebView.loadUrl("javascript:xxx('"+str+"')");

这是参考:http://developer.android.com/guide/webapps/webview.html

这篇关于将数据从java类传递到Web View html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆