public static function String getVersionName(Context context, Class cls)
{
try {
ComponentName comp = new ComponentName(context, cls);
PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
return pinfo.versionName;
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
return null;
}
}
本文介绍了一个用于获取Android应用版本名的公共静态函数,通过使用Context和Class参数,该函数能够从包管理器中获取版本信息。
1926

被折叠的 条评论
为什么被折叠?



