I have a simple application that should handle (display, play…) data downloaded by users. I.e. when the user downloads the application (for free), it is empty, or filled just with some sample data, but then the user can download the actual content of their preference (and potentially pay for it via Android billing system). Each item is a folder with an xml file plus several sub-folders (such as audio and images). In the development phase the data are stored in the assets directory.
The payment itself is not a subject of the question at this point. I am actually interested in the following:
- where can I store the downloaded data in the phone so that it would be accessible for the application but so it could not be copied manually by the user (for example to another phone). It would be ideal if I could store the downloaded data in the assets directory but I’m afraid once the apk file is generated, assets are “locked” and cannot be easily extended (or can they?) If I store them on the phone’s card (or in the built-in memory), they will be accessible by other applications such as media player or galleries, too, won’t they?
- it would be great if I could download the package as a single single file – is it possible to upack it by an built-in method and store it as a folder with upacked (and thus readable) sub-folders and files?
- when the application is downloaded, it is an apk file. Therefore it should be possible to have the sample data (i.e. downloaded with the application) at the same location as the data that will be downloaded later. How can I ensure this.
- the data can be pretty large and therefore it is not an option to have all of them included in the assets folder immediate after the download and unlock it on basis of the user’s actions
- once the data are downloaded, they must work off-line (i.e. the user must be able to display them without internet access; thus it is not possible to check identity of the user on the server – they can simply display anything they have previously downloaded)
Example (for clarification purposes): have an application able to display recipes. It does not contain any or just a few after installation. You should be able to download recipes (one by one) from a server (each having a certain file structure stored in a seperate directory). Once they are downloaded, they become an integral part of the application and always accessible for the user even if the use the airplane mode of their phone.
Hope it makes at least some sense (I can clarify the question further if it doesn’t). I’ve found several tutorials on how to work with data stored in assets and on how to handle data on an sd card but none concerning this particular topic.
you may store your date in your application data folder, basically it’s available to your application only. if you want to prevent your data to be copied to another phone, generate a random UUID on the first run, and then use it to encrypt your data stored in the data folder. another phone will have different UUID and different encryption key, making it pointless trying to copy encrypted data. you may even use non-symmetrical encryption and send your generated (public) key to the server and have the server to encode your data and send it back in encrypted form, thus preventing your data to be exposed at all.
the
assets/folder is generally read-only, you may put your data there only during the build step.make your file a .zip file — these are compact and you may easily read files and folders and whatever you need using
java.util.zip.ZipFilesample data goes into
assetsfolder, you may copy it out to the data folder on the first run.once you download the data and save it to the device, i don’t see any reason why your application won’t work offline