android - 如何在安装 .apk 时将一些文件从 .apk 解压到/data/data/<package> 文件夹?

标签 android unzip

我的 android 应用程序需要另一个 NATIVE 应用程序可执行文件在 android 应用程序之前运行,以便它们可以通过套接字进行通信。 Android 应用程序有一个 JNI 层用于处理客户端通信。

现在我需要将 native 可执行文件与 apk 文件 bundle 在一起,以便在将其安装到设备上时将其解压缩到手机内存或存储卡中。

我该怎么做? 我尝试将 native 可执行文件保存在 res/asset 和 res/raw 文件夹中,但它们仍然没有解压缩到/data/data/文件夹中。

我能找到的一种方法是使用 AssetManager,然后在 InputStream 和 OutputStream 的帮助下,我可以在第一次运行时将此文件写入设备,然后使用它。但是手动将其写入手机内存是没有意义的,因为它可能会耗尽内存。 (没有存储卡的情况。)

任何人都可以帮助我实现这个目标吗?如果有一个选项可以在安装时自动解压缩必要的文件,那就太好了。

最佳答案

How do i do this?

你不知道。您在首次运行应用程序时自行解压缩。

One way I could find is to use AssetManager and then with help of InputStream and OutputStream, i can write this file onto the device the first time it is run and then use it.

正确。

But there is no point to write it manually on phone memory as it might eat up the memory.

那你为什么一开始就想让它自动解压呢?

It would be great if there is an option to unzip the necessary files automatically at the time of installation.

不,抱歉,这是不可能的。

关于android - 如何在安装 .apk 时将一些文件从 .apk 解压到/data/data/<package> 文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3913490/

相关文章:

java.lang.RuntimeException : Unable to start activity: com. google.android.apps.messaging.ui.conversationlist.ShareIntentActivity - 找不到资源

linux - 用于替换 zip 文件名称的 bash 脚本

bash - 如何将 GNU 与 find -exec 并行使用?

ruby-on-rails - Rails - 使用回形针上传 zip 文件并解压缩

java - zip4j 不提取具有大扩展名的文件

android - 如何在android中动态授予权限,即在运行应用程序时,这是可以实现的吗?

android - 在不调用弹出 fragment 的 onCreateView 的情况下清除 fragment 堆栈

android - Android 中 EditText 的马拉地语字体支持

Java ZipInputStream 在读取图像的 ZipEntry 后关闭

android - 从 TabHost 中删除 Tab 给我运行时异常 (NullPointerException)