在Android开发中,有时需要读取meta-data中的内容,以下示例:
这里示例内容为
<meta-data
android:name="test"
android:value="hello android" />
读取meta-data标签下关键代码:
private String readMeta() {
String metaStr = "";
try {
ApplicationInfo applicationInfo =
getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo != null && applicationInfo.metaData != null) {
metaStr = (String) applicationInfo.metaData.get("test");// 这里为对应meta-data的name
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return metaStr;
}