一、词、excel、PPT展示
1 .微软Office公共Api接口
如果文档内容不敏感,或者需要实现文档预览,请考虑使用微软的公共Api接口来实现。
微软的Office公共Api地址是https://view.office apps.live.com/op/view.aspx吗?
在Android中的实现方法如下。
首先连接预览目标的URL :
3359 view.office apps.live.com/op/view.aspx? src=http://xxx.pptx
然后,使用WebView加载此URL。 建议的配置如下: websettingssettings=mweb view.get settings (;
settings.setcachemode (web settings.load _ cache _ else _ network );
settings.setsaveformdata(true;
settings.setsavepassword(true;
settings.setusewideviewport (true;
settings.setloadwithoverviewmode (true;
settings.setjavascriptenabled (true;
settings.setjavascriptcanopenwindowsautomatically (true;
settings.setsupportzoom(true; /*
支持HTTPS、HTTP混合模式
* http://blog.csdn.net/QQ _ 16472137/article/details/54346078
*/if (build.version.SDK _ int=build.version _ codes.lollipop ) {
settings.setmixedcontentmode (web settings.mixed _ content _ always _ allow );
//首选渲染接口settings.setrenderpriority (web settings.render priority.high ); //technicalsettingssettings.setsupportmultiplewindows (true;
settings.setcachemode (web settings.load _ default );
settings.setappcacheenabled (true;
settings.setdatabaseenabled (true;
settings.setdomstorageenabled (true;
settings.setappcachemaxsize (8* 1024 * 1024 ); //缓存最多支持8m/*cookies5.0或更高版本的手机不支持第三方cookies自动同步
*通常在iframe中的页面上保存cookies操作设置。)
* http://blog.Sina.com.cn/s/blog _ 6e 73239 a 0102 viku.html
*/if (Android.OS.build.version.SDK _ int=build.version _ codes.lollipop ) {
CookieManager.getInstance ().setacceptthirdpartycookies (mweb view,true );
}//WebView默认支持cookiescookiemanager.getinstance ().setacceptcookie ) true。
注:此用法是将文档的URL连接到连接上,以便无需下载文件即可在线预览office文件。
但是,使用Microsoft预览界面会导致文档的url地址被公开,从而导致所谓的文档安全丢失。
如果文件太大,加载速度可能很慢,无法加载。
2 .使用文档浏览Paas服务
服务代表为腾讯TBS浏览服务(免费)、百度文档DOC服务(收费) )。
要腾讯TBS,必须自行下载文件,并使用调用的TbsReadView方法下载。
存在的问题:
a )有些机型加载功能不稳定,加载正常,有些机型加载有问题。 最常见的问题是not supported by:xxx,它非常影响用户体验。
b ) )如果未安装腾讯产品,则TBS服务不可用。 因为腾讯系列产品都是基于X5内核的,TBS服务也是基于X5内核的。
必须注意,X5内核的某些版本存在内存泄漏。 必须将以下逻辑添加到onDestory中: @ overrideprotectedvoidondestroy (() try ) if ) webview!=空) {
webView.stopLoading (;
webView.removeAllViewsInLayout (;
webView.removeAllViews (;
CookieSyncManager.getInstance ().stopSync );
webView.destroy (;
webView=null;
}
} catch (可伸缩可伸缩) {
throwable.print堆栈跟踪(;
}finally{super.onDestroy (;
}
}
二. PDF展示
1 .使用腾讯TBS服务
该方案基本上与加载office文件的方案相同,对于存在的问题也是如此。 这里详细说明。
参考开源项目: https://github.com/zhing Xiaohong/super file view
2. AndroidPdfViewer
开源地址: https://github.com/barte KSC/androidpdfviewer
开发参考文章: https://www.cn blogs.com/Qixin gchao/p/11658226.html
3.PdfViewPager
开源地址: https://github.com/vog hdev/pdfviewpager