开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜