1.WebBrowserActivity extends BaseActivity

2.setContentView(R.layout.activity_web_html);

<WebView
android:id="@+id/wv_web_browser"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

3.wv_web_browser = (WebView)findViewById(R.id.wv_web_browser);

WebSettings webSet = wv_web_browser.getSettings();
webSet.setJavaScriptEnabled(true);
webSet.setJavaScriptCanOpenWindowsAutomatically(true);
webSet.setLoadsImagesAutomatically(true);
webSet.setSupportZoom(true);
webSet.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
webSet.setUseWideViewPort(true);
webSet.setLoadWithOverviewMode(true);
webSet.setMixedContentMode(0);
// 设置出现缩放工具
webSet.setBuiltInZoomControls(true);
int sysVersion = VERSION.SDK_INT;
if (sysVersion >= 11) {
webSet.setDisplayZoomControls(false);
} else {
ZoomButtonsController zbc = new ZoomButtonsController(wv_web_browser);
zbc.getZoomControls().setVisibility(View.GONE);
}
// 设置可以访问文件
webSet.setAllowFileAccess(true);
webSet.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSet.setAppCacheEnabled(true);
webSet.setDomStorageEnabled(true);
webSet.setDatabaseEnabled(true);

  

//通知h5应用状态 通知刷新html
informHtmlReceiver = new InformHtmlReceiver();
IntentFilter informHtmlFilter = new IntentFilter(AppConstants.ACTION_APP_PACKAGENAME_INFORM_HTML);
LocalBroadcastManager.getInstance(WebBrowserActivity.this).registerReceiver(informHtmlReceiver, informHtmlFilter);
// 增加h5与本地交互方法
wv_web_browser.addJavascriptInterface(new HtmlJavascriptInterface(),"jsObj");
wv_web_browser.addJavascriptInterface(new HtmlJavaAlarmInterface(), "mstore");

  

WebChromeClient wvcc = new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
  super.onReceivedTitle(view, title);
  if (!TextUtils.isEmpty(title)) {
tv_classify_title.setText(title);
}
}
};
wv_web_browser.setWebChromeClient(wvcc);

  

/**
* 调用js更新H5,js方法
*/
private class InformHtmlReceiver extends BroadcastReceiver{ @Override
public void onReceive(Context context, Intent intent) {
final String packageName = intent.getStringExtra("packagename");
String state = intent.getStringExtra("state");
wv_web_browser.loadUrl("javascript:callDownState('" + packageName +"','"+state+ "')");
}
}

  

public class HtmlJavaAlarmInterface {
/**
* 点击添加
*
* @param apps_json
*/
@JavascriptInterface
public void setAlarm(final String endTime, final String title, final String content) { if (CalendarUtil.tranceLong(endTime) != 0) {
CalendarUtil.setAlarm(WebBrowserActivity.this, CalendarUtil.tranceLong(endTime), title, content);
}
}
}

  

andriod webview和h5的更多相关文章

  1. swift禁用webView对H5中数字,链接,日期,地址,电话号码做解析

    showWebView.dataDetectorTypes = .None //swift禁用webView对H5中数字,链接,日期,地址,电话号码做解析 其UIDataDetectorTypes属性 ...

  2. android:如何通过chrome远程调试APP中的webView的h5代码

    今天出现一个问题,在老板的Mate9 Pro上,我们APP的所有H5页面都是一片空白,但是在其他手机上都是好的,那么我们就怀疑是h5报错了,但是到底是什么错,无法得知,所以就想要可以像在pc的chro ...

  3. Android中WebView与H5的交互,Native与JS方法互调

    项目中经常用到WebView与H5的交互,一个是H5调本地方法,一个是本地调H5方法,在此记录一下. 首先,启用JS支持 //启用js支持 webSettings.setJavaScriptEnabl ...

  4. Android WebView与H5联调技巧

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/78 背景: 突然想写一篇关于Android WebView ...

  5. Webview 与h5的交互

    步骤:H5代码   <html>   <head>   <meta charset="UTF-8">   <title>交互Demo ...

  6. Webview之H5页面调用android的图库及文件管理

    h5页面打开图片管理器 一般页面在pc打开文件管理器是用 type="file"的代码,可是这在android的webview是无效的,必须为webview设定WebChromeC ...

  7. 解决vue在ios或android中用webview打开H5链接时#号后面的参数被忽略问题angular同样适用

    在ios或android如果直接用webview在打开H5链接例如: 打开:http://localhost:8080/#/answer?id=1509335039582001 会变成 http:// ...

  8. 微信小程序web-view(webview) 嵌套H5页面 唤起微信支付的实现方案

    场景:小程序页面有一个web-view组件,组件嵌套的H5页面,要唤起微信支付. 先讲一下我的项目,首先我是自己开发的一个H5触屏版的商城系统,里面含有购物车,订单支付等功能.然后刚开始,我们公众号里 ...

  9. android webview处理h5打开本地文件浏览器的功能

    这周遇到一个比较棘手的问题,需要在android上边集成h5页面,并且在h5页面上,需要用户能够上传android本地的照片,一开始我以为webview会自动处理掉的,因此没太留意,当真正集成时,才发 ...

随机推荐

  1. redis编译 报告错误 jemalloc/jemalloc.h:没有那个文件或目录 解决.

    问题原因:没找到jemalloc头文件. 百度谷歌半天没找到有效的下载地址. github中有 到github下载.jemalloc https://github.com/jemalloc/jemal ...

  2. Echarts学习之路3(在react中使用)

    安装: npm install echarts --save demo import React, { Component } from 'react'; // 引入 ECharts 主模块 impo ...

  3. MySQL函数--(1)

    /*函数与存储过程的区别1.存储过程:可以有0个返回值,可以有多个返回值函数:有且仅有一个返回值*/ #创建语法create FUNCTION 函数名(参数列表) return 返回类型BEGIN函数 ...

  4. Asp.Net Core配置的知识总结

    配置在Asp.Net Core中由四个核心的对象组成: IConfiguration:配置的最终产出物,它代表了整个asp.net core应用的配置树,这棵树有根节点,子节点和叶子节点,根节点由IC ...

  5. Flutter绘制波浪

    以上动画是仿照 里面的物理动画还未仿写 代码见  https://github.com/dnoyeb/syk_flutter

  6. 仿 ELEMENTUI 实现一个简单的 Form 表单

    原文:仿 ElmentUI 实现一个 Form 表单 一.目标 ElementUI 中 Form 组件主要有以下 功能 / 模块: Form FormItem Input 表单验证 在这套组件中,有 ...

  7. Consecutive Sum LightOJ - 1269(区间异或和)

    Consecutive Sum 又来水一发blog... 本来是昨天补codechef的题,最后一道题是可持久化字典树,然后去黄学长博客看了看 觉得字典树写法有点不太一样,就想着用黄学长的板子写码几道 ...

  8. React Fullpage

    之前项目需要,单独拿出来做了个demo 目前仅支持收尾加autoheight github地址:https://github.com/zlinggnilz/React-Fullpage

  9. [LOJ3086][GXOI/GZOI2019]逼死强迫症——递推+矩阵乘法

    题目链接: [GXOI/GZOI2019]逼死强迫症 设$f[i][j]$表示前$i$列有$j$个$1*1$的格子的方案数,那么可以列出递推式子: $f[i][0]=f[i-1][0]+f[i-2][ ...

  10. MarkDown&思维导图

    从markdown文件创建思维导图 pzhaonet/mindr: an R package which converts markdown files (.md, .Rmd) into mindma ...