开发者

Android - add files into APK package?

开发者 https://www.devze.com 2023-02-19 07:38 出处:网络
is it possible to add to my apk file some XML file storing program version, 开发者_运维问答update path and other useful data (note: I don\'t mean Android XML file). All I want to is this file to be un

is it possible to add to my apk file some XML file storing program version, 开发者_运维问答update path and other useful data (note: I don't mean Android XML file). All I want to is this file to be unpacked somewhere to local data folder and I will use it for comparing version info installed locally and on the server in case of updates.

I am asking - is it possible to add to apk some other file?

Thanks


The assets/ folder in apk is intended to store any extra user files in any formats. They will be included to apk automatically on compilation stage and can be accessed from the app using getAssets() function. For example:

    final InputStream is = getResources().getAssets().open("some_file.xml")

It is even unnecessary to copy them to some local folder to read them.


If you only want to know the version info of the app then there is a much easier way to identify it. You can use

getPackageManager().getPackageInfo(getPackageName(),PackageManager.COMPONENT_ENABLED_STATE_DEFAULT).versionCode

to get the version code and

getPackageManager().getPackageInfo(getPackageName(),PackageManager.COMPONENT_ENABLED_STATE_DEFAULT).versionName

to get app's version name

0

精彩评论

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

关注公众号