Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取youtube android应用程序的版本_Android_Youtube - Fatal编程技术网

获取youtube android应用程序的版本

获取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

我知道,伙计们, 有没有一种方法可以通过java代码找到我手机中安装的youtube播放器的版本

谢谢。

尝试使用:

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;