android meta-data获取

取得meta-data中的数据

在manifest中声明:
<meta-data android:name="MY_META_KEY" android:value="输入的value37483748937429" />

    public static String getAppKey(Context context) {
        Bundle metaData = null;
        String appKey = null;
        try {
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
                    context.getPackageName(), PackageManager.GET_META_DATA);
            if (null != ai)
                metaData = ai.metaData;
            if (null != metaData) {
                // MY_META_KEY是meta-data中对应的key值
                appKey = metaData.getString(MY_META_KEY);
                if ((null == appKey) || appKey.length() != 24) {
                    appKey = null;
                }
            }
        } catch (NameNotFoundException e) {
        }
        return appKey;
    }

你可能感兴趣的:(android,metadata)