我想保存一个包含所有应用程序数据的 json 文件(类似于首选项),但我不确定限制大小是多少,因为如果应用程序无法使用此文件,它可能无法运行。是否事先知道此信息,并且操作系统会根据可用大小为您的应用程序或应用程序保留一些空间。
更新: 我并不真正关心外部存储,因为设备中并不总是可用并且可以更改(SD 卡),我可以检查 internal storage using this但这不是我想知道的,我想知道是否为设备的内部存储分配了内存大小?
最佳答案
如果您使用 Environment.getExternalStorageDirectory()
(或 Context.getExternalFilesDir()
对于 API 级别 8 及更高版本)作为 json 文件的位置,那么我相信大小将受到外部存储(通常是 SD 卡)中可用空间的限制。对于大多数设备,我相信 Android 中没有针对外部文件存储的固定限制。 (内部存储是另一回事。设备制造商可以施加相当严格的限制,可能低至所有应用程序共享的 100MB。)
更新:请注意,根据 compatibility definition for Android 2.3 (第 7.6.1 节),设备应该有相当多的内存:
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.
此空间由所有应用程序共享,因此可以填满。没有保证每个应用程序可用的最小存储空间。 (这样的保证最低限度对于需要存储超过最低限度的应用程序来说毫无值(value),而对于存储量较少的应用程序来说则是一种浪费。)
编辑:来自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.
来自 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.
有趣的是,实现应该提供至少 1GB 的建议保持不变。
关于android - 为应用程序分配的 android 内部存储是否有最大大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9198440/