企业新闻

优势智云与您分享优势智云的发展动态,一起见证下一个里程碑

OpenModule Android 文档解析

2021/04/26 16:12 4847

公司继续在插件开发方面发力。近日,公司开发出安卓app 附件预览插件,还能够支付动态添加水印。

本插件适用安卓版本区间:5.0 - 11.0。能够覆盖目前绝大多数安卓手机。


说明,本插件只能打开本地文件,支持添加水印,文件预览放大缩小。

在App.vue配置初始化

复制代码onLaunch: function() {            console.log('App Launch')            console.log("初始化插件。")            const yszyunOpenModule = uni.requireNativePlugin('yszyun-OpenModule');
            yszyunOpenModule.init()
        },
传入路径,标题

openDocFile(path, title)

文件路径需转换为绝对路径

plus.io.convertLocalFileSystemURL("tempFilePath")

水印名字,如不需要水印,设置为空即可

str1: '水印测试', str2: '测试人员2',

引入模块

const openModule = uni.requireNativePlugin('yszyun-OpenModule');

调用方法

{                var _this = this;
                uni.showLoading({                    title: "文件下载中"
                })                const downloadTask = uni.downloadFile({                    url: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-81f1d72a-96c3-47b4-ab95-0a2aaf322724/' + url,                    success: (res) => {                        if (res.statusCode === 200) {                            console.log("下载成功 res res.tempFilePath:" + JSON.stringify(res));
                            _this.filePaths = plus.io.convertLocalFileSystemURL(res.tempFilePath);                            console.log("下载成功 res res.filePaths:" + _this.filePaths);
                            uni.hideLoading()
                            uni.showModal({                                title: '提示',                                content: "下载完成,打开" + title,                                success: function(res) {                                    if (res.confirm) {                                        console.log('用户点击确定');
                                        _this.openDocFile(_this.filePaths, title)
                                    } else if (res.cancel) {                                        console.log('用户点击取消');
                                    }
                                }
                            });

                        }
                    }
                });

                downloadTask.onProgressUpdate((res) => {                    console.log('下载进度' + res.progress);                    console.log('已经下载的数据长度' + res.totalBytesWritten);                    console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);

                });
            },
            openDocFile(path, title) {
                yszyunOpenModule.openFile({                    docPath: path,                    docName: title
                }, {                    angle: 20,                    isShow: true,                    str1: '水印测试',                    str2: '测试人员2',                    txtColor: '#44000000',                    txtSize: 12,                    verSpacing: 300,                    horSpacing: 150,                    strSpacing: 15,                    verPadding: 40,                    horPadding: 20
                });
            }

预览效果