博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取androdmanifest里面的meta-data
阅读量:6447 次
发布时间:2019-06-23

本文共 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

你可能感兴趣的文章
flutter进行自动编译操作步骤
查看>>
4.6 直接插入排序法
查看>>
我的毕设总结所用的技术和只是要点 基于stm32F4的AGV嵌入式控制系统的设计
查看>>
盘点国内外那些有野心的BI公司
查看>>
JMeter—断言
查看>>
正则表达式
查看>>
结对编程总结
查看>>
结对作业——潘学
查看>>
冷备份恢复
查看>>
Pipeline MIPS Processor MIPS processor in C++
查看>>
PHP - 引用计数
查看>>
DO.NET操作数据库
查看>>
MapReduce计算每年最大值测试样例生成程序
查看>>
MapReduce计算每年最大值
查看>>
针对微信的一篇推送附有的数据链接进行MapReduce统计
查看>>
SpingMvc +WebSocket实现简单的在线聊天
查看>>
程序员面试逻辑题解析
查看>>
模拟QQ登录
查看>>
C++的新类创建:继承与组合
查看>>
m5-第9周作业
查看>>