当我得到如下的版本代码时:
public static int getVersionCode(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
return info.versionCode;
} catch (Exception e) {
return -1;
}
}
这是发生时的痕迹:
java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:78)
答案 0 :(得分:0)
使用
PackageInfo info = context.getPackageManager()。getPackageInfo(context.getPackageName(),PackageManager.GET_META_DATA);
希望这行得通