- 構文:
<meta-data android:name="string" android:resource="resource specification" android:value="string" />
- 上位の要素:
<activity>
<activity-alias>
<application>
<provider>
<receiver>
<service>
- 説明:
- 親コンポーネントに提供可能な任意の追加データアイテムの名前と値のペア。コンポーネント要素には任意の数の
<meta-data>
サブ要素を含めることができます。すべてのサブ要素の値が 1 つのBundle
オブジェクト内に集められ、コンポーネントでPackageItemInfo.metaData
フィールドとして利用できます。通常の値は
value
属性で指定します。リソース ID を値として割り当てるには、代わりにresource
属性を使用します。たとえば、以下のコードは、@string/kangaroo
リソースにどのような値が格納されていても、名前としてzoo
に割り当てます。<meta-data android:name="zoo" android:value="@string/kangaroo" />
一方、
resource
属性を使用すると、リソースに格納されている値ではなく、リソースの数値 ID がzoo
に割り当てられます。<meta-data android:name="zoo" android:resource="@string/kangaroo" />
関連データを複数の個別
<meta-data>
エントリとして提供しないようにすることを、強くおすすめします。そうではなく、コンポーネントに関連付ける複雑なデータがある場合はリソースとして保存し、resource
属性を使用してコンポーネントにその ID を伝えます。 - 属性:
android:name
- アイテムの一意の名前。名前を一意にするには、Java スタイルの命名規則(「
com.example.project.activity.fred
」など)を使用します。 android:resource
- リソースへの参照。リソースの ID はアイテムに割り当てられた値です。ID は、
Bundle.getInt()
メソッドを使用してメタデータBundle
から取得します。 android:value
- アイテムに割り当てられた値。以下の表に、値として割り当てることができるデータ型と、コンポーネントでこれらの値を取得する場合に使用する
Bundle
メソッドを示します。
タイプ Bundle メソッド 文字列: 二重バックスラッシュ( \\
)を使用して文字をエスケープします。たとえば、改行の場合は\\n
、Unicode 文字の場合は\\uxxxxx
です。getString()
整数: 100
などgetInt()
ブール値: true
またはfalse
getBoolean()
カラー: #rgb
、#argb
、#rrggbb
、#aarrggbb
の形式getInt()
浮動小数点数: 1.23
などgetFloat()
- 導入時の API レベル:
- API レベル 1
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# <meta-data\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cmeta-data android:name=\"string\"\n android:resource=\"resource specification\"\n android:value=\"string\" /\u003e\n ```\n\ncontained in:\n: [\u003cactivity\u003e](/guide/topics/manifest/activity-element)\n\n [\u003cactivity-alias\u003e](/guide/topics/manifest/activity-alias-element)\n\n [\u003capplication\u003e](/guide/topics/manifest/application-element)\n\n [\u003cprovider\u003e](/guide/topics/manifest/provider-element)\n\n [\u003creceiver\u003e](/guide/topics/manifest/receiver-element)\n\n [\u003cservice\u003e](/guide/topics/manifest/service-element)\n\ndescription:\n: A name-value pair for an item of additional, arbitrary data that can be\n supplied to the parent component. A component element can contain any\n number of `\u003cmeta-data\u003e` subelements. The values from all of\n them are collected in a single [Bundle](/reference/android/os/Bundle) object and made\n available to the component as the\n [PackageItemInfo.metaData](/reference/android/content/pm/PackageItemInfo#metaData) field.\n\n Specify ordinary values through the [value](/guide/topics/manifest/meta-data-element#val)\n attribute. To assign a resource ID as the value, use the\n [resource](/guide/topics/manifest/meta-data-element#rsrc) attribute instead. For example,\n the following code assigns whatever value is stored in the `@string/kangaroo`\n resource to the `zoo` name:\n\n\n ```xml\n \u003cmeta-data android:name=\"zoo\" android:value=\"@string/kangaroo\" /\u003e\n ```\n\n\n On the other hand, using the `resource` attribute assigns `zoo`\n the numeric ID of the resource, not the value stored in the resource:\n\n\n ```xml\n \u003cmeta-data android:name=\"zoo\" android:resource=\"@string/kangaroo\" /\u003e\n ```\n\n\n We highly recommend that you avoid supplying related data as\n multiple separate `\u003cmeta-data\u003e` entries. Instead, if you\n have complex data to associate with a component, store it as a resource and\n use the `resource` attribute to inform the component of its ID.\n\nattributes:\n:\n\n `android:name`\n : A unique name for the item. To keep the name unique, use a\n Java-style naming convention, such as\n \"`com.example.project.activity.fred`\".\n\n `android:resource`\n : A reference to a resource. The ID of the resource is the value assigned\n to the item. The ID is retrieved from the meta-data `Bundle` using the\n [Bundle.getInt()](/reference/android/os/BaseBundle#getInt(java.lang.String)) method.\n\n `android:value`\n : The value assigned to the item. The data types that can be assigned as values and the\n `Bundle` methods that components use to retrieve those values are listed in the following table:\n\n\n | Type | Bundle method |\n |---------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|\n | String: use double backslashes (`\\\\`) to escape characters, such as `\\\\n` for a new line and `\\\\uxxxxx` for a Unicode character | [getString()](/reference/android/os/BaseBundle#getString(java.lang.String)) |\n | Integer: for example, `100` | [getInt()](/reference/android/os/BaseBundle#getInt(java.lang.String)) |\n | Boolean: either `true` or `false` | [getBoolean()](/reference/android/os/BaseBundle#getBoolean(java.lang.String)) |\n | Color: in the form `#rgb`, `#argb`, `#rrggbb`, or `#aarrggbb` | [getInt()](/reference/android/os/BaseBundle#getInt(java.lang.String)) |\n | Float: for example, `1.23` | [getFloat()](/reference/android/os/Bundle#getFloat(java.lang.String)) |\n\n\nintroduced in:\n: API level 1"]]