1、读取版本信息、应用名称
/**
* 版本号
*/
public String getVersion(){
PackageInfo pkg;
try {
pkg = getPackageManager().getPackageInfo(getApplication().getPackageName(), 0);
// 应用名称
String appName = pkg.applicationInfo.loadLabel(getPackageManager()).toString();
// 版本号
String versionName = pkg.versionName;
return versionName;
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
2、Appliction 的Meta-data
/**
* appliction MetaData读取
*/
private void getApplicationMetaData() {
ApplicationInfo info;
try {
info = this.getPackageManager().getApplicationInfo(
getPackageName(), PackageManager.GET_META_DATA);
String msg = info.metaData.getString("tel");
System.out.println("tel:" + msg);
msg = info.metaData.getString("channel");
System.out.println("channel:" + msg);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
3、Activity中的Meta-data
/**
* activity MetaData读取
*/
private void testActivityMetaData() {
ActivityInfo info;
try {
info = getPackageManager().getActivityInfo(getComponentName(),
PackageManager.GET_META_DATA);
String msg = info.metaData.getString("name");
System.out.println("name:" + msg);
msg = info.metaData.getString("city");
System.out.println("city:" + msg);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}