使用默认文件部署 android 个应用

Deploy android app with default files

我想在安装应用程序时在我的应用程序的文档目录中安装文件,如果需要,应用程序需要能够下载这些文件的新版本。

目前,我正在res/raw中打包这些文件并复制到本地。这是对 space 的浪费,因为设备将同时包含资源和本地副本。有没有一种机制可以让我将文件直接捆绑到可写目录而不是资源中?

这是我目前正在做的事情:

File moviesDir = cw.getDir("movies", Context.MODE_PRIVATE);
in = getResources().openRawResource(R.raw.tutorial);
file = new File(moviesDir,"tutorial.mp4");
copyInputStreamToFile(in,file);

Is there a mechanism that would let me bundle the file directly to a writable directory rather than in the resources?

不,抱歉。

Raw、asset 等捆绑在您的 apk 文件中,这在已安装的设备上当然是不可写的。您可以不将您的资源捆绑在 apk 文件中(即要求应用程序将其下载到其他地方)或承担开销。

注意:在您的情况下,根据您的用例,您可能会探索将其从原始资源直接流式传输到播放器。参见 Setting data source to an raw ID in MediaPlayer