AnimatedRNG
AnimatedRNG

Reputation: 1939

Downloading resource files in Android

I've been trying to make a game, and I'm getting the background music to work right now. The files are simply too large to fit in the res/raw directory and compile into an apk, so I'm downloading them from online. This is a good solution; it doesn't use up any space on the phone and it plays smoothly, just that it won't work if the phone can't connect to the internet when the app is running. A better solution would be to download the music when the app starts for the first time, but I can't find the documentation on how to do this.

Any help would be appreciated.

Upvotes: 0

Views: 4357

Answers (1)

Cristian
Cristian

Reputation: 200100

A better solution would be to download the music when the app starts for the first time, but I can't find the documentation on how to do this.

There are lots of documentation of how to download a file. So, if you want to know when the app starts the first time you can do it using SharedPreferences (here is an example).

Also, you can check if the files are there before trying to download them:

File theFile = new File("/sdcard/blah");
if(!theFile.exists(){
    // if it does not exists it means that it has not been downloaded
    // or maybe the user delete it
}

Upvotes: 1

Related Questions