android中获取package的versionCode和versionName

//获取当前软件的版本getPackageInfo("系统中其他已经案子的软件包名", PackageManager.GET_CONFIGURATIONS);

//获取系统日历的版本信息

packageInfo = getPackageManager().getPackageInfo("com.android.calendar", PackageManager.GET_CONFIGURATIONS);
System.out.println("versionCode:" + packageInfo.versionCode);
System.out.println("versionNode:" + packageInfo.versionName);
            
//获取当前软件的版本getPackageInfo("当前软件的包名,AndroidManifest.xml文件中跟节点manifest的package属性的值", PackageManager.GET_CONFIGURATIONS);
packageInfo = getPackageManager().getPackageInfo("com.example.apkinfo", PackageManager.GET_CONFIGURATIONS);
System.out.println("versionCode:" + packageInfo.versionCode);
System.out.println("versionNode:" + packageInfo.versionName);

你可能感兴趣的:(Android开发)