In my Travel app which depends on lot of images. I have implemented a Lazy Loader and Caching of images. In total for all the destinations the images are close to 20mb. If a User wants to download all the Images so that he can still access the app offline. How can i make sure the caching of the files work with the downloaded image files.
There are two possibilities for your app, depending on what exactly you are wanting to do. Feel free to read more about this at the Android Docs.
Internal Storage
This directory persists, and is private to your application. It might have limited space, especially for older devices.
SD Card
This will have much more space, but will be accessible to the user and other apps. You could store information in your private storage to verify the integrity of this data. You will need a permission to write to the card.
I would suggest you choose one of these two, and store your data there. This should persist from run to run. Perhaps you could even include a function that would "Pre-cache" all of the files to the appropriate folder. 20 Mb isn't really that much space, you could even include it in your app itself. It's all up to you.
Related
Is there a place where I can store and manage my own images outside of internal storage? I don't want other apps to be able to see or access these images. Should I use external storage? Does such a place exist in the new MediaStore? It's fine if they're deleted when the app is deleted.
This solution needs to support API 21 or higher.
I know there are a lot of questions like this, but they're 10+ years old and a lot has changed since then.
Use case / background
I have an app where all data is stored locally on the device (no external servers).
Users can choose custom background images for journal entries. A user could choose to use a different image for each journal entry they create. They can create as many journal entries as they want. They may revisit those journal entries. So, I need to store an unknown amount of images for the lifetime of the app. I've been saving a copy of the images the user picks from the gallery in my local app storage via context.filesDir.
I noticed a crash Fatal Exception: android.database.sqlite.SQLiteDiskIOException disk I/O error (code 4874 SQLITE_IOERR_SHMSIZE) and after googling, I found This error may indicate that the underlying filesystem volume is out of space.
My concern is that my app is running out of internal storage space because of the user images I'm storing.
Where should I be storing these images? I originally chose internal storage because I wanted my users' images to be reasonably private (since I don't know if they're storing sensitive images or not). I also wanted to make sure the images would always be available even if the source image (chosen from user's media) is deleted. However, I hadn't considered the limits imposed on internal storage. Silly me!
Darshil's answer is correct. Using the recommended Storage Access Framework for your use case, you should use getFilesDir() which will return your app's internal storage, which is private to your app.
Where should I be storing these images?
problem is due to limit of resource which is out of our control. However if you really want to store all the images, you can take some approaches:
1. Online: Use some cloud servers for storing user data. This might cost you a lot.
2. Offline: Tell user that you have only the limited amount of storage and storing more images will require to delete some older ones.
3. Both: Store in device. When internal storage is running low, tell user to buy some type of premium subscription to store unlimited cloud photos.
Android does not provide a place for you to store private photos (can't be accessed by user or other apps) outside of app's internal storage. I know you can contradict me by saying that one can store them in external storage by using getExternalStoragePublicDirectory() but the problem is that it is a shared directory accessible to users and other apps and remains when the app is deleted.
So I suggest you to use getFilesDir() as the directory returned by it is hidden from users and is deleted when the app is deleted. And also implement a image compressing tool in your app which automatically compresses images when uploaded by the user and then save it to internal storage. This won't solve the problem completely but I guess it's a start.
I would recommend checking out AWS Amplify which allows you to integrate your application with AWS services. For what you have described, you could use amplify to give your app the ability to authenticate users and set up cloud storage on AWS S3 which you can configure to only allow users to access and edit files that they have uploaded. One nice thing about AWS Amplify and AWS S3 cloud storage is that there is a free tier which allows you to develop your application for little to no cost. Depending on the amount of data that you will be uploading, it may be quite a while before you surpass the free tier limits.
A guide like this one may help you learn more.
I am not sure if I fully understand your question, but writing a quick tip.
try cloud services to store your images like AWS s3, cloudinary. Cloudinary is much cheaper if you want to try like 25gb/month free.
With limited storage space appearing to be the root cause, I recommend intentionally using the UI to encourage users to use existing images over new images. (This can work in addition to the technical options provided in other answers)
For example, present the user with a list of available background images and a link to add a new image. In this case, using an existing image is 1 click with a preview, where getting a new image requires opening a new view and searching for the new image.
Using the UI in this way doesn't directly get you more space, but it can help you to more efficiently use the space you have by guiding users to use existing images. It also gives you a place to warn about (or limit) adding more images when there is not more space available.
*If you still must have more storage on the device outside of the app, you could try using the public space with encryption for "privacy".
I'm developing an ebook reader app for Android. The special books for this app are zipped files of some html/css/js/image/... files which are in a server and will be downloaded by the app. Each zipped file may have 1-5 MB and if extracted, a lot more than that.
I was wondering, regarding to android guidelines, where is suitable to
Put the zipped book files?
Put the extracted files when they are being used?
Well, if you actually need to save that data when app finishes, you should use sd-card, since it has more space, but if you only download image one time, just to show it on screen than use internal storage. Also consider your lowest API since that will be phone with least storage, and your app needs to work there as well as on new devices. Either way if you have to make several files while extracting data, use internal storage because it will be faster, and move it later to sd card if you actually need to save it.
I am downloading files from a remote server to be saved for use on an android device. These files are mostly images and audio but I would like it so that a user cannot access this data using methods other than the app.
The issue is that these files could be large and that's why I use external storage. The problem here is that users can access the data stored on external storage by hooking the phone up to a computer.
Apart from using internal storage, do I have any options to secure the files written to disk?
If I do have to use internal storage, are there any other disadvantages other than the fact that some users might have a small amount of internal storage?
Thanks for your time! Any help will be much appreciated! :)
EDIT 1 :
The data being downloaded is paid content (via In App Billing). This is why I'm concerned about restricting access.
EDIT 2 :
I am already adding a "." before the folder I'm saving my data to. I'm more concerned about 'power' users who would know to look in hidden folders.
Seems like you are populating app's cache from web. It is always recommended to use external storage for such purposes because some users may not have enough internal memory to accommodate this.
Since you downloading includes images and audios, i wouldn't suggest you to use encryption/decryption as it will slow down the app's processing. So there's nothing much you can do to secure your data if you want to put on external memory and skip its encryption.
I personally don't think any harm/disadvantage to leave such data as it is (not encrypted). But if you have some of the files important, perhaps you may perform encryption on those particular files only.
I have to store a lot of images that have to be downloaded from the web server. The size of the images might be 80Mb. So I want a guidance where to store them, whether in internal or external storage. Both create some problems for me. Internal storage is as every one knows is very limited but the problem with external storage is that images can be accessed by user. I don't wanna my application images to be exposed to user and changed or deleted. So is there any alternative or is there any technique to safely put data into external storage?
Unfortunately no, external storage has FAT file system, which does not support access restriction. And you simply must not store such large chunks of data in internal memory (or otherwise users will not like you, to put it mildly).
So the only way to go, is to use external storage. If you need some protection, then you may either encrypt/decrypt data. Or just obfuscate data, like changing file extensions, or adding 10 bytes at the beginning of each file. Obfuscation is more efficient resource-wise, but much less protected. Though encryption key can still be extracted from your application, so both of this approaches have their flows.
I would advice to store them in the external storage. If you don't want the user to be able to read it, protect it with an encryption. I think it's a bad idea to impose large data to the user. If the user wants to remove it, you shouldn't want to prevent it. Perhaps consider the possibility of re-download the pictures from the web if it has been deleted.
Use encryption for file content:
i found nice and lightweight sample code on http://www.androidsnippets.com/encryptdecrypt-strings
I recommend saving to external. Preventing the user from deleting his data is not recommended. Also user can format the sdcard to delete it. so you cannot stop the user. You can hide it from him. Just prefix a dot to the folder name to make it hidden.
If you are using Android 2.3, OBB is your choice.
http://developer.android.com/reference/android/os/storage/StorageManager.html
OBBs contain a filesystem that maybe be encrypted on disk and mounted on-demand from an application. OBBs are a good way of providing large amounts of binary assets without packaging them into APKs as they may be multiple gigabytes in size. However, due to their size, they're most likely stored in a shared storage pool accessible from all programs. The system does not guarantee the security of the OBB file itself: if any program modifies the OBB, there is no guarantee that a read from that OBB will produce the expected output.
Related
What is OBB(Opaque Binary Blob) in Android develop site?
My app has several image and media files, which are around 1MB each or so. So if i follow the normal way, the app size is crossing over 40MB, which is huge. Is there anyway to avoid this?
I have heard of external storage, but i really don't get any clue of how to work on them!
Do i need to ask all those who instal this to save the images and media files in the external disk and then the app uses those? This makes my files public..isn't it?
I actually don't own a android device. So is it like, whenever people install an app from the market, does it ask if it has to install in the phone memory or the external memory?
I really need your help.
If there is a way, i'd be thankful if you can provide me the step by step details of how this can be done!
Thanks a lot..
Regards
Nithin
There is, from the little I know of this, a slight security risk from putting files onto the SD card. I don't think I personally would worry too much about that since most people that would want access to the files in your apk (Which does not include your source code) could get it regardless without too much trouble.
As of Android 2.2 the user has the option to move an app to their SD card, but only if the developer explicitly tells the app to allow it. I'm fairly sure this only applies to 2.2+ devices though, so being that you are likely going for a larger audience than that it isn't an end-all solution. I am only really pointing this out in case you do end up putting one large file on the market. If so, be sure to allow the transfer to SD card, your app will stay on devices much longer.
Downloading the files online from within the app and saving them out to the SD card would be a good solution, though I am not sure how end users feel about downloading a small app then having to download a very large package before using it. In the end they will have to download it either way, so it is up to you whether you want to ask them to do it up front in the market or afterwards via the app. If you do want to try to download all the content then maybe the code example in this link will help you figure it out :
http://androidsnips.blogspot.com/2010/08/download-from-internet-and-save-to-sd.html
You might consider streaming the files or downloading them inside the application to the sdcard. Speaking from experience my users have had problems downloading apps as big as 30MB. Some phones also have a severely limited internal memory, which is where the applications are downloaded to.