5

是否可以在 android 中以编程方式了解设备上安装的应用程序的哪个版本(例如 facebook/twitter)?

谢谢...

4

1 回答 1

5

是的,像这样:

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);
    }
}
于 2013-06-28T10:48:14.033 回答