How to include data files with the app's APK?
Asked Answered
C

3

45

I want to create some pre-created files when my Android application is installed.

I would like to create the file in both the internal memory (data/data//files/) and in a newly created sdcard directories (/sdcard//data1/).

How can I do this?

Chemurgy answered 30/11, 2010 at 5:4 Comment(0)
E
42

You can save you files in \res\raw and write the code to store this files to the desired locations if it does not exist when the app start.
Check this to access the internal memory and sdcard
and access the raw file using the following

InputStream databaseInputStream = getResources().openRawResource(R.raw.yourfile);
Entomophagous answered 30/11, 2010 at 5:12 Comment(0)
P
45

If you have a larger number of files and a directory structure you should use /assets. These are not given any R-constants and can be scanned by your application

To open an asset-file:

InputStream is = getAssets().open("path/file.ext");

To list a directory:

String[] files = getAssets().list("");
Prepositor answered 30/11, 2010 at 10:31 Comment(1)
I think this is the correct answer. also see developer.android.com/reference/android/content/res/… and developer.android.com/tools/projects/index.htmlBrutality
E
42

You can save you files in \res\raw and write the code to store this files to the desired locations if it does not exist when the app start.
Check this to access the internal memory and sdcard
and access the raw file using the following

InputStream databaseInputStream = getResources().openRawResource(R.raw.yourfile);
Entomophagous answered 30/11, 2010 at 5:12 Comment(0)
C
2

It is worth mentioning that really large amounts of data can be dealt with APK Expansion Files.

In 2016, Google Play currently requires that your APK file be no more than 100MB. For most applications, this is plenty of space.

The APK size limit increases from time to time, so it's meaningful to check the current digit.

Chrismatory answered 29/3, 2016 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.