Is it possible to have custom attributes in AndroidManifest.xml tags?

后端 未结 5 1211
故里飘歌
故里飘歌 2020-12-13 06:44

I would like to add a custom attribute to the application tag of my AndroidManifest.xml file. Is this possible in the Android environment?

相关标签:
5条回答
  • 2020-12-13 06:56

    You could go for a SharedPreferences, instead (aka, settings).

    0 讨论(0)
  • 2020-12-13 06:58

    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

    0 讨论(0)
  • 2020-12-13 07:02

    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")
    
    0 讨论(0)
  • 2020-12-13 07:05

    You cannot define custom attribute to a predefined tag, but you can add key-value pairs called meta-data.

    0 讨论(0)
  • 2020-12-13 07:07

    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.

    0 讨论(0)
提交回复
热议问题