Nayan
Nayan

Reputation: 367

How may I know my android app's previous Version name/code when I update to latest version

I have developed an android app and I have saved the current version name/code in sharedprefs so that on next releases I would get the previous version name/code every time I update the app so that to handle compatibility issues.

But as the previous versions of the app don't contain this functionality so I can't get the previous version/code and so can't handle compatibility issues.

Does android notify that "xyz" was the previous version of the app while updating to latest version?

Any help is appreciated.

Upvotes: 1

Views: 1136

Answers (1)

karan
karan

Reputation: 8853

You can get current version name and version code programmatically. You can get the current version of installed apk and check for the version you need. you can get the current version code and name of apk using below code.

try {
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(getPackageName(), 0);
    String version = pInfo.versionName;      //version name
    int verCode = pInfo.versionCode;         //version code
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
}

It is not possible if you want to check previous apk version before you install new version programmatically.

Upvotes: -1

Related Questions