一、版本信息、應用名稱java
/** * 測試版本信息 */ private void getVersion(){ PackageInfo pkg; try { pkg = getPackageManager().getPackageInfo(getApplication().getPackageName(), 0); String appName = pkg.applicationInfo.loadLabel(getPackageManager()).toString(); String versionName = pkg.versionName; System.out.println("appName:" + appName); System.out.println("versionName:" + versionName); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
二、Appliction 的Meta-dataapp
/** * appliction MetaData讀取 */ private void testApplicationMetaData() { 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(); } }
三、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(); } }