7***@qq.com
7***@qq.com
  • 发布:2023-01-12 12:59
  • 更新:2023-01-12 15:42
  • 阅读:332

【报Bug】安卓使用uni.openDocument无法打开文件,ios可以

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 12.5

HBuilderX类型: 正式

HBuilderX版本号: 3.6.5

手机系统: Android

手机系统版本号: Android 10

手机厂商: 小米

手机机型: MI8

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
uni.downloadFile({  
						url: 'http://172.20.10.2:8080/order_all_report.xls',  
						success: (res) => {  
							console.log('download success', res)  
							if (res.statusCode === 200) {  
								uni.saveFile({  
									tempFilePath: res.tempFilePath,  
									success: function(res) {  
										plus.push.createMessage('download successfully', {  
											downloadFilePath: res.savedFilePath,  
										});  
									}  
								});  
							} else {  
								plus.push.createMessage("Download Fail");  
							}  
						},  
						fail: (err) => {  
							console.log("download fail", err)  
							plus.push.createMessage("Download Fail");  
						}  
					});  
  
plus.push.addEventListener('click', (result) => {  
				console.log("click", result)  
				const {  
					payload  
				} = result;  
				if (payload?.downloadFilePath) {  
					// plus.runtime.openFile(payload?.downloadFilePath, {}, (err) => {  
					// 	console.log("open error", err)  
					// })  
					uni.openDocument({  
						filePath: payload.downloadFilePath,  
						success(res) {  
							console.log("成功打开", res)  
						},  
						fail(err) {  
							plus.push.createMessage("Open Fail");  
						}  
					});  
				}  
				plus.push.clear();  
			}, false);

操作步骤:

下载文件后,打开文件

预期结果:

安卓成功打开文件,并提示使用什么软件打开改文件

实际结果:

安卓没有打开文件,没反应

bug描述:

调用uni.openDocument()无法打开文件,ios可以,wps等软件也已经下载

并且没有打开文件,还进入了success的回调,提示[Object] {"errMsg":"openDocument:ok"}

2023-01-12 12:59 负责人:无 分享
已邀请:
FullStack

FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866

更新下hbx

我手机红米 andorid11,有提示用哪个app打开文档

  • 7***@qq.com (作者)

    3.6.5的hbuildx了 算是最新版了吧


    2023-01-12 15:45

  • FullStack

    回复 7***@qq.com: 3.6.15,才是最新的,我用 alpha 最新版本测试的,,你打文档直接放在工程里,看看,可能你下载的文件不全


    2023-01-12 15:50

  • 7***@qq.com (作者)

    回复 FullStack: 大佬还是不行,最新版本打的包,只有杀死app,然后每次重新运行app,第一次调用openDocument的时候可以打开


    2023-01-12 16:29

  • FullStack

    回复 7***@qq.com: 是不是,勾选默认选项了?勾选之后,下次不会弹出,就直接打开了


    2023-01-12 16:39

  • 7***@qq.com (作者)

    回复 FullStack: 不是的点击直接没反应,我不知道为什么

    plus.push.addEventListener('click', (result) => {

    const { payload } = result;

    if (payload?.downloadFilePath) {

    setTimeout(() => {

    plus.runtime.openFile(payload.downloadFilePath, {}, (err) => {

    console.log("open error", err)

    })

    },1000)

    }

    });


    我现在是写在settimeout里面了。。。就可以了。。很神奇,分析不出来原因


    2023-01-13 10:59

要回复问题请先登录注册