怎样的WebView与功放之间的通信; JavaScript的? [英] How to communicate between WebView & JavaScript?

查看:100
本文介绍了怎样的WebView与功放之间的通信; JavaScript的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的本地应用程序。我的应用程序有一个的WebView 。我要记录这种的WebView 的组件的的每一个动作的。哪个按钮点击,它的图像拖动。在那之后,我将记录这些事情,我想存储在SQLite的。

I am developing native application. My application have a WebView. I want to log this WebView's component's every action. Which button clicked, which image dragged. After that, I will log those things, I want to store in SQLite.

所以,我用Google搜索并找到 WebAppInterface 连通的Java和放大器; JavaScript的。但是,这种沟通是不够的。我无法从 WebAppInterface 类发送数据库。

So, I googled and find WebAppInterface which communicates Java & JavaScript. But this communication isn't enough. I can't send database from WebAppInterface class.

我想问这个问题实际上(分钟 46:00 )。

这可能吗?或者,另一种解决方案?

Is it possible? Or, another solution?

问候,

推荐答案

您应该添加JavaScript接口的web视图这样的:

You should add javascript interface to your webView like that:

webView.addJavascriptInterface(新JavascriptInterface(本),AndroidFunction);

您应该创建接口类:

public class JavascriptInterface{
Context mContext;

    JavascriptInterface(Context c) {
        mContext = c;
    }

    public void save(String action){
        // save to database
    }
}

在该网站上,你应该叫:

On the website you should call:

AndroidFunction.save("actionName");

这篇关于怎样的WebView与功放之间的通信; JavaScript的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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