android_manifest/meta_data.rs
1use super::resources::*;
2use serde::{Deserialize, Serialize};
3
4/// A name-value pair for an item of additional, arbitrary data that can be
5/// supplied to the parent component.
6///
7/// A component element can contain any number
8/// of `<meta-data>` subelements. The values from all of them are collected in a
9/// single [`Bundle`] object and made available to the component as the
10/// [`PackageItemInfo.metaData`] field.
11///
12/// Ordinary values are specified through the [`value`] attribute. However, to assign a
13/// resource ID as the value, use the [`resource`] attribute instead. For example, the
14/// following code assigns whatever value is stored in the @string/kangaroo resource to
15/// the `"zoo"` name:
16///
17/// ## XML Examples
18///
19/// ```xml
20/// <meta-data android:name="zoo" android:value="@string/kangaroo" />
21/// ```
22/// On the other hand, using the resource attribute would assign `"zoo"` the
23/// numeric ID of the resource, not the value stored in the resource:
24///
25/// ```xml
26/// <meta-data android:name="zoo" android:resource="@string/kangaroo" />
27/// ```
28///
29/// It is highly recommended that you avoid supplying related data as multiple
30/// separate `<meta-data>` entries. Instead, if you have complex data to
31/// associate with a component, store it as a `resource` and use the resource
32/// attribute to inform the component of its ID.
33///
34/// ## XML Syntax
35/// ```xml
36/// <meta-data android:name="string"
37/// android:resource="resource specification"
38/// android:value="string" />
39/// ```
40///
41/// ## Contained in
42/// * [`<activity>`]
43/// * [`<activity-alias>`]
44/// * [`<applocation>`]
45/// * [`<service>`]
46/// * [`<receiver>`]
47/// * [`<provider>`]
48///
49/// ## Introduced in
50/// API Level 1
51///
52/// [`Bundle`]: https://developer.android.com/reference/android/os/Bundle
53/// [`PackageItemInfo.metaData`]: https://developer.android.com/reference/android/content/pm/PackageItemInfo#metaData
54/// [`value`]: crate::MetaData#structfield.value
55/// [`resource`]: crate::MetaData#structfield.resource
56/// [`<activity>`]: crate::Activity
57/// [`<activity-alias>`]: crate::ActivityAlias
58/// [`<applocation>`]: crate::Application
59/// [`<service>`]: crate::Service
60/// [`<receiver>`]: crate::Receiver
61/// [`<provider>`]: crate::Provider
62#[derive(
63 Debug, Deserialize, Serialize, YaSerialize, YaDeserialize, PartialEq, Eq, Default, Clone,
64)]
65pub struct MetaData {
66 /// A unique name for the item. To ensure that the name is unique, use a Java-style
67 /// naming convention — for example, `"com.example.project.activity.fred"`.
68 #[yaserde(attribute, prefix = "android")]
69 pub name: Option<String>,
70 /// A reference to a resource. The ID of the resource is the value assigned to the
71 /// item. The ID can be retrieved from the meta-data Bundle by the
72 /// [`Bundle.getInt()`] method.
73 ///
74 /// [`Bundle.getInt()`]: https://developer.android.com/reference/android/os/BaseBundle#getInt(java.lang.String)
75 #[yaserde(attribute, prefix = "android")]
76 pub resource: Option<AnyResource>,
77 /// The value assigned to the item. The data types that can be assigned as values and
78 /// the Bundle methods that components use to retrieve those values are listed in the
79 /// following table: https://developer.android.com/guide/topics/manifest/meta-data-element#val
80 #[yaserde(attribute, prefix = "android")]
81 pub value: Option<String>,
82}