android得到version name

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)