在项目中需要加入预览文件功能,在网上搜索了大部分的回答,集合自己的项目综合考虑,调用WPS的方式更加适合自己,简单不用第三方的sdk,但是手机中得安装WPS。下面是代码:(复制的)
- Intent intent = new Intent();
- Bundle bundle = new Bundle();
- bundle.putString(WpsModel.OPEN_MODE, OpenMode.NORMAL); // 打开模式
- bundle.putBoolean(WpsModel.SEND_CLOSE_BROAD, true); // 关闭时是否发送广播
- bundle.putString(WpsModel.THIRD_PACKAGE, getPackageName()); //getPackageName()是你的项目包名
- bundle.putBoolean(WpsModel.CLEAR_TRACE, true);// 清除打开记录
- // bundle.putBoolean(CLEAR_FILE, true); //关闭后删除打开文件
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setAction(android.content.Intent.ACTION_VIEW);
- intent.setClassName(PackageName.NORMAL, ClassName.NORMAL);
- File file = new File(path);
- if (file == null || !file.exists()) {
- System.out.println("文件为空或者不存在");