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

来源:互联网 发布:eclipse生成java程序 编辑:程序博客网 时间:2024/06/11 20:03
privateString getMetaDataValue(String name, String def) {
 
    String value = getMetaDataValue(name);
 
    return(value == null) ? def : value;
 
}
 
privateString 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) {
 
        thrownew RuntimeException(
 
        "Could not read the name in the manifest file.", e);
 
    }
 
    if(value == null) {
 
        thrownew RuntimeException("The name '" + name
 
        +"' is not defined in the manifest file's meta data.");
 
    }
 
    returnvalue.toString();
 
}
0 0