What Do I Do To Get Compatibility Patch Download Off My Android Phone
I need to figure out how to get or make a build number for my Android application. I need the build number to display in the UI.
Do I have to do something with AndroidManifest.xml
?
8 things you should know about Apple Music for Android. With a list of choices installed on my phone. Apple Music isn't on that list and if I answer with 'Apple Music' Google doesn't.
Peter O.28 Answers
Use:
And you can get the version code by using this
Gastón SaillénIf you're using the Gradle plugin/Android Studio, as of version 0.7.0, version code and version name are available statically in BuildConfig
. Make sure you import your app's package, and not another BuildConfig
:
No Context object needed!
Also make sure to specify them in your build.gradle
file instead of the AndroidManifest.xml
.
Slightly shorter version if you just want the version name.
XaviThere are two parts you need:android:versionCode android:versionName
versionCode is a number, and every version of the app you submit to the Market needs to have a higher number then the last.
VersionName is a string, and can be anything you want it to be. This is where you define your app as '1.0' or '2.5' or '2 Alpha EXTREME!' or whatever.
Example:
Kotlin:
Java:
MerkidemisMerkidemisUsing Gradle and BuildConfig
Getting the VERSION_NAME from BuildConfig
Yep, it's that easy now.
Is It Returning an Empty String for VERSION_NAME?
If you're getting a empty string for BuildConfig.VERSION_NAME
then read on.
I kept getting an empty string for BuildConfig.VERSION_NAME
because I wasn't setting the versionName
in my Grade build file (I migrated from ANT to Gradle). So, here are instructions for ensuring you're setting your VERSION_NAME
via Gradle.
build.gradle
Note: This is from the masterful Jake Wharton.
Removing versionName
and versionCode
from AndroidManifest.xml
And since you've set the versionName
and versionCode
in the build.gradle
file now, you can also remove them from your AndroidManifest.xml
file, if they are there.
Here is a clean solution, based on the solution of scottyab (edited by Xavi). It shows how to get the context first, if it's not provided by your method. Furthermore it uses multiple lines instead of calling multiple methods per line. This makes it easier when you have to debug your application.
Now that you received the version name in the String myVersionName
, you can set it to a TextView or whatever you like..
If you're using PhoneGap, then create a custom PhoneGap plugin:
Create a new class in your app's package:
In the plugins.xml, add the following line:
In your deviceready event, add the following code:
Then, you can get the versionName attribute by doing:
Derived from here and here.
Sean HallSean HallFor xamarin users, use this code to get version name and code
1) Version Name:
2) Version Code:
RKRKIf you want to use it on xml then add below line on your gradle file:
And then use it on your xml like this:
Irfan RazaIrfan RazaTo get the build code which is used to identify the apk by its version code . Version code is used to detext the actual build configuraion at the time of database upgrade, publish etc.
int versionCode = BuildConfig.VERSION_CODE;
What Do I Do To Get Compatibility Patch Download Off My Android Phone Free
Version name is used to shoe the users pr the developers of the developmemt sequence.You can add any kind of version name as you want
String versionName = BuildConfig.VERSION_NAME;
There are some ways to get versionCode
and versionName
programmatically.
- Get version from
PackageManager
. This is the best way for most cases.
- Get it from generated
BuildConfig.java
. But notice, that if you'll access this values in library it will return library version, not apps one, that uses this library. So use only in non-library projects!
There are some details, except of using second way in library project. In new android gradle plugin (3.0.0+) some functionalities removed. So, for now, i.e. setting different version for different flavors not working correct.
Incorrect way:
Code above will correctly set values in BuildConfig
, but from PackageManager
you'll receive 0
and null
if you didn't set version in default
configuration. So your app will have 0
version code on device.
There is a workaround - set version for output apk
file manually:
No,you don't need to do anything with AndroidManifest.xml
Basically your app's version name & version code inside app level gradle file, under defaultConfig tag:
Note: When you wish to upload app in playstore can give any name as version name but version code have to be different than current version code if this app already in play store.
Simply use the following code snippet to get version code & version name from anywhere in your app:
for Api 28 the PackageInfo.versionCode is deprecated so use this code below:
This code was mentioned above in pieces but here it is again all included. You need a try/catch block because it may throw a 'NameNotFoundException'.
I hope this simplifies things for someone down the road. :)
Someone who does’t need BuildConfig info for application's UI however wants to use these info for setting a CI job configuration or others, like me.
There is a automatically generated file, BuildConfig.java, under your project directory as long as you build your project successfully.
{WORKSPACE}/build/generated/source/buildConfig/{debug|release}/{PACKAGE}/BuildConfig.java
Split information you need by python script or other tools. Here’s an example:
Please excuse my limited English ability, but hope this helps.
What Do I Do To Get Compatibility Patch Download Off My Android Phone Number
Atif MahmoodWhat Do I Do To Get Compatibility Patch Download Off My Android Phone Download
As I had to get only version code and check whether app is updated or not, if yes, I had to launch the playstore to get updated one. I did this way.
Then I saved version code using shared preference by creating an util class.
Useful for build systems: there is a file generated with your apk called output.json
which contains an array of information for each generated APK, including the versionName and versionCode.
eg
What Do I Do To Get Compatibility Patch Download Off My Android Phone App
protected by Community♦Mar 23 '18 at 15:05
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?