| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package eVVM.apk.helper;
- import android.content.Context;
- import android.content.pm.PackageManager;
- import android.os.Bundle;
- /**
- * desc : 获取清单文件中的值
- */
- public final class ManifestHelper {
- /**
- * 获取 meta-data 的值
- */
- private static Bundle getMetaData(Context context) {
- try {
- return context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData;
- } catch (PackageManager.NameNotFoundException ignored) {
- return new Bundle();
- }
- }
- /**
- * 检查 key
- * @param context 上下文
- * @return meta-data
- */
- public static Bundle checkMetaData(Context context, String key) {
- Bundle metaData = getMetaData(context);
- if (!metaData.containsKey(key)) {
- // 清单文件没有设置这个 key
- throw new IllegalArgumentException("are you ok?");
- }
- return metaData;
- }
- /**
- * 是否有设置这个值
- *
- * @param context 上下文
- * @param key key
- * @return value
- */
- public static boolean contains(Context context, String key) {
- return checkMetaData(context, key).containsKey(key);
- }
- /**
- * 获取 Object
- *
- * @param context 上下文
- * @param key key
- * @return value
- */
- public static Object get(Context context, String key) {
- return checkMetaData(context, key).get(key);
- }
- /**
- * 获取 String
- *
- * @param context 上下文
- * @param key key
- * @return value
- */
- public static String getString(Context context, String key) {
- return checkMetaData(context, key).getString(key);
- }
- /**
- * 获取 boolean
- *
- * @param context 上下文
- * @param key key
- * @return value
- */
- public static boolean getBoolean(Context context, String key) {
- return checkMetaData(context, key).getBoolean(key);
- }
- /**
- * 获取 int
- *
- * @param context 上下文
- * @param key key
- * @return value
- */
- public static int getInt(Context context, String key) {
- return checkMetaData(context, key).getInt(key);
- }
- /**
- * 获取 long
- *
- * @param context 上下文
- * @param key key
- * @return value
- */
- public static long getLong(Context context, String key) {
- return checkMetaData(context, key).getLong(key);
- }
- /**
- * 获取 float
- *
- * @param context 上下文
- * @param key key
- * @return value
- */
- public static float getFloat(Context context, String key) {
- return checkMetaData(context, key).getFloat(key);
- }
- /**
- * 获取 double
- *
- * @param context 上下文
- * @param key key
- * @return value
- */
- public static double getDouble(Context context, String key) {
- return checkMetaData(context, key).getDouble(key);
- }
- }
|