Android 获取AndroidManifest.xml文件versionCode,versionName属性

转载地址:http://hzhlu.iteye.com/blog/1407768

Android 获取AndroidManifest.xml文件versionCode,versionName属性 

String pName = "cn.nedu.math.ninebox";
try {
        PackageInfo pinfo = getPackageManager().getPackageInfo(pName, PackageManager.GET_CONFIGURATIONS);
        String versionCode = pinfo.versionName;
        Strint versionName = pinfo.versionCode;
} catch (NameNotFoundException e) {
}

AndroidManifest.xml文件如下 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="cn.nedu.math.ninebox"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".NineBox"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="3" />
</manifest> 


你可能感兴趣的:(android,String,application,action,encoding)