Is there any possibility to get the versionCode of an App without the getPackageManager? My Problem is, that i want a public Configuration class which have no Activity, so the getPackageManager() does not work. Any Idea?
My current Code:
PackageInfo pinfo;
try {
pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
} catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
pinfo = null;
}
appVersion = pinfo.versionCode;
Take an instance of Context in the constructor of your non-activity class and use that to call all such methods.
Something like this:
Then do this to create an object of that class in your Activtiy’s
onCreate():