11

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

Waypoint
  • 17,283
  • 39
  • 116
  • 170
  • Take a look at http://stackoverflow.com/questions/3535728/android-how-to-manually-add-a-file-to-apk – Adnan Mar 23 '11 at 09:24

2 Answers2

20

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.

GrAnd
  • 10,141
  • 3
  • 31
  • 43
2

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

pankajagarwal
  • 13,462
  • 14
  • 54
  • 65