Skip to content Skip to sidebar Skip to footer

How Do You Add User Defined Properties/values In To The Android Manifest File?

I want to add a custom attribute / property into the manifest file, and be able to read it at run time. I want to do this so I can customize the app's behavior via these manifest p

Solution 1:

You can add meta-data to your AndroidManifest.xml file and then read that in your application.

Write the data like so:

<meta-data android:value="bar" android:name="foo"></meta-data>

And read the data like so:

ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
Object value = (Object)ai.metaData.get("foo");

See http://developer.android.com/guide/topics/manifest/meta-data-element.html

Solution 2:

You can create an empty resource file in res/values and add strings and items (for bool or integer values) to it.

<?xml version="1.0" encoding="utf-8"?><resources><stringname="foo">bar</string">
    <itemname="testint"type="integer">33</item><itemname="testbool"type="bool">true</item></resources>

Alternatively you could simply use a Constants object in which you define your properties as final static variables.

Post a Comment for "How Do You Add User Defined Properties/values In To The Android Manifest File?"