get Meta Data String from Manifest - Android App

Android examples for App:Manifest

Description

get Meta Data String from Manifest

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;

public class Main {
    private static final String TAG = "ManifestHelper";

    private static String getMetaDataString(Context context, String name) {
        String value = null;/*ww  w.  j a  v  a  2 s .  co  m*/
        PackageManager pm = context.getPackageManager();
        try {
            ApplicationInfo ai = pm.getApplicationInfo(
                    context.getPackageName(), PackageManager.GET_META_DATA);
            value = ai.metaData.getString(name);
        } catch (Exception e) {
            Log.d(TAG, "Couldn't find config value: " + name);
        }
        return value;
    }
}

Related Tutorials