Android-在编译时存储大文件

发布于 2024-12-01 23:55:04 字数 1036 浏览 3 评论 0原文

在这个美丽而过于复杂的框架中,究竟如何处理如此简单的事情呢?

是的,我已经阅读了 Android 数据存储的文档,大约 54.5 次。但我找不到文档描述如何在编译时将文件放置到外部存储上的任何地方。

这就是我想要做的:我想在我的应用程序中包含几个(大)(10-20mb)音频文件。当然,我不希望将它们存储在内部存储中,因为它们太大了。因此,将它们放在 res/raw 中不是一个选项(因为,如果我理解正确的话,res/raw 中的内容将放置在手机的内部存储中,对吗?)

该文档仅指出“如果您想存储静态编译时的文件,使用 res/raw”。现在,如果 Android 足够智能,可以自行将这些文件放在外部存储上,那么我将永远感激不已。但不知怎的,我对此表示怀疑。感谢所有帮助:) (抱歉,如果我看起来有态度,我只是在如此简单的事情上花了太多时间)

再次感谢:)

更新:我最终从应用程序下载了文件,而不是在安装时包含它们。感谢各位的帮助!

我在尝试通过网址下载时遇到了问题,花了很多时间尝试让它工作,最后问题是因为我没有在 android 清单文件中声明正确的权限!因此,对于任何想要在应用程序中下载内容的人,不要忘记在 Android 清单中设置权限,以下是我需要的权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

将这些权限放在标签开头上方

How exactly does one go about such a simple thing in this beautifully over-complicated framework?

Yes I've read the documentation on Data Storage for Android, about 54.5 times. But I can not find anyplace where the documentation describes how you should go about placing files on the external storage at compile time.

Here's what I want to do: I want to include a couple of (big) (10-20mb) audio files in my application. Naturally, I do not want these to be stored on the internal storage, because they're just too big. So placing them in res/raw is not an option (because, if I understand correctly, things in res/raw will be placed in the internal storage of the phone, correct?)

The documentation only states that "if you want to store static files at compile time, use res/raw". Now if Android is smart enough to place those files on the external storage all by itself then I'm forever greatful.. But somehow I doubt that. All help is appreciated :)
(Sorry if it seems like I have an attitude, I've just spent way too much time on something so simple)

Thanks again :)

UPDATE: I ended up downloading the files from the application instead of including them at install-time. Thanks for the help guys!

I hit a problem while trying to download through a url, spent a lot of time trying to get it to work, and in the end the problem was because I hadn't declared the correct permission in the android manifest file! So to anyone who's looking to download stuff in their apps, do not forget to set the permissions in the android manifest, here are the permissions I needed:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

Place these above the start of the tag

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

画▽骨i 2024-12-08 23:55:04

如果您的大文件位于 APK 中,它们将存储在 APK 存储的任何位置 - 这可以是内部或外部,这似乎不是您想要的。您最可能的选择似乎是将文件放在网站上,并且在应用程序首次运行期间,它必须注意到这些文件不存在并在安装后检索它们。

If your large files are in the APK, they'll be stored wherever the APK gets stored - this can be internal or external, and it seems that this is not what you want. The most likely option for you seems to be to place the files on a web site and during the first run of your application, it must notice that the files do not exist and retrieve them post-installation.

落叶缤纷 2024-12-08 23:55:04

您应该如何在编译时将文件放置到外部存储上。

我假设上面是一个拼写错误,您的意思是安装时

至于您的要求 - 在安装过程中不可能指示 Android 应用程序管理器将 APK 的不同部分解压到不同的位置。

除此之外,无法保证 APK 下载将进入内部或外部内存存储(除非以其他方式删除,否则它将保留在此处)。

更进一步,即使设备有外部存储,也不能保证它在安装时可用或有足够的可用空间。

此时,我想知道大小为 10-20MB 的音频文件 - 要么它们很长(持续时间),要么它们以高比特率编码。如果是后者,那么这没有多大意义,因为大多数移动设备的音频再现都相当差(相对而言)......只是一些需要仔细考虑的想法。

我个人认为马赫关于安装后下载的建议可能是更好的方法,但我关于外部存储可用性的评论仍然成立。

how you should go about placing files on the external storage at compile time.

I'm assuming the above is a typo and you mean at install time.

As for your requirement - it's not possible to instruct the Android Application Manager to unpack different parts of an APK to different places during the installation.

Further to this, there's no guarantee that an APK download will go to the internal or external memory storage (where it will stay unless otherwise deleted).

And even further to this, there's no guarantee that even if a device has external storage, it will be available at installation time or have enough free space.

At this point I wonder about audio files which are 10-20MB in size - either they're very long (in duration) or they're encoded at a high bit-rate. If it's the latter then this doesn't make too much sense as most mobile devices have fairly poor audio reproduction (in relative terms)....just some thoughts to mull over.

I personally think mah's suggestion of downloading post-installation may be a better approach but my comments about availability of external storage still hold true.

送你一个梦 2024-12-08 23:55:04

在 Android 上解决问题的正确方法是“不要将它们与您的应用程序放在一起”。只需在首次启动时从 Web 服务器下载它们(使用 HTTP 客户端 API),或者,如果这些文件将独立于应用程序本身进行升级,请将它们准备为单独的“应用程序”,供用户通过市场下载。

Proper approach to solving your problem on Android is "don't put them with your application". Just download them on first start from your web server (using HTTP client API) or, if these files will be upgraded independently of the application itself, prepare them as a separate "application" for the user to download via Market.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文