{"id":25,"date":"2013-12-27T04:02:39","date_gmt":"2013-12-27T02:02:39","guid":{"rendered":"http:\/\/en.nisi.ro\/blog\/?p=25"},"modified":"2014-07-13T19:30:40","modified_gmt":"2014-07-13T17:30:40","slug":"android-get-versioncode-versionname-androidmanifest-xml","status":"publish","type":"post","link":"https:\/\/en.nisi.ro\/blog\/development\/java-android\/android-get-versioncode-versionname-androidmanifest-xml\/","title":{"rendered":"Android get versionCode and versionName from your AndroidManifest.xml"},"content":{"rendered":"<p>Sometimes showing version in your app is a good think, and when you do this a good think is to not have 2 ore more places where wou have to maintain tha app version for every releases.<\/p>\n<p>In your\u00a0<strong>AndroidManifest.xml<\/strong> there is required 2 fields<\/p>\n<p><strong>android:versionCode<\/strong> witch is an int with the app version<\/p>\n<p><strong>android:versionName<\/strong> witch is a string something like 1.0.1 showing app version.<\/p>\n<p>It is recomanded to use them and do not maintain a separate constant for using it in your code. Ok so programmatically you can retrieve this fields from your\u00a0<strong>AndroidManifest.xml<\/strong> like this:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/* Get android:versionName *\/\r\nString versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;\r\n\r\n\/* Get android:versionCode *\/\r\nint versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes showing version in your app is a good think, and when you do this a good think is to not have 2 ore more places where wou have to maintain tha app version for every releases. In your\u00a0AndroidManifest.xml there is required 2 fields android:versionCode witch is an int with the app version android:versionName witch [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[35,39,38,36,37],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-java-android","tag-androidmanifest-xml","tag-getpackageinfo","tag-getpackagemanager","tag-versioncode","tag-versionname"],"_links":{"self":[{"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":1,"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":26,"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions\/26"}],"wp:attachment":[{"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/en.nisi.ro\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}