I would like to add a custom attribute to the application tag of my AndroidManifest.xml file. Is this possible in the Android environment?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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")
回答2:
You cannot define custom attribute to a predefined tag, but you can add key-value pairs called meta-data.
回答3:
You could go for a SharedPreferences, instead (aka, settings).
回答4:
In the tag (as well as service and receiver), you can use the tag (http://developer.android.com/guide/topics/manifest/meta-data-element.html )
It contains a name and a value or a resource ID.
You retrieve it through the PackageManager.
回答5:
If anybody needs that for Xamarin (Mono for Android) I couldn't find the constant, but i found the value for it, which is 128.
I used a "for" condition to go through all values from 0 to 1000 and check whenever the MetaData property was not null. lol