基于onJsPrompt的混合开发框架

本文介绍了如何集成和使用一个基于onJsPrompt的混合开发框架,通过在Android的WebView中实现JsBridgeInterface接口,实现JavaScript与Native的交互。详细讲述了自定义plugin类、配置及调用流程,包括H5调用Native方法和Native回调H5的机制。此外,还提供了代码地址和展示了框架的效果。
摘要由CSDN通过智能技术生成

集成

gradle引用

#在项目的build.gradle中加入jcenter库
allprojects {
    repositories {
        google()
        jcenter()
        
    }
}
 #在app目录的build.gradle中加
compile 'com.jason.simple:jsBridge:1.0.2'

使用

直接继承LightAppActivity并实现JsBridgeInterface接口,就可以直接进行使用

public class DemoActivity extends LightAppActivity implements JsBridgeInterface

#在Activity的onCreate方法里调用

setInterface(this)

#然后就可以直接调用

loadUrl("https://www.baidu.com")

setTitle("") 改变title

....还有一些其他方法等等

关于plugin类,是用于与web交互的实体类,自定义plugin类需要继承JsPlugin类

public class DemoPlugin extends JsPlugin {
    private Handler handler;
    private JsBridgeWebView webView;
    private Context mContext;

    public DemoPlugin(Handler handler, Context mContext, JsBridgeWebView webView) {
        super(handler, mContext, webView);
        this.handler = handler;
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值