get Meta Data As Object - Android android.content.pm

Android examples for android.content.pm:PackageManager

Description

get Meta Data As Object

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 Object getMetaDataAsObject(Activity context, String key) {
        ActivityInfo info = getActivityInfo(context);
        return info == null ? null : info.metaData.get(key);
    }//  ww  w .  jav a2 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