Friday, September 27, 2013

Using Android application meta-data

Passing meta data from Android manifest XML file

Meta data can be defined through in the manifest file and retrieved through the API.

Example <meta-data> tag such as ...

<meta-data name="string" resource="resource specification" value="string">


The <meta-data> can be contained in <application>, <activity>, <activity-alias>, <service> and <receiver>. An example <meta-data> in application level looks like ...

<application icon="@drawable/icon" label="@string/app_name">
<meta-data name="aKey" value="aValue">
...
</meta-data>

To retrieve the meta data in program (says in Activity class) ...

ApplicationInfo ai = getPackageManager().getApplicationInfo(this.getPackageName(), PackageManager.GET_META_DATA);
Bundle aBundle=ai.metaData;
String aValue=aBundle.getString("aKey");