为应用程序分配的 Android 内部存储空间是否有最大大小?

发布于 2025-01-03 22:10:15 字数 299 浏览 2 评论 0原文

我想保存一个包含所有应用程序数据的 json 文件(类似于首选项),但我不确定限制大小是多少,因为如果应用程序无法使用此文件,它可能无法运行。此信息是否事先已知,操作系统是否会根据可用大小为您的应用程序保留一些空间。

更新: 我不太关心外部存储,因为设备中并不总是可用并且可以更改(SD 卡),我可以检查 内部存储使用这个但这不是我想知道的,我想知道是否为设备的内部存储分配了内存大小?

I want to save a json file with all the application data (something similar to preference) but im not sure what is the limit size, because if the app cant use this file it will not function probably. is this information known beforehand and the OS reserve some space for your app or its based on the size available.

Update:
I dont really care about External storage since is not always available in the device and could be changed (SD card) and i could check for internal storage using this but this is not what i want to know, What i want to know if there's a memory size allocated for internal storage for the device ?

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

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

发布评论

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

评论(5

很快妥协 2025-01-10 22:10:15

如果您使用 Environment.getExternalStorageDirectory()(或Context.getExternalFilesDir() 对于 API 级别 8 及更高版本)作为 json 文件的位置,那么我相信大小将受到外部存储(通常是 SD 卡)中的可用空间的限制。对于大多数设备,我相信 Android 中没有内置外部文件存储的固定限制。 (内部存储是另一回事。设备制造商可以施加相当严格的限制,可能低至所有应用程序之间共享的 100MB。)

更新:请注意,根据 Android 2.3 的兼容性定义 (第 7.6.1 节),设备应该有相当多的内存:

设备实现必须具有至少 150MB 的非易失性存储空间可用于用户数据。也就是说,/data 分区必须至少为 150MB。

除了上述要求之外,设备实现应该至少有 1GB 的非易失性存储可用于用户数据。请注意,这
更高的要求计划成为 Android 未来版本的最低硬性要求。强烈鼓励设备实现满足
现在就满足这些要求,否则它们可能不符合未来版本 Android 的兼容性。

该空间由所有应用程序共享,因此可能会被填满。不保证每个应用程序可用的最小存储空间。 (这样的保证最小值对于需要存储超过最小值的应用程序来说毫无价值,并且对于存储较少的应用程序来说是一种浪费。)

编辑:来自 Android 4.0 的兼容性定义

设备实现必须具有至少 350MB 的非易失性存储空间可用于用户数据。也就是说,/data 分区必须至少为 350MB。

来自兼容性定义安卓4.3

设备实现必须至少有 512MB 的非易失性存储空间可用于用户数据。也就是说,/data 分区必须至少为 512MB。

有趣的是,实现应提供至少 1GB 的建议保持不变。

If you use Environment.getExternalStorageDirectory() (or Context.getExternalFilesDir() for API level 8 and up) as the place for your json file, then I believe the size will be limited by the available space in the external storage (usually an SD card). For most devices, I believe there are no fixed limits built into Android for external file storage. (Internal storage is a different matter. Device manufacturers can impose quite restrictive limits, perhaps as low as 100MB shared among all applications.)

UPDATE: Note that according to the compatibility definition for Android 2.3 (Section 7.6.1), devices should have quite a bit of memory:

Device implementations MUST have at least 150MB of non-volatile storage available for user data. That is, the /data partition MUST be at least 150MB.

Beyond the requirements above, device implementations SHOULD have at least 1GB of non-volatile storage available for user data. Note that this
higher requirement is planned to become a hard minimum in a future version of Android. Device implementations are strongly encouraged to meet
these requirements now, or else they may not be eligible for compatibility for a future version of Android.

This space is shared by all applications, so it can fill up. There is no guaranteed minimum storage available for each app. (Such a guaranteed minimum would be worthless for apps that need to store more than the minimum and would be a waste for apps that store less.)

Edit: From the compatibility definition for Android 4.0

Device implementations MUST have at least 350MB of non-volatile storage available for user data. That is, the /data partition MUST be at least 350MB.

From the compatibility definition for Android 4.3

Device implementations MUST have at least 512MB of non-volatile storage available for user data. That is, the /data partition MUST be at least 512MB.

Interestingly, the recommendation that implementations SHOULD provide at least 1GB has stayed the same.

睫毛上残留的泪 2025-01-10 22:10:15

我从未见过它限制单个应用程序,并且我之前已经通过在应用程序文件目录中保存一些相当大(200 mb)的视频文件来测试它。

对于内部存储,我认为您唯一的限制是可供所有应用程序共享的内部存储量。正如@Ted Hopp 提到的,在一些较旧的和低端的设备上它相当小。但在更新和更高端的设备上,他们已经开始将其提高到合理的数量,尽管即使设备有很多空间,它仍然可能被其他应用程序占用(因此您需要测试会发生什么)这种情况)。

还值得指出的是,如果您使用 SD 卡等外部存储,那么您的 json 文件在技术上可以由用户编辑。如果他们愿意,他们可以在文本编辑器中打开它并开始更改原始值。 (如果您选择使用内部存储,这也是可能的,但它需要有 root 权限的设备,而如果存储在 SD 卡上则不需要 root 权限)

因此,如果您存储的信息不希望用户拥有手动编辑的选项,您可能需要考虑到这一点。

I've never witnessed it limit a single application, and I have tested it with saving some rather large (200 mb) video files in the app Files dir before.

For internal storage I think your only limited by the amount of internal storage made available for all applications to share. Which as @Ted Hopp mentioned is rather small on some of the older and lower end devices. But on the newer and higher end devices they've started bumping it up to a reasonable amount, though even if the device has a lot of space, it could still be taken up by other applications(so you need to test what will happen in this scenario).

It is also worth pointing out that if you use external storage such as the SD card then your json file would technically editable by the user. They could open it up in a text editor and start changing the raw values if they had any desire to. (This is also possible if you choose to use internal storage, but it would require a rooted device, whereas if it is stored on the SD card would not require root)

So if you are storing info that you'd rather the user not have the option to manually edit, you may want to take that into consideration.

吾家有女初长成 2025-01-10 22:10:15

我认为硬性限制约为 3.61GB。

我目前在我的选项卡上安装了 termux。 Termux 运行一个 Linux 终端,我可以在其中安装 Nodejs 和 npm。从而实质上创建了一个开发环境。我安装的软件包没有太多与空间相关的问题,除非我的设备的内存非常低。但就最近而言。我想我已经达到了这个极限,这让我想到了这个问题并点击了这个页面。

我的设备存储空间远远超过 1GB,并且我使用低至 200MB 的空间时没有出现此问题。但我的 termux 安装已增长到 3.61GB。我最近开始使用纱线,看起来纱线是一个太空霸主。我正在安装一个包,突然记录了:
错误无法写入文件“/data/data/com.termux/files/home/dev/ide/theia/yarn-error.log”:“ENOSPC:设备上没有剩余空间

所以它破坏了安装并认为我真的用完了空间,但我没有。进一步检查发现,我的内部存储中仍然有上述空间,并且yarn已经占用了750MB,其中npm的缓存只有大约500MB。从那以后我一直在使用 npm,但只需要使用yarn,因为 Theia 的安装并没有很好地用 npm 完成。 Theia 似乎使用纱线作为他们的包管理器。因此 3.61GB 暗示是应用程序 + 数据的硬限制。

删除一些软件包并减少其他冗余软件包使用的一些空间,我获得了创建文件并根据需要安装的空间,但一旦我再次达到 3.61GB!繁荣!!!就是这样,我无法再创建任何文件了。

我认为这没有得到充分的记录,但它正在发生。

我正在使用棒棒糖(android 5.1)

为了断言这一点,其他人应该尝试使用在其内部沙箱中创建非常大的文件的应用程序。不是在内部存储中,而是在其私有数据区域中。我确信您可能会达到这个硬限制。

I think there is a hard limit of about 3.61GB.

I currently have termux installed on my tab. Termux runs a linux terminal where i can install nodejs and npm. Thereby essentially creating a development environment. I have installed packages without much space-related problems except when my device's internal memory is realy low. But as of recent. I think I have reached that limit, which brought me to this question and hit on this page.

My device storage is way beyond 1GB and I have used it with space as low as 200MB without this issue. But my termux installation has grown to 3.61GB. I recently started with yarn and it seems like yarn is a space hog. I was installing a package and it suddenly logged:
error Could not write file "/data/data/com.termux/files/home/dev/ide/theia/yarn-error.log": "ENOSPC: no space left on device

So it crushed the installation and thought i really ran out of space, but I hadn't. Further inspection shows that i still have the aforementioned space in internal storage and yarn has hogged 750MB, of which npm only about 500MB in cache. I have been using npm since, but just needed to use yarn as the installation for Theia wasn't finishing well with npm. Theia seems to be using yarn as their package manager. So 3.61GB hints to be the hard limit for app + data.

Removing some packages and reducing some space used by other redundant packages, I gain space to create files and install as I please, but as soon as I reach 3.61GB again!!! boom!!! that's it, I can't create any files anymore.

I don't think this is well-documented, but it is happening.

I am using lollipop (android 5.1)

To assert this, someone else should try to use an app that creates really large files in its internal sandbox. Not in the internal storage, but in its private data area. I am sure you will likely hit this hard-limit.

不如归去 2025-01-10 22:10:15

/sdcard/Android/data/ 中的每个应用程序绝对有 3.5 GB 左右的上限,至少在某些设备上是这样。这也适用于 Google 为官方 Android 模拟器提供的映像。
当我在某个使用 Unity 构建的 Android 应用程序下载大量图像、视频、音频数据时反复出现“磁盘空间不足”错误时,我注意到了这一点。每次当上述位置的文件夹增长到 3.5 GB 左右时都会发生这种情况。再多的清理空间也无法解决这个问题。
然而,关于这种行为的文献似乎为零。

There is definitely a cap around 3.5 GB per app in /sdcard/Android/data/, at least on certain devices. This also applies to the images provided by Google for the official Android Emulator.
I noticed this when I repeatedly got "out of disk space" errors in a certain Android app built with Unity that downloads a lot of image, video, audio data. Each time it happened when the folder in the aforementioned location grew to around 3.5 GB. No amount of clearing space will fix this.
There seems to be zero documentation about this behaviour, however.

忆沫 2025-01-10 22:10:15

更新 Ted 的评论;

根据 Android 7.0 的兼容性定义

Android TV 设备必须至少具有4GB 和其他设备实现必须具有至少 3GB 可用于应用程序私有数据的非易失性存储。

Update for the Ted's comment;

From the compatibility definition for Android 7.0

Android Television devices MUST have at least 4GB and other device implementations MUST have at least 3GB of non-volatile storage available for application private data.

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