开发者

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

开发者 https://www.devze.com 2023-01-27 07: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

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?


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("");


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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号