Here we go:
private String getVersionName(Context context,Class class_name)
{
try
{
PackageInfo pinfo;
ComponentName comp = new ComponentName(context,class_name);
pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
return pinfo.versionName;
}
catch (Exception e)
{
return null;
}
}
Happy coding:-)
private String getVersionName(Context context,Class class_name)
{
try
{
PackageInfo pinfo;
ComponentName comp = new ComponentName(context,class_name);
pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
return pinfo.versionName;
}
catch (Exception e)
{
return null;
}
}
Happy coding:-)
Thanks for sharing information.
ReplyDeleteJavin
How classpath works in Java
@Javin: If my sharing is usefull to you, then I'm happy:-)
ReplyDeleteWell, with respect to above post: Its a good practice to return any other relevant values other than "null". I have read this suggestion in one of blog post(not sure but I suppose from Dzone). So please correct the same while implementing..