get Apk Version Code - Android android.content.pm

Android examples for android.content.pm:Apk Property

Description

get Apk Version Code

Demo Code

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import java.io.File;

public class Main{

    public static int getApkVersionCode(Context context, String apkPath) {

        if (context == null || apkPath == null) {
            return -1;
        }/*from  ww  w  .ja  v a2 s .co  m*/

        PackageManager pm = context.getPackageManager();
        PackageInfo info = pm.getPackageArchiveInfo(apkPath,
                PackageManager.GET_ACTIVITIES);
        if (info != null) {
            ApplicationInfo appInfo = info.applicationInfo;

            return info.versionCode;
        }

        return -1;
    }

}

Related Tutorials