简体   繁体   English

Android解压文件权限被拒绝

[英]Android untar a file permission denied

I have a tar file that I want to download from an API and un-tar it, on most devices the code below works fine but on few devices it gives an error我有一个 tar 文件,我想从 API 下载并解压缩它,在大多数设备上,下面的代码可以正常工作,但在少数设备上它会出错

code:代码:

val untar = arrayOf("tar", "-xvf", file.absolutePath, "-C", tempDirectory.absolutePath)
val process = Runtime.getRuntime().exec(untar)

Error on few devices only:仅在少数设备上出错:

tar: exec gunzip: Permission denied

Make sure you have the right android permissions:确保您拥有正确的 android 权限:

<manifest>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>

I am not sure, maybe tar which is a link to toybox is fine, but unzip which is a link to ziptool is not.我不确定,也许作为 toybox 链接的 tar 没问题,但作为 ziptool 链接的 unzip 不行。 Maybe you should try using apache commons compress, in order to bring your own dependecies and not rely on operation system issues, altough the solution is going to be more complex.也许你应该尝试使用apache commons compress,为了带来你自己的依赖而不是依赖操作系统问题,尽管解决方案会更复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM