Lucky
Lucky

Reputation: 1

How can I get version of release before updating application?

I am beginner in android programming, so please help me to find out in some questions and sorry for my English. I develop application on eclipse for android. And I want to develop module of load update file from website. I know how can I get update file, load and launch it from programm code (example of code you can see by this link Android: install .apk programmatically). But before I want to get version of release of update file. And I don't know how I can do it. May be somebody developed the same module and can give me advise.

Upvotes: 0

Views: 129

Answers (1)

Aleks G
Aleks G

Reputation: 57316

You can use PackageManager for this purpose. I have successfully used this code in my app:

PackageInfo info = context.getPackageManager().getPackageArchiveInfo(apkPath, PackageManager.GET_META_DATA);
if(info != null) {
    ApplicationInfo appInfo = info.applicationInfo;
    if(Build.VERSION.SDK_INT >= 8) {
        appInfo.sourceDir = apkPath;
        appInfo.publicSourceDir = apkPath;
    }       
    String version = info.versionName;
    int vcode = info.versionCode;
}

Upvotes: 1

Related Questions