在webview android中设置/获取数据 [英] set/get Data in webview android

查看:255
本文介绍了在webview android中设置/获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网络视图:

<textarea name="text" id="textPage" class="text_area"></textarea>
<script language="javascript" charset="utf-8">
//call some method of javascript.
</script>

是否可以将文本设置为textarea并从textarea获取文本. 从id设置/获取数据(如果可能的话)将不胜感激.

Is it possible to set text to textarea and get text from textarea. Set/get data from id(if any method possible) will be appreciated.

推荐答案

经过大量研究,我发现了解决方案,将来可能会有用:

After many research i found solution, it might useful in future:

设置数据:

Android:

Android:

webView.loadUrl("javascript:setData()");

JS:

JS:

function setData(){
//js code
}

获取数据:

Android:

Android:

JavascriptInterface jsInterface = new JavascriptInterface(MainActivity.this);
converterWeb.addJavascriptInterface(jsInterface, "Android");//android is a tag.

班级:

public class JavascriptInterface {
        Context mContext;

        JavascriptInterface(Context c) {
            mContext = c;
        }

        public boolean getData(String name) {
            Toast.makeText(mContext, "Text: "+name, Toast.LENGTH_SHORT).show();
            return true;
        }
    }

JS:

JS:

Android.convertedText(value);//send data in tag.

更好的选择仍然受到欢迎.

better option still welcome.

这篇关于在webview android中设置/获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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