使用腾讯内核 implementation 'com.tencent.tbs.tbssdk:sdk:43903'

。使用x5内核的webview,我这里自定义了一个

package opj.cordova.ispm.view;import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
import com.tencent.smtt.sdk.CookieManager;
import com.tencent.smtt.sdk.CookieSyncManager;
import com.tencent.smtt.sdk.DownloadListener;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;import java.util.ArrayList;
import java.util.List;import opj.cordova.ispm.R;public class MyX5WebView extends WebView {private static final String TAG = "";private static final int MAX_LENGTH = 8;ProgressBar progressBar;private TextView tvTitle;private ImageView imageView;private List<String> newList;public MyX5WebView(Context context) {super(context);initUI();}public MyX5WebView(Context context, AttributeSet attrs) {super(context, attrs);initUI();}public MyX5WebView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);initUI();}public void setShowProgress(boolean showProgress) {if (showProgress) {progressBar.setVisibility(VISIBLE);} else {progressBar.setVisibility(GONE);}}private void initUI() {getX5WebViewExtension().setScrollBarFadingEnabled(false);setHorizontalScrollBarEnabled(false);//水平不显示小方块setVerticalScrollBarEnabled(false); //垂直不显示小方块//      setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);//滚动条在WebView内侧显示
//      setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);//滚动条在WebView外侧显示progressBar = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleHorizontal);progressBar.setMax(100);progressBar.setProgressDrawable(this.getResources().getDrawable(R.drawable.ic_camera));addView(progressBar, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 6));imageView = new ImageView(getContext());imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//      加载图 根据自己的需求去集成使用imageView.setImageResource(R.mipmap.ic_launcher);imageView.setVisibility(VISIBLE);addView(imageView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));initWebViewSettings();}//   基本的WebViewSettingpublic void initWebViewSettings() {setBackgroundColor(getResources().getColor(android.R.color.white));setWebViewClient(client);setWebChromeClient(chromeClient);setDownloadListener(downloadListener);setClickable(true);setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {return false;}});WebSettings webSetting = getSettings();webSetting.setJavaScriptEnabled(true);webSetting.setBuiltInZoomControls(true);webSetting.setJavaScriptCanOpenWindowsAutomatically(true);webSetting.setDomStorageEnabled(true);webSetting.setAllowFileAccess(true);webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);webSetting.setSupportZoom(true);webSetting.setUseWideViewPort(true);webSetting.setSupportMultipleWindows(true);webSetting.setAppCacheEnabled(true);webSetting.setGeolocationEnabled(true);webSetting.setAppCacheMaxSize(Long.MAX_VALUE);webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);//android 默认是可以打开_bank的,是因为它默认设置了WebSettings.setSupportMultipleWindows(false)//在false状态下,_bank也会在当前页面打开……//而x5浏览器,默认开启了WebSettings.setSupportMultipleWindows(true),// 所以打不开……主动设置成false就可以打开了//需要支持多窗体还需要重写WebChromeClient.onCreateWindowwebSetting.setSupportMultipleWindows(false);
//        webSetting.setCacheMode(WebSettings.LOAD_NORMAL);
//        getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if ((keyCode == KeyEvent.KEYCODE_BACK) && this.canGoBack()) {this.goBack(); // goBack()表示返回WebView的上一页面return true;}return super.onKeyDown(keyCode, event);}private WebChromeClient chromeClient = new WebChromeClient() {@Overridepublic void onReceivedTitle(WebView view, String title) {if (tvTitle == null || TextUtils.isEmpty(title)) {return;}if (title != null && title.length() > MAX_LENGTH) {tvTitle.setText(title.subSequence(0, MAX_LENGTH) + "...");} else {tvTitle.setText(title);}}//监听进度@Overridepublic void onProgressChanged(WebView view, int newProgress) {progressBar.setProgress(newProgress);if (progressBar != null && newProgress != 100) {//Webview加载没有完成 就显示我们自定义的加载图progressBar.setVisibility(VISIBLE);} else if (progressBar != null) {//Webview加载完成 就隐藏进度条,显示WebviewprogressBar.setVisibility(GONE);imageView.setVisibility(GONE);}}};private WebViewClient client = new WebViewClient() {//当页面加载完成的时候@Overridepublic void onPageFinished(WebView webView, String url) {CookieManager cookieManager = CookieManager.getInstance();cookieManager.setAcceptCookie(true);String endCookie = cookieManager.getCookie(url);Log.i(TAG, "onPageFinished: endCookie : " + endCookie);if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {CookieSyncManager.getInstance().sync();//同步cookie} else {CookieManager.getInstance().flush();}super.onPageFinished(webView, url);}@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {//返回值是true的时候控制去WebView打开,// 为false调用系统浏览器或第三方浏览器if (url.startsWith("http") || url.startsWith("https") || url.startsWith("ftp")) {return false;} else {try {Intent intent = new Intent();intent.setAction(Intent.ACTION_VIEW);intent.setData(Uri.parse(url));view.getContext().startActivity(intent);} catch (ActivityNotFoundException e) {Toast.makeText(view.getContext(), "手机还没有安装支持打开此网页的应用!", Toast.LENGTH_SHORT).show();}return true;}}@Overridepublic WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {return super.shouldInterceptRequest(view, request);}@Overridepublic void onLoadResource(WebView webView, String s) {super.onLoadResource(webView, s);String reUrl = webView.getUrl() + "";
//            Log.i(TAG, "onLoadResource: onLoadResource : " + reUrl);List<String> urlList = new ArrayList<>();urlList.add(reUrl);newList = new ArrayList();for (String cd : urlList) {if (!newList.contains(cd)) {newList.add(cd);}}}};public void syncCookie(String url, String cookie) {CookieSyncManager.createInstance(getContext());if (!TextUtils.isEmpty(url)) {CookieManager cookieManager = CookieManager.getInstance();cookieManager.setAcceptCookie(true);cookieManager.removeSessionCookie();// 移除cookieManager.removeAllCookie();//这里的拼接方式是伪代码String[] split = cookie.split(";");for (String string : split) {//为url设置cookie// ajax方式下  cookie后面的分号会丢失cookieManager.setCookie(url, string);}String newCookie = cookieManager.getCookie(url);Log.i(TAG, "syncCookie: newCookie == " + newCookie);//sdk21之后CookieSyncManager被抛弃了,换成了CookieManager来进行管理。if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {CookieSyncManager.getInstance().sync();//同步cookie} else {CookieManager.getInstance().flush();}} else {}}//删除Cookieprivate void removeCookie() {CookieSyncManager.createInstance(getContext());CookieManager cookieManager = CookieManager.getInstance();cookieManager.removeSessionCookie();cookieManager.removeAllCookie();if (Build.VERSION.SDK_INT < 21) {CookieSyncManager.getInstance().sync();} else {CookieManager.getInstance().flush();}}public String getDoMain(String url) {String domain = "";int start = url.indexOf(".");if (start >= 0) {int end = url.indexOf("/", start);if (end < 0) {domain = url.substring(start);} else {domain = url.substring(start, end);}}return domain;}DownloadListener downloadListener = new DownloadListener() {@Overridepublic void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {Uri uri = Uri.parse(url);Intent intent = new Intent(Intent.ACTION_VIEW, uri);getContext().startActivity(intent);}};
}

,最后使用

url="https://view.officeapps.live.com/op/view.aspx?src="+url;
wwebview.loadUrl(url);

我的使用dialog的

  try {AlertDialog.Builder alterDiaglog = new AlertDialog.Builder(context);alterDiaglog.setIcon(R.mipmap.ispm);//图标MyX5WebView wb_view= (MyX5WebView) LayoutInflater.from(context).inflate(R.layout.item_webview,null);url="https://view.officeapps.live.com/op/view.aspx?src="+url;// webview必须设置支持Javascript才可打开wb_view.getSettings().setJavaScriptEnabled(true);// 设置此属性,可任意比例缩放wb_view.getSettings().setUseWideViewPort(true);wb_view.loadUrl(url);//通过在线预览office文档的地址加载alterDiaglog.setView(wb_view);
//            alterDiaglog.setView(remotePDFViewPager);alterDiaglog.show();} catch (Exception e) {e.printStackTrace();}

https://view.officeapps.live.com/op/view.aspx?src=这个前缀好像只是展示docx  其他文件浏览服务器去找,谷歌肯定是不能用了

在线浏览Office文档:

http://blogs.office.com/2013/04/10/office-web-viewer-view-office-documents-in-a-browser/

查看docx文档:

http://view.officeapps.live.com/op/view.aspx?src=newteach.pbworks.com%2Ff%2Fele%2Bnewsletter.docx

查看xlsx文档:

http://view.officeapps.live.com/op/view.aspx?src=http%3A%2F%2Flearn.bankofamerica.com%2Fcontent%2Fexcel%2FWedding_Budget_Planner_Spreadsheet.xlsx

查看PPT文档:

http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fbuild%2f2011%2fslides%2fTOOL-532T_Sutter.pptx

http://www.cnblogs.com/wuhuacong/p/3871991.html

在线地址来自https://www.cnblogs.com/huangtailang/p/76492af9d30087d8659d8d5400d20fc7.html

预览pdf  使用pdfviewpager轻松搞定

implementation 'es.voghdev.pdfviewpager:library:1.0.3'
      remotePDFViewPager= new RemotePDFViewPager(context, url, new DownloadFile.Listener(){@Overridepublic void onSuccess(String url, String destinationPath) {String filename=   url.substring(url.lastIndexOf("/")+1);PDFPagerAdapter   adapter = new PDFPagerAdapter(context,filename );remotePDFViewPager.setAdapter(adapter);}@Overridepublic void onFailure(Exception e) {}@Overridepublic void onProgressUpdate(int progress, int total) {}});alterDiaglog.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {}});alterDiaglog.setView(remotePDFViewPager);

webview展示doc docx pdf,excels相关推荐

  1. java使用freemark实现word(.doc/.docx)/pdf生成和导出(附源码和模板文件)

    freemark生成word/pdf 一. 背景 二.实现的技术选型以及遇到的坑 三.最终的效果 2.1 `.doc` word效果展示 2.1 `.docx` word效果展示 2.2 docx w ...

  2. pywin32/win32com批量转格式doc/docx/pdf/html/python-docx批量修改Word文档内容和格式

    请看代码块,及里面的注释 import re import os from win32com.client import Dispatch from docx import Document as D ...

  3. java 接口文档的格式化_Java Word API - 读写转换处理DOC DOCX HTML PDF HTML格式

    Java Word 文档处理API 先进功能 执行邮件合并 使用邮件合并生成报表 插入格式户文本,段落,图像,表格以及其他内容到Word文档中 使用数据库的检索数据填充到Word文档中的表格 创建邮件 ...

  4. Word处理控件Aspose.Words功能演示:在 Python 中将 Word DOCX 或 DOC 转换为 PDF

    Word 到PDF是最流行和执行最广泛的文档转换之一.DOCX或DOC文件在打印或共享之前会转换为 PDF 格式.在本文中,我们将在 Python 中自动将 Word 转换为 PDF.步骤和代码示例将 ...

  5. Word处理控件Aspose.Words功能演示:在 Java 中将 Word DOC/DOCX 转换为 PDF

    Aspose.Words是一种高级Word文档处理API,用于执行各种文档管理和操作任务.API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word. A ...

  6. php 读取并显示doc,PHP读取doc,docx,xls,pdf,txt内容

    我的一个客户有这样的需求:上传文件,可以是doc,docx,xls,pdf,txt格式,现需要用php读取这些文件的内容,然后计算文件里面字数. 1.PHP读取DOC格式的文件 首先介绍一下如何在wi ...

  7. python word转pdf linux_Linux下使用LibreOffice+python将doc/docx/wps格式的文档转成html/txt/docx等格式...

    Linux下的word文档格式转换工具 最近接到一个需求,要将所有不同格式的文档(包括.doc/.docx/.wps)转成统一格式,如都转为.docx,或直接转为.html 或.txt.经调研后,发现 ...

  8. 参考file-convert-util工具,实现doc,docx,html,md,pdf,png转换

    参考 https://gitee.com/zhengqingya/file-convert-util 项目,打包到本地仓库实现doc,docx,html,md,pdf,png转换 https://gi ...

  9. vue - - - - - 在线预览常见文件格式 .doc, .docx, .xls, .xlsx,.pdf

    在线预览常见文件 1.HTML5 - ```embed```标签 1.1 注意⚠️ 1.2 使用方式 2. HTML - ```iframe```标签 2.1 注意⚠️ 2.2 使用方式 3. HTM ...

最新文章

  1. 安装JDK1.8+环境配置
  2. 【前端来刷LeetCode】两数之和与两数相加
  3. ubuntu c++检测usb口事件变化_从MacBook支持USB-C口充电看电脑标配充电器发展史
  4. Spring IOC实现
  5. Chrome指令/追踪Http请求相关
  6. Tensorflow 卷积神经网络 (二)
  7. Delphi 常用API 函数
  8. Lasso回归算法: 坐标轴下降法与最小角回归法小结
  9. centos下安装和卸载jdk
  10. golang中的异常如何捕获?
  11. Andro - Multipurpose OpenCart 2.X 自适应主题模板 ABC-0651
  12. 月薪30K+的电子工程师应具备什么?
  13. Openwrt 硬改过程记录
  14. 操作系统课设——Windows 进程管理
  15. 谷歌浏览器插件打包ChromePackage-extention
  16. 编程基础——鱼龙混杂来两波
  17. DELL戴尔笔记本关闭触摸板触控板WIN10
  18. TypeError: Descriptors cannot not be created directly解决
  19. 2019杭电多校 第七场 Kejin Player 6656(求期望值)
  20. angular自带的jquery lite用法实例,不用引入jq照样回到老夫就用jq的感觉~

热门文章

  1. 健康睡眠,提高工作效率
  2. 设置input为不可编辑状态
  3. Shape的属性介绍及使用
  4. 基于知识图谱的人机对话系统 | 公开课笔记
  5. Lodash.js学习(二)——difference深度理解
  6. 慎用文件夹加密软件!
  7. c语言project3: 复杂动态字体显示欲穷千里目更上一层楼,健身励志名言短句霸气?八字励志名言短句大全...
  8. 随机森林python参数_随机森林的参数说明
  9. 拆分大sdf文件并删除分子属性数据
  10. 老司机带你秒懂结构体