0

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.

Community
  • 1
  • 1
Lucky
  • 1
  • 3
  • Are you trying to find the version of the app in a downloaded APK file or the version of your currently running app? – Aleks G Aug 08 '13 at 11:55
  • I am trying to find the version of the app in a downloaded APK file – Lucky Aug 08 '13 at 11:57
  • PackageInfo pInfo = getPackageManager().getPackageInfo("com.package.name.of.your.app", 0); version = pInfo.versionName; – Eugene Pinchuk Aug 08 '13 at 12:47
  • @EugenePinchuk That's not what the OP is asking. He needs to get version information from an APK file, not from an installed app. – Aleks G Aug 08 '13 at 13:24

1 Answers1

1

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;
}
Aleks G
  • 56,435
  • 29
  • 168
  • 265