开发者

Store data in the internal memory not on the sd card?

开发者 https://www.devze.com 2023-04-10 12:44 出处:网络
I\'ve been developing a content-based app for Android and I have over 120 MB of data that i need to store on the phone. I download this data from a server when the user first runs the app. My first qu

I've been developing a content-based app for Android and I have over 120 MB of data that i need to store on the phone. I download this data from a server when the user first runs the app. My first question is, is it ok if I store this data on the internal memory of the app using Context.getDir() method or is it better to store it on the sd card using Environment.getExternalStorageDirectory(). The problem with storing it on the sd card is that I would then have to secure this data somehow otherwise they woul开发者_JAVA技巧d be accessible to every other app or person. My second question is if it's okey to store that amount of data in the internal memory of the app then are they secure there?


For the First Question and For the Second Question


If you're intend to saving files to the internal memory, you'll just need to call a method like this:

FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);

If you set the Context.MODE_PRIVATE, it is not visible for other apps and even for you and user. Of course, this MODE_PRIVATE is useful only for the phone without root access. Those phones who have get rooted will have access to any folder in internal memory no matter if you set PRIVATE MODE or not.

Therefore if you decide to save your files in internal memory, despite of the sizes, you need to use some kind of encryption if you think these files should be kept privately.

As for the sizes, 120MB is a little bit oversized for data files saving on internal memory. The phones in the same era of Nexus One usually has 512MB internal memory, so from the user point of view, they don't like oversized app to occupy their internal memory because insufficient internal memory sometimes will cause the Android OS to stop receiving SMS and stop synchronisation.

All in all, because of the root access in nearly all Android phone, it is not safe to directly save your app private data to either external or internal memory. As for your 120MB data size, I recommend you do a simple encryption and save to SD Card.

Here's an excellent explanation on two storage types on saving files

And here's the Saving Options from Android Developers for your reference.


You must research on how to secure your data, cause your application data should be deployed/downloaded into the external storage sd card as an example. Cause many modern smartphones relies on the internal storage in as ram memory to run the applications.

Thats why I think you shouldn't install you applicatino data in the internal storage. I learned this developing for windows ce, windows mobile similar OS devices.

Thanks,


My suggestion is in internal memory.

Most of the devices should have the same storage partition shared between internal storage and SD card. Either way, you consume the same storage space. From the users' perspactive, there is no different between SD Card and internal storage except that the data in SD card could be shared in some ways which is not what you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号