sleejay
sleejay

Reputation: 51

How can I package binary files with my APK, and copy them to sdcard

I have 2 binary files that i would like to package with my apk. (/res/raw)

i need to copy these 2 files to /sdcard when the application is run

how can i do this?

Upvotes: 2

Views: 3648

Answers (3)

CaseyB
CaseyB

Reputation: 25048

You need to use the AssetManager.

That will give you can InputStream that you can copy to a FileOutputStream.

Upvotes: 2

Ron Albury
Ron Albury

Reputation: 31

We have the same issue ... the direction we are exploring is to have two separate installs - the first one is the app and the second one is the data-app. When the data-app installs it copies the binary files to the SD card. When we uninstall the data-app it frees up the internal storage.

We don't have this one completely licked yet, and would love to hear other input and maybe find someone to help us by writing a couple of skeletal sample applications for us.

There are so many people who are in this boat (based on my googling) that if this approach doesn't work I suggest we (or someone) set up a generic file delivery web server and generic file delivery Android service and make it available to developers for a very low cost.

Upvotes: 3

snctln
snctln

Reputation: 12225

It all depends on what your goal is by doing this.

Are you trying to be nice to the user and conserve disk space on the device by moving files to the sdcard? Or do you merely want to ensure that these files are on the sd card?

If you just want to put the files on the sdcard then you should use the AssetManager as CaseyB mentioned

If you are trying to conserve phone memory then consider distributing the apk file without the 2 raw files, and then on first run download the files from a server that you have set up. This may cause a bit of a problem due to the time needed to download the files, but some users on devices with limited memory available on the device itself will be appreciative of it.

Upvotes: 1

Related Questions