4

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

1 Answer 1

4

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;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.