0

伙计们,有没有办法通过java代码找到我手机中安装的youtube播放器的版本?

谢谢。

4

2 回答 2

1

是的,这是可能的。与类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;
于 2013-02-13T15:19:36.507 回答
0

尝试使用:

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。

于 2013-02-13T15:19:33.353 回答