get Meta Data As String - Android App

Android examples for App:Manifest

Description

get Meta Data As String

Demo Code


//package com.java2s;
import android.app.Activity;

import android.content.pm.ActivityInfo;

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

public class Main {

    public static String getMetaDataAsString(Activity context, String key) {
        ActivityInfo info = getActivityInfo(context);
        return info == null ? null : info.metaData.getString(key);
    }/*from  w  w w .  java  2 s .co  m*/

    private static ActivityInfo getActivityInfo(Activity context) {
        PackageManager packageManager = context.getPackageManager();
        try {
            return packageManager.getActivityInfo(
                    context.getComponentName(),
                    PackageManager.GET_META_DATA);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related Tutorials