Java tutorial
//package com.java2s; /* * Copyright 2014 Capptain * * Licensed under the CAPPTAIN SDK LICENSE (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://app.capptain.com/#tos * * This file is supplied "as-is." You bear the risk of using it. * Capptain gives no express or implied warranties, guarantees or conditions. * You may have additional consumer rights under your local laws which this agreement cannot change. * To the extent permitted under your local laws, Capptain excludes the implied warranties of merchantability, * fitness for a particular purpose and non-infringement. */ import android.content.Context; import android.content.pm.PackageManager; import android.os.Bundle; public class Main { /** * Get application meta-data of the current package name. * @param context application context. * @return meta-data, may be empty but never null. */ public static Bundle getMetaData(Context context) { return getMetaData(context, context.getPackageName()); } /** * Get application meta-data of a package name. * @param context application context. * @param packageName package name to get meta-data. * @return meta-data, may be empty but never null. */ public static Bundle getMetaData(Context context, String packageName) { Bundle config; try { config = context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_META_DATA).metaData; if (config == null) config = new Bundle(); } catch (Exception e) { /* * NameNotFoundException or in some rare scenario an undocumented "RuntimeException: Package * manager has died.", probably caused by a system app process crash. */ config = new Bundle(); } return config; } }