TBS腾讯浏览器服务x5内核打开本地doc(doc docx xlsx pdf ppt)文档(官网最新43903版本SDK)
目前最新版本(官网最新43903版本SDK)仅支持本地文件查看
测试Demo:TBS腾讯浏览器服务x5内核打开本地doc(docdocxxlsxpdfppt)文档(官网最新43903版本SDK)-互联网文档类资源-CSDN下载
腾讯TBS初始化失败,加载失败问题 : https://blog.csdn.net/jifenglie/article/details/106669723
配置:
1、gradle中引入(使用此方法,不需要在去官网下载SDK,也不需要下载SO文件)
implementation 'com.tencent.tbs.tbssdk:sdk:43903'
2、在gradle中配置 ndk
//X5兼容64位手机
ndk {abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
3、在你的Application 的onCreate 方法中初始化:
//初始化X5内核
QbSdk.initX5Environment(this, new QbSdk.PreInitCallback() {@Overridepublic void onCoreInitFinished() {//x5内核初始化完成回调接口,此接口回调并表示已经加载起来了x5,有可能特殊情况下x5内核加载失败,切换到系统内核。}@Overridepublic void onViewInitFinished(boolean b) {//x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。Log.e("@@","加载内核是否成功:"+b);}
});
使用:
1、本地文件存在,直接使用TbsReaderView打开:
private String tbsReaderTemp = Environment.getExternalStorageDirectory() + "/TbsReaderTemp";
private void displayFile(String filePath, String fileName) {//增加下面一句解决没有TbsReaderTemp文件夹存在导致加载文件失败String bsReaderTemp = tbsReaderTemp;File bsReaderTempFile = new File(bsReaderTemp);if (!bsReaderTempFile.exists()) {Log.d("print", "准备创建/TbsReaderTemp!!");boolean mkdir = bsReaderTempFile.mkdir();if (!mkdir) {Log.d("print", "创建/TbsReaderTemp失败!!!!!");}}Bundle bundle = new Bundle();Log.d("print", "filePath" + filePath);//可能是路径错误Log.d("print", "tempPath" + tbsReaderTemp);bundle.putString("filePath", filePath);bundle.putString("tempPath", tbsReaderTemp);boolean result = mTbsReaderView.preOpen(getFileType(fileName), false);Log.d("print", "查看文档---" + result);if (result) {mTbsReaderView.openFile(bundle);} else {}}
2、文件不存在去下载
OkGo.get(docUrl)//.tag(this)//.execute(new FileCallback(download, docName) { //文件下载时,可以指定下载的文件目录download和文件名docName@Overridepublic void onSuccess(File file, Call call, Response response) {// file 即为文件数据,文件保存在指定目录Log.d("print", "下载文件成功");displayFile(download + file.getName(), file.getName());Log.d("print", "" + file.getName());}@Overridepublic void downloadProgress(long currentSize, long totalSize, float progress, long networkSpeed) {//这里回调下载进度(该回调在主线程,可以直接更新ui)Log.d("print", "总大小---" + totalSize + "---文件下载进度---" + progress);}});
完整的展示pdf文件的代码:
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.widget.RelativeLayout;import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.FileCallback;
import com.tencent.smtt.sdk.TbsReaderView;import java.io.File;import okhttp3.Call;
import okhttp3.Response;public class TbsActivity extends AppCompatActivity implements TbsReaderView.ReaderCallback {RelativeLayout mRelativeLayout;private TbsReaderView mTbsReaderView;// private String docUrl = "/test\\/WD802-8.doc";
// private String docUrl = "/test\\/安卓类库整理20190125.xlsx";
// private String docUrl = "/test\\/登录.pdf";private String docUrl = "/test\\/新个人所得税法扣缴及六项专项附加扣除操作指引.ppt";
// private String docUrl = "/test\\/接口需求0327.docx";// private String docUrl = "http:\\/\\/zyweike.cdn.bcebos.com\\/zyweike\\/ep1\\/2018\\/04\\/02\\/周末加班统计.xlsx";private String download = Environment.getExternalStorageDirectory() + "/download/test/document/";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_tbs);mTbsReaderView = new TbsReaderView(this, this);mRelativeLayout = findViewById(R.id.tbsView);mRelativeLayout.addView(mTbsReaderView, new RelativeLayout.LayoutParams(-1, -1));Intent intent = getIntent();String data = intent.getStringExtra("type");if ("1".equals(data)) {this.docUrl = "/test\\\\/WD802-8.doc";} else if ("2".equals(data)) {docUrl = "/test\\\\/接口需求0327.docx";}else if("3".equals(data)){docUrl = "/test\\\\/登录.pdf";}else if("4".equals(data)){docUrl = "/test\\\\/安卓类库整理20190125.xlsx";} else if ("5".equals(data)) {docUrl = "/test\\/新个人所得税法扣缴及六项专项附加扣除操作指引.ppt";}initDoc();}private void initDoc() {int i = docUrl.lastIndexOf("/");String docName = docUrl.substring(i, docUrl.length());Log.d("print", "---substring---" + docName);// String[] split = docUrl.split("\\/");
// String s = split[split.length - 4] + split[split.length - 3] + split[split.length - 2] + split[split.length - 1];
// Log.d("print", "截取带时间---" + s);//判断是否在本地/[下载/直接打开]File docFile = new File(download, docName);if (docFile.exists()) {//存在本地;Log.d("print", "本地存在");displayFile(docFile.toString(), docName);} else {OkGo.get(docUrl)//.tag(this)//.execute(new FileCallback(download, docName) { //文件下载时,可以指定下载的文件目录和文件名@Overridepublic void onSuccess(File file, Call call, Response response) {// file 即为文件数据,文件保存在指定目录Log.d("print", "下载文件成功");displayFile(download + file.getName(), file.getName());Log.d("print", "" + file.getName());}@Overridepublic void downloadProgress(long currentSize, long totalSize, float progress, long networkSpeed) {//这里回调下载进度(该回调在主线程,可以直接更新ui)Log.d("print", "总大小---" + totalSize + "---文件下载进度---" + progress);}});}}private String tbsReaderTemp = Environment.getExternalStorageDirectory() + "/TbsReaderTemp";private void displayFile(String filePath, String fileName) {//增加下面一句解决没有TbsReaderTemp文件夹存在导致加载文件失败String bsReaderTemp = tbsReaderTemp;File bsReaderTempFile = new File(bsReaderTemp);if (!bsReaderTempFile.exists()) {Log.d("print", "准备创建/TbsReaderTemp!!");boolean mkdir = bsReaderTempFile.mkdir();if (!mkdir) {Log.d("print", "创建/TbsReaderTemp失败!!!!!");}}Bundle bundle = new Bundle();/* 1.TbsReader: Set reader view exception:Cannot add a null child view to a ViewGroupTbsReaderView: OpenFile failed! [可能是文件的路径错误]*//* 2.插件加载失败so文件不支持;*//*ndk {//设置支持的SO库架构 'arm64-v8a',abiFilters 'armeabi', "armeabi-v7a", 'x86'} *//*3.自适应大小*/Log.d("print", "filePath" + filePath);//可能是路径错误Log.d("print", "tempPath" + tbsReaderTemp);bundle.putString("filePath", filePath);bundle.putString("tempPath", tbsReaderTemp);boolean result = mTbsReaderView.preOpen(getFileType(fileName), false);Log.d("print", "查看文档---" + result);if (result) {mTbsReaderView.openFile(bundle);} else {}}private String getFileType(String paramString) {String str = "";if (TextUtils.isEmpty(paramString)) {Log.d("print", "paramString---->null");return str;}Log.d("print", "paramString:" + paramString);int i = paramString.lastIndexOf('.');if (i <= -1) {Log.d("print", "i <= -1");return str;}str = paramString.substring(i + 1);Log.d("print", "paramString.substring(i + 1)------>" + str);return str;}@Overridepublic void onCallBackAction(Integer integer, Object o, Object o1) {}@Overrideprotected void onDestroy() {super.onDestroy();mTbsReaderView.onStop();}
}
activity_tbs.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"><RelativeLayoutandroid:id="@+id/tbsView"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintBottom_toBottomOf="parent"></RelativeLayout></android.support.constraint.ConstraintLayout>
测试Demo:TBS腾讯浏览器服务x5内核打开本地doc(docdocxxlsxpdfppt)文档(官网最新43903版本SDK)-互联网文档类资源-CSDN下载
腾讯TBS初始化失败,加载失败问题 : https://blog.csdn.net/jifenglie/article/details/106669723
TBS腾讯浏览器服务x5内核打开本地doc(doc docx xlsx pdf ppt)文档(官网最新43903版本SDK)相关推荐
- 腾讯浏览服务X5内核集成
腾讯浏览服务X5内核集成 导读 1.什么是X5内核? 2.需求场景 3.开始搬砖 4.优化 5.集成后的问题 6.补充 一.什么是X5内核? 用官方文档的话说,就是解决系统webview兼容性差.加载 ...
- 腾讯文档网页版登录提示服务器,腾讯文档官网地址,腾讯文档电脑版pc端登录入口...
腾讯文档是腾讯近期推出的一款多人协作在线文档产品,不但打通QQ.微信和PC等多个平台,哪么腾讯文档官网地址是什么?有没有电脑版,想在pc端编辑文档怎么办呢?腾讯文档没有电脑版软件,但腾讯文档网页版可以 ...
- TencentTbs腾讯浏览服务 x5内核使用
Tencent TBS (下简称TBS) 腾讯浏览服务 What is it? 百度百科解释: 腾讯浏览服务(Tencent Browsing Service,以下简称TBS),由腾讯X5浏览服务升级 ...
- Android使用腾讯浏览服务X5内核
[前期准备] 腾讯X5 jar包下载地址 [点击打开] 本次完整DEMO源码 [打开Github] [集成步骤] 第一步:下载jar包添加到项目 第二步:添加权限 [java] view plainc ...
- 谷歌Chrome浏览器内直接打开编辑保存 Word、Excel、PPT 文档,可离线部署!
谷歌Chrome经过开发团队不断优化,凭借运行界面简单,打开速度最快及扩展插件众多,Chrome已经成为了世界上最受欢迎的浏览器.不过有一点非常可惜,由于微软Office不是开源程序,所以Chrome ...
- Android应用内打开.docx/.pdf/.xlsx/.txt等文档——腾讯TBS
Android应用内打开.docx/.pdf/.xlsx/.txt等文档-腾讯TBS 1.功能借鉴:https://blog.csdn.n ...
- Android实现通过浏览器点击链接打开本地应用(APP)
Android实现通过浏览器点击链接打开本地应用(APP)并拿到浏览器传递的数据 今天老大给我提了一个需求叫我调研一下,他已经测试了iOS平台上是可以的,需求很简单就是在系统浏览器中通过输入一个uri ...
- Android 应用内打开Word、Excel、PPT、PDF等文档
Android平台中,可以使用以下几种方式打开Word和Excel文档: 预览图: 一:直接上传给第三方之后用webview打开 1.微软: https://view.officeapps.live. ...
- 计算机如何打开office,win10电脑没有office软件如何打开ppt文档
一些用户在网上下载ppt文档,但是自己win10 64位系统电脑并没有安装office办公软件,所以一直打不开ppt,怎么办呢?针对win10电脑没有office软件却打不开ppt文档的问题, ...
最新文章
- 请收下这份NLP热门词汇解读
- hongyi lee 作业1
- Juju-Gui 安装笔记
- awk 脚本中使用正则表达式
- 中怎么构建ebug模式_自动挡中的“手自一体”,该怎么用?多少人把手动模式当成摆设?...
- [转]完美解决IE(IE6/IE7/IE8)不兼容HTML5标签的方法
- 技术生态两手抓,打造面向未来的企业级领先数据库
- 【Elasticsearch】使用Elasticsearch实现同段和同句搜索
- 如何去除计算机的访问限制,访问限制达成,教你如何禁止别人访问你电脑的C盘...
- 植物病害分类的深度可解释体系结构(github源码)
- 为什么B+树适合做索引
- android 4.0.4模拟器,Android 4.0.4模拟器安装(转自51CTO)
- [4G+5G专题-132]: 传输层 - 以太网电缆的类型(Cat5,Cat5e,Cat6,Cat6a)
- linux多线程之原子锁技术
- 中国人的宴席座次礼仪
- qcustomplot圆_Qt之QCustomPlot(图形库)
- Spring Boot 3.0.0-M1 Reference Documentation(Spring Boot中文参考文档)-附录A-C
- java 仿qq空间_仿QQ空间和微信朋友圈,高解耦高复用高灵活
- 第一周 一起走进摄影世界
- 波段合成,去除黑边并提取土地利用数据....下