伙计们,有没有办法通过java代码找到我手机中安装的youtube播放器的版本?
谢谢。
是的,这是可能的。与类PackageInfo
(参考:PackageInfo)
// The version number of this package, as specified by the <manifest> tag's
// versionCode attribute. Added in API level 1
public int versionCode
// The version name of this package, as specified by the <manifest> tag's
// versionName attribute. Added in API level 1
public String versionName
代码:
PackageInfo pinfo = null;
pinfo = getPackageManager().getPackageInfo("com.google.android.youtube", 0);
int versionNumber = pinfo.versionCode;
String versionName = pinfo.versionName;
尝试使用:
String versionName = context.getPackageManager().getPackageInfo("youtube's package name as String", 0 ).versionName;
int versionCode = context.getPackageManager().getPackageInfo("youtube's package name as String", 0 ).versionCode;
确保将其包装在一个try-catch
块中,NameNotFoundException
以防用户设备上未安装 YouTube。