Waypoint
Waypoint

Reputation: 17763

Android - add files into APK package?

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

Upvotes: 11

Views: 20253

Answers (2)

GrAnd
GrAnd

Reputation: 10221

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.

Upvotes: 20

pankajagarwal
pankajagarwal

Reputation: 13582

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

Upvotes: 2

Related Questions