Android Manifest文件中meta-data的配置读取

Manifest文件中配置meta-data的读取,例如如下配置信息:

<meta-data

            android:name="AA_DB_NAME"

            android:value="Pickrand.db" />

 

读取方式

public static <T> T getMetaData(Context context, String name) {
		try {
			final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
					PackageManager.GET_META_DATA);

			if (ai.metaData != null) {
				return (T) ai.metaData.get(name);
			}
		}
		catch (Exception e) {
			Log.w("Couldn't find meta-data: " + name);
		}

		return null;
	}



private int getMetaDataDatabaseVersionOrDefault() {
			Integer aaVersion = ReflectionUtils.getMetaData(mContext, AA_DB_VERSION);
			if (aaVersion == null || aaVersion == 0) {
				aaVersion = 1;
			}

			return aaVersion;
		}

		private String getMetaDataSqlParserOrDefault() {
		    final String mode = ReflectionUtils.getMetaData(mContext, AA_SQL_PARSER);
		    if (mode == null) {
		        return DEFAULT_SQL_PARSER;
		    }
		    return mode;
		}

 

猜你喜欢

转载自lynen.iteye.com/blog/2162105