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.
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
}
Related
I need download some images from web (the app will use these images) before first run of the application. During installation or during downloading from Google Play. Is it possible?
I need to use logos in the first Activity, that are put on the web archives. I would not do it, but the app should work without internet connectivity and when I want to download an image during the app running, I will not download it without the internet connection. That´s why I am asking, how to do it another way?
You need to download these images on the first launch of your application. Everytime the application is openned, you need to check if the images are available (in the folder you downloaded them). If not, you need to download them. Be sure to let the user know what you are doing, and make them waiting while you download them.
Other solution would be to include them directly in the .apk (add them in drawables/raw folder, they're meant to be used this way)
I've got a link for a media file on the web that my application usually plays using a MediaPlayer. I want the user to be able to download the file and save it on his device.
How can I download the file and save it on a predefined folder on his device.
I'm actually asking for two things
1) How to download a file
2) How to save a file to the device's memory.
You may want to do HTTP GET to get a file, start looking at HttpClient class and example, to save, data storage.
You've asked a very general question, so the best I can do is give you a general answer. To actually download the file itself, you'll probably want to use an HttpURLConnection. Make sure not to do this on the main thread UI thread as it will cause your app to freeze. You'll want to do it on separate thread using something like an AsyncTask. To actually have the user kick off the download, you'll probably want to put some sort of button in your UI that allows them to first select a folder and then once a folder is selected, you launch your AsycnTask. Android doesn't really have a builtin file manager, but you can could integrate with the OpenIntents file manager.
I am currently programming an "One time after first login tutorial" and since it should be only shown one time after the user starts the application for the first time, I would like to remove all the unnecessary files like for example pictures which I only use in this tutorial.
So is there a way to remove some of these files which are shipped within the .apk ?
The Android apk is a read only file, so once a file is part of an apk, it cannot be removed.
An option would be to download the files from the network the first time the user installs the app and then put it on the sd card or locally and then delete it when you want it.
I have 11 videos to include in my App. Each of them is around 9MB. Besides those, I have to a few sound files and image files in the app. Therefore the app size is going 100+MB. Is there any way to accommodate all the files so that app size does not become an issue for me?
Download the files after starting the app for the first time.
Puh..that's quite large. In such a situation I'd
Let the user download your app not containing any videos/audio files that cause the large size
At first run guide the user through a wizard where you download the additionally needed files to the SD card.
Still, downloading nearly 100MB won't be ideal, but better than directly download all of it at the first install. (IMHO)
The most common sollution i've seen is downloading them during the first run of the programme. Just check if everything is available, and if it isn't, download the needed files.
pros:
This way you can also add video's on the fly.
APK size stays small so initial download is quick
Cons:
after downloading the app you can't directly use it: content must be downloaded first
I would suggest you to put them in the assets folder, so they will not be compressed.
This way you'll have problems testing your project with eclipse, so try building it with command line, and then install on device with adb
In my scenario, I had 300+ videos, totalling upto 400+ MB of the size.
I checked with few of them and deployed the app the way i just told.
may not be the best way around, but may work.
You can upload into youtube or make your own simple video streaming server
I'm working on a platform=app for games and I want the user to be able to choose games like some kind of an add on, then it will download some file (a game) which my app knows how to read and work with.
Basically, what I want is to build a market without apk files.
Or to generate a new kind of apk files.
I hope you can understand my question..
The way I do it is to simply send a level to the client using the network connection.
My maps look like: [[0,1,2],[0,-1-1]...] which can be nicely compressed.
Even a big level doesn't take more than a few seconds to download.
You just need to generate your own 'level' code reader.
the way snesdroid works is it will play emulator files on the sd card, not sure if you could code the app to download files directly to the sdcard in a specific folder then have the app rescan that directory to refresh the levels.