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

<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;
    }
原文地址:https://www.cnblogs.com/muyuge/p/6152099.html