简体   繁体   English

这对我来说是最好的存储选择吗?

[英]is this the best storage option for me?

I want to save downloaded images from a server. 我想保存从服务器下载的图像。 I want these images to be accessible only from within the application itself. 我希望只能从应用程序内部访问这些图像。 I don't want the images accessible from anywhere else, ie someone can just delete/modify it like if it was on the SD card or from another different application. 我不希望从其他任何地方访问这些图像,即有人可以像在SD卡上或其他应用程序中一样对其进行删除/修改。 I'm thinking it would be best if I were to use internal storage, as it is private to my app. 我认为最好使用内部存储,因为它对我的应用程序是私有的。

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal http://developer.android.com/guide/topics/data/data-storage.html#files内部

are there better options out there? 有更好的选择吗?

Internal storage is the best option if you want to keep your files private. 如果要使文件保密,则内部存储是最佳选择。

However, on most devices, internal storage is very limited and the users might uninstall your app if you use too much of it (images can be pretty big). 但是,在大多数设备上,内部存储空间非常有限,如果您使用过多的应用程序(图像可能很大),用户可能会卸载您的应用程序。

You should look into using the external storage to save images, and possibly encrypting them if you really want to keep them private. 您应该考虑使用外部存储来保存图像,如果您确实想将它们保密,则可以对它们进行加密。

As already mentioned by Raghav this would be a good option, and as said the internal storage is very limited (mostly on older devices), however if you are on a rooted device it will be possible to delete your files anyway. 正如Raghav所提到的,这将是一个不错的选择,并且说内部存储空间非常有限(主要是在较旧的设备上),但是,如果您使用的是root用户设备,则仍然可以删除文件。 Take into account the limited storage, as people is also making "swap partitions" on their SD cards because internal storage is very limited. 考虑到有限的存储空间,因为内部存储空间非常有限,人们还在其SD卡上制作“交换分区”。

This is is the simplest solution. 这是最简单的解决方案。 The other typical solution is to store the image as a blob in the application's database. 另一个典型的解决方案是将图像作为Blob存储在应用程序的数据库中。 This will make it completely inaccessable outside of your application. 这将使其在您的应用程序外部完全不可访问。 You can do it using the method shown here: 您可以使用此处显示的方法进行操作:

How to store and retrieve a byte array (image data) to and from a SQLite database? 如何在SQLite数据库之间存储和检索字节数组(图像数据)?

The draw back to this is the relatively small memory space you will be given for your DB (<60MB), so this only works if you have a small number of images. 缺点是为数据库提供的内存空间相对较小(<60MB),因此仅在图像数量较少的情况下才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM