Embedding meta data in an application's manifest

Written by Xavier Gouchet - 19 november 2012 - 1 comment

A little tip I just discovered : besides having information on Activities, Services and such, you can embed any metadata inside an application's manifest.

To do this, simply include the following meta-data tag in an application, activity, activity-alias, service or receiver. The tag can either be used to store a value (int, float, string) or a resource id :

    android:value="1.5" />

    android:resource="@string/meta_owner" />

The meta data is stored in a Bundle instance, which you can retrieve using one of the following lines :

PackageManager pm = getPackageManager();
PackageItemInfo info;

info = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
info = pm.getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
info = pm.getReceiverInfo(component, PackageManager.GET_META_DATA);
info = pm.getServiceInfo(component, PackageManager.GET_META_DATA);
Bundle metaData = info.metaData; 

You can then read any metadata stored in the bundle using the getter methods.

1 comment

meta-data is not allowed to be below application see google documentation. we have devices where this causes issues in manifest parsing and very strange behavior (providers not exported or accessible etc).

#1 Written by : Reinhard (monday 05 august 2013 @ 17:49)

Write a comment

Enter image code :