2010-06-07 83 views
1

我想知道是否有反正确定不是通过包,而是通过应用程序应用程序的版本是不是当前的应用程序。确定应用程序版本

比方说现在我在应用程序A的范围,我想从运行应用程序B.我想要的应用程序B.

感谢的版本代码前检查,

射线的活动。

回答

4

这是我使用验证版本的方法,如果一个特定的包已经安装或不:

/** 
* Returns the version number we are currently in 
* @param appPackageName - full name of the package of an app, 'com.dcg.meneame' for example. 
*/ 
public static int getAppVersionCode(Context context, String appPackageName) { 
    if (context!= null) 
    { 
     try { 
      return context.getPackageManager().getPackageInfo(appPackageName, 0).versionCode; 
     } catch (NameNotFoundException e) { 
      // App not installed! 
     } 
    } 
    return -1; 
} 
+0

是的,但后来agian我需要的包名..我不能仅仅通过应用程序名称进行搜索? – rayman 2010-06-08 08:46:09

+0

就像我知道的那样,你不能。考虑到应用程序名称位于本地化文件(Strings.xml)中,以便可以更改。包名称不会更改。 – Moss 2010-06-08 12:50:09