获取versionCode,versionName属性
String pName = "cn.nedu.math.ninebox";
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" />
String pName = "cn.nedu.math.ninebox";
try {
packagemanager pm = getpackagemanager();
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>
添加: pName可以用Context.gerPackageName()取得packageName.
转:http://hi.baidu.com/sunboy_2050/blog/item/c57baf0dec6850f7aa6457e0.html