Finding app version number in code - android

Is there a simple way to find the current version of my application from within it? I would like to add the version string to the about screen.

You should check this question.
I am doing it this way:
try {
String pkg = mContext.getPackageName();
mVersionNumber = mContext.getPackageManager().getPackageInfo(pkg, 0).versionName;
} catch (NameNotFoundException e) {
mVersionNumber = "?";
}

please try out this.
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;

Related

Android - Versionsname in a Textview not work correct on appstoreupdate

I will show the Versionname of my app in a textview. have anyone an idea why this only changes if you reinstalled the app and not on an update?
String appversion = "Version " + context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
The reading works perfectly! My question was: I have an app with version 1.1 in the store. After an update to 1.2 the Textview still contains 1.1.(only on update) But if the app is reinstalled then 1.2 will be displayed. Why is that, and how can I fix it?
You can get current version name using
String versionname = "";
try {
versionname = getApplicationContext().getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
TextView versionname = (TextView) findViewById(R.id.textName);
versionname.setText(versionname);
to get Version Name : use below code :
public String getVersion(){
PackageInfo versionInfo = getPackageInfo();
String title = context.getString(R.string.app_name) + " v"
+ versionInfo.versionName;
return title;
}
private PackageInfo getPackageInfo() {
PackageInfo info = null;
try {
info = context.getPackageManager().getPackageInfo(
context.getPackageName(), PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return info;
}
define your context If you are in fragment then
context = getActivity();
if you are in activity then context = this.
then set it to your textview like
textview.settext(getVersion());

Version of VideoView for Android

I have an Android application. Сan I get the version of VideoView programmatically?
Maybe there's a way to find it using the firmware version?
please try this code :
try {
PackageInfo pInfo = this.getPackageManager().getPackageInfo("video player package name", 0);
String version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

How to get Custom SW version number of android

I have a Marshmallow device. It has custom built SW.
I have seen the build.prop file. There I can perceive the Software version name comes from ro.custom.build.version
My question is - how can I get the "ro.custom.build.version" information programmatically in my application ?
I got the answer. It is very simple -
First, I created a function to read from SystemProperties.
public String getSystemProperty(String key) {
String value = null;
try {
value = (String) Class.forName("android.os.SystemProperties")
.getMethod("get", String.class).invoke(null, key);
} catch (Exception e) {
e.printStackTrace();
}
return value;
}
And then called the function with "ro.custom.build.version" as a key
getSystemProperty("ro.custom.build.version");
Special thanks to #sasikumar for giving me the hint
You have to do as below :
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
To get the Version code, Use as below :
int verCode = pInfo.versionCode;
Check android.os.Build.VERSION. You can use INCREMENTAL.

How can I compare A app and B app version on android? without market

A app and B app same app.
only different version
recently my phone have A app
and my server have B app.
I want if my server have recently version
change app .
How can I do?
use BufferedReader ?
thanks
this will get the current App version
PackageManager manager = context.getPackageManager();
PackageInfo pInfo = null;
try {
pInfo = manager.getPackageInfo(context.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
String cuurentVersion = pInfo.versionName;
and you can do some version check on server by a webservice.. That you have to do

How do I get the version number of an application in Android?

We have a set of 3-5 android applications that we have developed for an enterprise to integrate with our back-end. How do we create an installer system that upgrades applications automatically. We were thinking of getting version numbers and querying the backend to get current versions and downloading them.
How do I get the version number of an application in Android?
ApplicationInfo info = getApplicationInfo();
try {
info = getPackageManager().getApplicationInfo(info.packageName, PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
Any pointers will be most useful.
Thanks
Sameer
Using the function below you can get the current Version Name or No for the application.
This you can check against that of the app at server side and if needed you can upgrade app.
public static function String getVersionName(Context context, Class cls) {
try {
ComponentName comp = new ComponentName(context, cls);
PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
return pinfo.versionName;
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
return null;
}
}

Categories

Resources