文档

管理 H5 页面

更新时间:

打开 H5 离线包后,您可以选择同步方法或异步方法将单个容器的视图(View)嵌入到原生页面中。

说明

使用异步方法不占用主线程,不会影响性能。

  • 使用同步方法嵌入单个容器视图到原生页面的方法如下:

    public static final void openH5(String url) {
        if (TextUtils.isEmpty(url)) {
            return;
        }
        H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext()
                .findServiceByInterface(H5Service.class.getName());
        H5Bundle bundle = new H5Bundle();
        Bundle param = new Bundle();
        // 要打开的离线包 appId
        param.putString(H5Param.APP_ID, appId);
        // 要打开的离线包内的 URL /www/index.html,必须加 /
        // 如果不传 URL,容器将默认打开离线包默认配置的 URL
        param.putString(H5Param.LONG_URL,url);
        bundle.setParams(param);
        if (h5Service != null) {
            H5Page h5Page=h5Service.createPage(activity,bundle);
          View view=h5Page.getContentView(),
         // view 最后添加到自己的页面中就行
        }
    }
  • 使用异步方法嵌入单个容器视图到原生页面的方法如下:

    H5Service h5Service = LauncherApplicationAgent.getInstance().getMicroApplicationContext()
                      .findServiceByInterface(H5Service.class.getName());
    H5Bundle bundle = new H5Bundle();
    Bundle param = new Bundle();
         param.putString(H5Param.APP_ID, appId);
         param.putString(H5Param.LONG_URL, url);
         bundle.setParams(param);
         if (h5Service != null) {
                 h5Service.createPageAsync(activity, bundle, h5PageReadyListener);
         }
  • 本页导读 (0)
文档反馈