在android中如何将应用程序缓存保存在内部SD卡中?
在我的应用程序中,从服务器下载大量文件。我想将它们缓存在SD卡中。 为此,我正在使用以下 api..
context.getExternalCacheDir();
但问题是,无法将它们保存在内部 sdcard(即;不可移动的外部存储)中。它们保存在“/mnt/sdcard/external_sd/Android/data/”中。
请给我一种将可能的文件保存到不可移动的 Android 缓存中的方法。
问候, 斯里尼瓦斯
In my application , downloading lot of files from server. I want to cache them in sdcard.
for that am using fallowing api..
context.getExternalCacheDir();
But problem is that, not able to save them in internal sdcard(i.e; non removable external storage).They are saving in to "/mnt/sdcard/external_sd/Android/data/".
Please gimme a way to save may files in to non removable android cache.
Regards,
Srinivas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自Entellisense for Environment.getExternalStorageDirectory:
“获取Android外部存储目录。如果用户已将其安装在计算机上、已从设备中删除或发生了其他问题,则当前可能无法访问该目录。您可以使用 getExternalStorageState() 确定其当前状态
注意:不要被这里的“外部”一词混淆。它是一个可以容纳相对较大数量的文件系统。数据并且在所有应用程序之间共享(传统上不强制执行权限),但它也可以实现为设备中的内置存储,与受保护的内部存储不同,并且可以安装为。计算机上的文件系统。
在具有多个“外部”存储目录(例如安全应用程序存储和可安装共享存储)的设备中,此目录代表用户将与之交互的“主要”外部存储。
应用程序不应该直接使用这个顶级目录,以避免污染用户的根命名空间。应用程序私有的任何文件都应放置在 Context.getExternalFilesDir 返回的目录中,如果卸载应用程序,系统将负责删除该目录。其他共享文件应放置在 getExternalStoragePublicDirectory(String) 返回的目录之一中。”
From intellisense for Environment.getExternalStorageDirectory:
"Gets the Android external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState().
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.
In devices with multiple "external" storage directories (such as both secure app storage and mountable shared storage), this directory represents the "primary" external storage that the user will interact with.
Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace. Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String)."