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 properties. How can this be done?
How do you add user defined properties/values in to the Android manifest file?
22.5k views Asked by inor At
2
There are 2 answers
5
On
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>
<string name="foo">bar</string">
<item name="testint" type="integer">33</item>
<item name="testbool" type="bool">true</item>
</resources>
Alternatively you could simply use a Constants object in which you define your properties as final static variables.
You can add meta-data to your
AndroidManifest.xml
file and then read that in your application.Write the data like so:
And read the data like so:
See http://developer.android.com/guide/topics/manifest/meta-data-element.html