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

你说的曾经没有我的故事 提交于 2019-12-17 07:17:24

问题


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?


回答1:


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



回答2:


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

To open an asset-fil:

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

To list a directory:

String[] files = getAssets().list("");



回答3:


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.



来源:https://stackoverflow.com/questions/4310695/how-to-include-data-files-with-the-apps-apk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!