1

I was working on my application for android. And as I started it just now i gave the version as Version 0.01. and hard coded it in string.xml which is used in linear layout.

Now my question is: do android provide some method so that instead of hard coding the version no., android provide this. And when I want to update the version it is easily updated. If android does not provide such thing , is there some way through which I save myself from hard coding it.

Thanks in advance.

Android
  • 3,828
  • 9
  • 46
  • 79
  • 2
    possible duplicate of [User versionName value of AndroidManifest.xml in code](http://stackoverflow.com/questions/3637665/user-versionname-value-of-androidmanifest-xml-in-code) – David Snabel-Caunt Mar 05 '12 at 10:05
  • Sorry for duplicate question, should I remove it??????? I searched question but may be I missed out few more keyword. Sorry again to all users – Android Mar 05 '12 at 10:26

1 Answers1

5

You can enter the app version number in the android manifest file.

If you want to access the version from inside the code use the following code

getPackageManager().getPackageInfo(getPackageName(), 0).versionName

To add version number into the manifest use the following

manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc.app"
android:versionCode="6"
android:versionName="1.3.1 "
rfsk2010
  • 8,571
  • 4
  • 32
  • 46
  • I downvoted when your answer was simply 'You can enter the app version number in the android manifest file.' and now it's locked until you edit again. It is now correct, though this question should be closed as an exact duplicate. – David Snabel-Caunt Mar 05 '12 at 10:21
  • OK.now that the answer is correct, wouldn't it be right to negate the down vote? – rfsk2010 Mar 05 '12 at 10:32
  • I will but I can't unless you edit the answer due to a SO restriction – David Snabel-Caunt Mar 05 '12 at 10:35