5

Is it possible to learn which version of an application (such as facebook/twitter) installed on the device programmatically in android ?

Thanks...

sesamoslu
  • 145
  • 2
  • 10

1 Answers1

5

Yes, like this:

String packageToCheck = "com.facebook";          

List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
for (int i=0; i<packages.size(); i++) {
    PackageInfo p = packages.get(i);
    if (p.packageName.contains(packageToCheck)) {
        String name = p.applicationInfo.loadLabel(getPackageManager()).toString();
        String pname = p.applicationInfo.loadLabel(getPackageManager()).toString();
        String packageName = p.packageName;
        String versionName = p.versionName;
        int versionCode = p.versionCode;
        Log.i(TAG, name + ": " + pname + ": " + packageName + ": " + versionName + ": " + versionCode);
    }
}
Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • @Ken: Is there a way I can check whether Facebook app installed on the device is the latest..? – Mudassir Sep 30 '14 at 04:41
  • @Mudassir there is no "official" way but you could check the Google Play published version using this: http://stackoverflow.com/a/12091672/833647 and then compare the versionCode. If it is < the market version then it is not the latest. – Ken Wolf Sep 30 '14 at 05:24
  • @Ken: Thanks for the quick response. As it is not official, there is no guarantee it will be (always) supported on all devices. – Mudassir Sep 30 '14 at 06:12