0

I want to decouple data from code on my Android application, and I am not sure of the best way to do that.

For instance - with the Linux Mahjongg game you can add new tiles to the game by dropping a specially formatted file into a specific directory. The Mahjongg game checks that directory when it starts up.

I want to do the same thing with my Android app - I want to be able to install the app, and then have separate installs for different data files. It's the data file installs that have me hung up. I do not want to have to set up my own server and write my own download code.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

2

You can ship the data with the installer app, then use Input/Output Streams to copy the data from the assets or raw dirs.

Check this out:

Ship an application with a database

The answer has an implementation of in/outputstream. You don't need to use a db, just copy the file to ext storage.

One important detail: if you put the file in assets, it will be shipped compressed, and the phone/tab will try to uncompress the file in its entirety in memory. One (hocky) way to avoid that is to name the file .mp3. Assets in .mp3 format are not compressed. (Hey! I said it was hocky!)

The installer app can either uninstall itself by using ACTION_DELETE in an intent (see http://android.amberfog.com/?p=98 for details) or just show a msg to the user that it's safe to delete the data app.

HTH,

llappall

Community
  • 1
  • 1
llappall
  • 2,852
  • 3
  • 23
  • 26
1

by dropping a specially formatted file into a specific directory

You can do that on external storage. Create a directory, and check it when your app starts up for new files. Tell the user they have to stick the magic files in the magic directory for it to work.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491