2013-02-13 51 views

回答

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不會安裝在用戶的設備上。

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; 
相關問題