How do you add user defined properties/values in to the Android manifest file?

核能气质少年 提交于 2019-11-28 17:49:41
P.Melch

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!