您的位置:首页 > 其它

安卓获取清单文件meta-data数据

2016-11-25 13:52 495 查看
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >

<meta-data
android:name="api_key"
android:value="iRFgdYoBfUP0n4YjVds1fGCD" />
</application>


假设我们要获取meta-data标签中的value值方法

// 获取ApiKey
public static String getMetaValue(Context context, String metaKey) {
Bundle metaData = null;
String apiKey = null;
if (context == null || metaKey == null) {
return null;
}
try {
ApplicationInfo ai = context.getPackageManager()
.getApplicationInfo(context.getPackageName(),
PackageManager.GET_META_DATA);
if (null != ai) {
metaData = ai.metaData;
}
if (null != metaData) {
apiKey = metaData.getString(metaKey);
}
} catch (NameNotFoundException e) {
Log.e(TAG, "error " + e.getMessage());
}
return apiKey;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: