Search code examples
androidembedded-resource

Deploy android app with default files


I want to install files in my application's documents directory when installing the app, and the app needs to be able to download a new version of these files if needed.

At the moment, I am packaging these files in res/raw and copying them locally. That's a waste of space since the device will contain both the resource and the local copy. Is there a mechanism that would let me bundle the file directly to a writable directory rather than in the resources?

Here is what I am doing at the moment:

File moviesDir = cw.getDir("movies", Context.MODE_PRIVATE);
in = getResources().openRawResource(R.raw.tutorial);
file = new File(moviesDir,"tutorial.mp4");
copyInputStreamToFile(in,file);

Solution

  • Raw, asset, etc are bundled in your apk file, which is of course not writable on an installed device. You can either not bundle your resources in the apk file (ie. require the app to download it elsewhere) or bear with the overhead.

    Note: in your case, depending on your use case, you may perhaps explore streaming it from the raw resource to the player directly. See Setting data source to an raw ID in MediaPlayer