Android:永久保存文件(即使在清除数据/卸载后)
我想知道是否有办法永久存储少量数据。
我所说的永久是指即使用户清除应用程序数据/卸载应用程序,我也希望数据能够保留。
我知道当用户清除应用程序数据/卸载应用程序时,共享首选项和数据库将被删除。
我也知道我可以在 SD 卡上保存内容,但是如果设备没有 SD 卡怎么办/ SD卡未挂载?
我认为最好的选择是将数据保存在设备内存上,但是在清除应用程序数据/卸载应用程序时是否可以在不删除数据的情况下做到这一点?
I would like to know if there is a way to store a small amount of data permanently.
By permanently I mean I want the data to persist even if user clears app data / uninstalls app.
I know that shared preferences and databases are deleted when user clears app data / uninstalls app.
I also know that I can save stuff on SD Card, but what if device does not have SD Card /
SD Card is unmounted?
I think that the best option would be to save the data on device internal memory, but is it possible to do that without getting the data deleted when clears app data / uninstalls app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不应该这样做,你不应该强迫用户在未经他们同意的情况下将数据保存在他们的手机上。
无论如何,应用程序数据目录将在卸载后被删除,但在更新后不会被删除
拥有持久数据的唯一方法是使用SD卡,但同样,用户不喜欢在应用程序卸载后将数据保留在卡上
或者您可以考虑:
You shouldn't do that, you shouldn't force the users to keep data on their phones without their consent.
Anyway, application data directory will be deleted after uninstall, but NOT after an update
The only way to have persistent data is to use the SD card, but again, users won't like to have the data on their card after the app is uninstalled
Or you can consider:
Environment.getDataDirectory()
至少是一个可以保存文件的目录。它位于内部存储(/data)上。我使用它的一种情况是定义一个服务是否正在运行;我在其中创建一个 .lock 文件并始终检查它是否存在。
Environment.getDataDirectory()
is at least one directory where you can save files. It's on the internal storage (/data).One case I use it is to define whether a service is running; I create a .lock file in there and always check whether it exists or not.