获取youtube android应用程序的版本
我知道,伙计们, 有没有一种方法可以通过java代码找到我手机中安装的youtube播放器的版本 谢谢。尝试使用:获取youtube android应用程序的版本,android,youtube,Android,Youtube,我知道,伙计们, 有没有一种方法可以通过java代码找到我手机中安装的youtube播放器的版本 谢谢。尝试使用: String versionName = context.getPackageManager().getPackageInfo("youtube's package name as String", 0 ).versionName; int versionCode = context.getPackageManager().getPackageInfo("youtube's pac
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;
如果用户的设备上没有安装YouTube,请确保将其包装到
名称NotFoundException
的try catch
块中。是的,这是可能的。使用类PackageInfo
(参考:)
请问你为什么想知道youtube应用程序的版本?
// 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;