简体   繁体   中英

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

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:

<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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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