获得AndroidManifest.xml文件中meta-data的value值工具类

package com.SLGames.Android;


import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;


public class GetMetadataValueUtils 
{
public static String getMetaDataValue(String name, String def)
{
   String value = getMetaDataValue(name);
   return (value == null) ? def : value;
}
 
private static String getMetaDataValue(String name) {
   Object value = null;
   
   PackageManager packageManager = ApplicationContext.getContext().getPackageManager();
   ApplicationInfo applicationInfo;
 
   try
   {
       applicationInfo = packageManager.getApplicationInfo(ApplicationContext.getContext().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();
}


}
阅读更多
上一篇得到Android设备的唯一id
下一篇001-支持并发的两次判空懒汉单例
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭