blob: 777d016b5da8d923e9fb2fae8205d29461c6dfb7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001page.title=<receiver>
2@jd:body
3
4<dl class="xml">
5<dt>syntax:</dt>
6<dd><pre class="stx">&lt;receiver android:<a href="#enabled">enabled</a>=["true" | "false"]
7 android:<a href="#exported">exported</a>=["true" | "false"]
8 android:<a href="#icon">icon</a>="<i>drawable resource</i>"
9 android:<a href="#label">label</a>="<i>string resource</i>"
10 android:<a href="#nm">name</a>="<i>string</i>"
11 android:<a href="#prmsn">permission</a>="<i>string</i>"
12 android:<a href="#proc">process</a>="<i>string</i>" &gt;
13 . . .
14&lt;/receiver&gt;</pre></dd>
15
16<dt>contained in:</dt>
17<dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code></dd>
18
19<dt>can contain:</dt>
20<dd><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filer&gt;</a></code>
21<br/><code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html">&lt;meta-data&gt;</a></code></dd>
22
23<dt>description:</dt>
24<dd>Declares a broadcast receiver (a {@link android.content.BroadcastReceiver}
25subclass) as one of the application's components. Broadcast receivers enable
26applications to receive intents that are broadcast by the system or by other
27applications, even when other components of the application are not running.
28
29<p>
30There are two ways to make a broadcast receiver known to the system: One is
31declare it in the manifest file with this element. The other is to create
32the receiver dynamically in code and register it with the <code>{@link
33android.content.Context#registerReceiver Context.registerReceiver()}</code>
34method. See the {@link android.content.BroadcastReceiver} class description
35for more on dynamically created receivers.
36</p></dd>
37
38<dt>attributes:</dt>
39<dd><dl class="attr">
40<dt><a name="enabled"></a>{@code android:enabled}</dt>
41<dd>Whether or not the broadcast receiver can be instantiated by the system &mdash;
42"{@code true}" if it can be, and "{@code false}" if not. The default value
43is "{@code true}".
44
45<p>
46The <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element has its own
47<code><a href="{@docRoot}guide/topics/manifest/application-element.html#enabled">enabled</a></code> attribute that applies to all
48application components, including broadcast receivers. The
49<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> and
50{@code &lt;receiver&gt;} attributes must both be "{@code true}" for
51the broadcast receiver to be enabled. If either is "{@code false}", it is
52disabled; it cannot be instantiated.
53</p></dd>
54
55<dt><a name="exported"></a>{@code android:exported}</dt>
56<dd>Whether or not the broadcast receiver can receive messages from sources
57outside its application &mdash; "{@code true}" if it can, and "{@code false}"
58if not. If "{@code false}", the only messages the broadcast receiver can
59receive are those sent by components of the same application or applications
60with the same user ID.
61
62<p>
63The default value depends on whether the broadcast receiver contains intent filters.
64The absence of any filters means that it can be invoked only by Intent objects that
65specify its exact class name. This implies that the receiver is intended only for
66application-internal use (since others would not normally know the class name).
67So in this case, the default value is "{@code false}".
68On the other hand, the presence of at least one filter implies that the broadcast
69receiver is intended to receive intents broadcast by the system or other applications,
70so the default value is "{@code true}".
71</p>
72
73<p>
74This attribute is not the only way to limit a broadcast receiver's external exposure.
75You can also use a permission to limit the external entities that can send it messages
76(see the <code><a href="{@docRoot}guide/topics/manifest/receiver-element.html#prmsn">permission</a></code> attribute).
77</p></dd>
78
79<dt><a name="icon"></a>{@code android:icon}</dt>
80<dd>An icon representing the broadcast receiver. This attribute must be set
81as a reference to a drawable resource containing the image definition.
82If it is not set, the icon specified for the application as a whole is used
83instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code>
84element's <code><a href="{@docRoot}guide/topics/manifest/application-element.html#icon">icon</a></code> attribute).
85
86<p>
87The broadcast receiver's icon &mdash; whether set here or by the
88<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element &mdash; is also the
89default icon for all the receiver's intent filters (see the
90<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element's
91<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#icon">icon</a></code> attribute).
92</p></dd>
93
94<dt><a name="label"></a>{@code android:label}</dt>
95<dd>A user-readable label for the broadcast receiver. If this attribute is not
96set, the label set for the application as a whole is
97used instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's
98<code><a href="{@docRoot}guide/topics/manifest/application-element.html#label">label</a></code> attribute).
99
100<p>
101The broadcast receiver's label &mdash; whether set here or by the
102<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element &mdash; is also the
103default label for all the receiver's intent filters (see the
104<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element's
105<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#label">label</a></code> attribute).
106</p>
107
108<p>
109The label should be set as a reference to a string resource, so that
110it can be localized like other strings in the user interface.
111However, as a convenience while you're developing the application,
112it can also be set as a raw string.
113</p></dd>
114
115<dt><a name="nm"></a>{@code android:name}</dt>
116<dd>The name of the class that implements the broadcast receiver, a subclass of
117{@link android.content.BroadcastReceiver}. This should be a fully qualified
118class name (such as, "{@code com.example.project.ReportReceiver}"). However,
119as a shorthand, if the first character of the name is a period (for example,
120"{@code . ReportReceiver}"), it is appended to the package name specified in
121the <code><a href="{@docRoot}guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></code> element.
122
123<p>
124There is no default. The name must be specified.
125</p></dd>
126
127<dt><a name="prmsn"></a>{@code android:permission}</dt>
128<dd>The name of a permission that broadcasters must have to send a
129message to the broadcast receiver.
130If this attribute is not set, the permission set by the
131<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's
132<code><a href="{@docRoot}guide/topics/manifest/application-element.html#prmsn">permission</a></code> attribute applies
133to the broadcast receiver. If neither attribute is set, the receiver
134is not protected by a permission.
135
136<p>
137For more information on permissions, see the
138<a href="{@docRoot}guide/topics/manifest/manifest-intro.html#sectperm">Permissions</a>
139section in the introduction and a separate document,
140<a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a>.
141</p></dd>
142
143<dt><a name="proc"></a>{@code android:process}</dt>
144<dd>The name of the process in which the broadcast receiver should run.
145Normally, all components of an application run in the default process created
146for the application. It has the same name as the application package. The
147<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's
148<code><a href="{@docRoot}guide/topics/manifest/application-element.html#proc">process</a></code> attribute can set a different
149default for all components. But each component can override the default
150with its own {@code process} attribute, allowing you to spread your
151application across multiple processes.
152
153<p>
154If the name assigned to this attribute begins with a colon (':'), a new
155process, private to the application, is created when it's needed and
156the broadcast receiver runs in that process.
157If the process name begins with a lowercase character, the receiver will run
158in a global process of that name, provided that it has permission to do so.
159This allows components in different applications to share a process, reducing
160resource usage.
161</p></dd>
162</dl></dd>
163
164</dl>