I would like to add a custom attribute to the application tag of my AndroidManifest.xml file. Is this possible in the Android environment?
2
-
i guess not ...but can you elaborate this...Its not blank– Its not blank2012-04-25 08:22:57 +00:00Commented Apr 25, 2012 at 8:22
-
Sure, my motivations are here: stackoverflow.com/q/10311504/183123. I would like to have an application register with a service I am developing. The target application need not be runningMM.– MM.2012-04-25 08:24:16 +00:00Commented Apr 25, 2012 at 8:24
Add a comment
|
5 Answers
Yes. Here's an example. The custom tag is ContentVersion.
<application android:name=".MyApplication"
android:icon="@drawable/icon"
android:label="@string/app_name">
<meta-data android:name="ContentVersion" android:value="1.9" />
<activity android:name="com.someone.something.MainActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:screenOrientation="sensor"
android:label="@string/app_name">
To access it:
ApplicationInfo ai = _context.getPackageManager().getApplicationInfo(_context.getPackageName(),PackageManager.GET_META_DATA);
ai.metaData.get("ContentVersion")
4 Comments
Sharanabasu Angadi
stackoverflow.com/questions/17972963/… can you suggest me
user128536
It appears that you can't add <meta-data> to an <application> tag. Here's the relevant doc: developer.android.com/guide/topics/manifest/…
Simon
@JoeBowers Thanks for that. Interesting! However, it does work, and continues to work in published apps so presumably under all later versions. I will test again though.
Bart Friederichs
@JoeBowers The documentation seems to be wrong. If I put that tag in a
<service> it doesn't work (metaData is null), but when it is in <application> it works fine.You cannot define custom attribute to a predefined tag, but you can add key-value pairs called meta-data.
Comments
6 Comments
njzk2
this is completely unrelated.
Sergi Juanola
Not completely. I was going for other solutions that could fit in this situation.
njzk2
tags in the manifest are added at compile time and accessed at runtime. sharedpreferences are created and accessed at runtime.
zapl
@njzk2 manifest is accessed even before runtime of your app to e.g. install the app.
njzk2
@zapl : by the system, yes. but you can access it during the runtime of your app
|