开发者

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

开发者 https://www.devze.com 2023-01-10 12:54 出处:网络
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 wer

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 thi开发者_开发百科nking 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;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号