매니페스트에 다음과 같이 밑줄 된 값이 필요할때 다음과 같이 가져온다.


AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.si.pe.shin.library"
android:versionCode="1"
android:versionName="3.7.0" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:description="@string/app_name"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activity.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

/**
* 매니페스트 버전을 얻는다
* @param context context
* @return 버전
*/
public static String getVersionName(Context context) {
String version = "";
try {
PackageInfo i = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
version = i.versionName + "";
} catch(NameNotFoundException e) {
}
return version;
}
/**
* 매니페스트 버전코드를 얻는다
* @param context context
* @return 버전코드
*/
public static int getVersionCode(Context context) {
int versionCode = 1;
try {
PackageInfo i = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
versionCode = i.versionCode;
} catch(NameNotFoundException e) {
}
return versionCode;
}
/**
* 매니페스트 Description를 얻는다
* @param context context
* @return 어플아이디
*/
public static String getDescription(Context context) {
String appId = "";
try {
PackageManager pm = context.getPackageManager();
PackageInfo i = pm.getPackageInfo(context.getPackageName(), 0);
appId = i.applicationInfo.loadDescription(pm) + "";
} catch(NameNotFoundException e) {
}
return appId;
}

/**
* 매니페스트 Label을 얻는다
* @param context context
*/
public static String getAppLabel(Context context) {
String appName = "";
try {
PackageManager pm = context.getPackageManager();
PackageInfo i = pm.getPackageInfo(context.getPackageName(), 0);
appName = i.applicationInfo.loadLabel(pm) + "";
} catch(NameNotFoundException e) {
}
return appName;
}


728x90
반응형

+ Recent posts