The below snippet helps to find the application version
public static String getVersionName(Context context, String strPkgName)
{
try
{
return context.getPackageManager().getPackageInfo(strPkgName, 0).versionName;
}
catch (NameNotFoundException e)
{
Log.e("getVersionName()", ""+e.getMessage());
return "";
}
}
Here we have to pass context of the application and package name of the application that you want to find the version.
If the application exists(Installed) in the mobile then it will return the application version as string. otherwise it will return empty string.
public static String getVersionName(Context context, String strPkgName)
{
try
{
return context.getPackageManager().getPackageInfo(strPkgName, 0).versionName;
}
catch (NameNotFoundException e)
{
Log.e("getVersionName()", ""+e.getMessage());
return "";
}
}
Here we have to pass context of the application and package name of the application that you want to find the version.
If the application exists(Installed) in the mobile then it will return the application version as string. otherwise it will return empty string.
No comments:
Post a Comment