获取androdmanifest里面的meta-data
发布日期:2021-08-26 17:01:12 浏览次数:9 分类:技术文章

本文共 2931 字,大约阅读时间需要 9 分钟。

hot3.png

/* * Copyright 2017 JessYan * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.jess.arms.integration;import android.content.Context;import android.content.pm.ApplicationInfo;import android.content.pm.PackageManager;import java.util.ArrayList;import java.util.List;/** * ================================================ * 用于解析 AndroidManifest 中的 Meta 属性 * 配合 {@link ConfigModule} 使用 * 

* Created by JessYan on 12/04/2017 14:41 * Contact me * Follow me * ================================================ */public final class ManifestParser { private static final String MODULE_VALUE = "ConfigModule"; private final Context context; public ManifestParser(Context context) { this.context = context; } public List

parse() { List
modules = new ArrayList
(); try { ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo( context.getPackageName(), PackageManager.GET_META_DATA); if (appInfo.metaData != null) { for (String key : appInfo.metaData.keySet()) { if (MODULE_VALUE.equals(appInfo.metaData.get(key))) { modules.add(parseModule(key)); } } } } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Unable to find metadata to parse ConfigModule", e); } return modules; } private static ConfigModule parseModule(String className) { Class
clazz; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Unable to find ConfigModule implementation", e); } Object module; try { module = clazz.newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Unable to instantiate ConfigModule implementation for " + clazz, e); } catch (IllegalAccessException e) { throw new RuntimeException("Unable to instantiate ConfigModule implementation for " + clazz, e); } if (!(module instanceof ConfigModule)) { throw new RuntimeException("Expected instanceof ConfigModule, but found: " + module); } return (ConfigModule) module; }}

 

 

转载于:https://my.oschina.net/u/1177694/blog/3018631

转载地址:https://blog.csdn.net/weixin_33892359/article/details/92082963 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Mac系统如何显示隐藏文件
下一篇:IntelliJ IDEA (idea)引入eclipse web项目

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年02月12日 20时10分08秒