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

1 try {
2
3 packagemanager pm = getPackageManager();
4
5 PackageInfo pinfo = pm.getPackageInfo(gerPackageName(), PackageManager.GET_CONFIGURATIONS);
6 String versionCode = pinfo.versionName;
7 Strint versionName = pinfo.versionCode;
8 } catch (NameNotFoundException e) {
9 }

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 获取AndroidManifest.xml文件versionCode,versionName属性 .)