
这工作正常,但在某些情况下,外部存储的状态被删除或卸载等…我无法访问存储我的数据…
我的问题是,当这个存储不可用时,什么是一个很好的后备解决方案?
我的目标是Android 1.6及更高版本.
解决方法 请注意,您直接在 should not use环境中返回了Environment.getExternalStorageDirectory()返回的路径: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 byContext.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 bygetExternalStoragePublicDirectory(String).
使用getFilesDir()返回的路径在内部存储上存储应用程序专用的文件,或使用getExternalFilesDir()存储在外部存储上.
如果您要临时存储数据,请考虑使用缓存目录.
These files will be ones that get deleted first when the device runs
low on storage.
在外部文件系统上使用方法:getCacheDir()或getExternalCacheDir().阅读文档,了解它们之间的重要差异.
如果要存储的数据大小不大,那么最好使用内部存储.否则,您将不得不管理检测外部存储是否可用的复杂性,否则将不再支持内部存储.
总结以上是内存溢出为你收集整理的android – getExternalStorageDirectory不可用时的后备解决方案?全部内容,希望文章能够帮你解决android – getExternalStorageDirectory不可用时的后备解决方案?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)