您的位置:首页 > 移动开发 > Android开发

android中获取AndroidManifest.xml中的MetaData标签值

2016-09-06 18:26 459 查看
private String getMetaDataValue(String name, String def) {

String value = getMetaDataValue(name);

return (value == null) ? def : value;

}

private String getMetaDataValue(String name) {

Object value = null;

PackageManager packageManager = context.getPackageManager();

ApplicationInfo applicationInfo;

try {

applicationInfo = packageManager.getApplicationInfo(context

.getPackageName(), 128);

if (applicationInfo != null && applicationInfo.metaData != null) {

value = applicationInfo.metaData.get(name);

}

} catch (NameNotFoundException e) {

throw new RuntimeException(

"Could not read the name in the manifest file.", e);

}

if (value == null) {

throw new RuntimeException("The name '" + name

+ "' is not defined in the manifest file's meta data.");

}

return value.toString();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: