blob: 8df6273bbf99009fc62901d82e7b7a5c81d888df [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>
Chris Tatea9194862009-04-02 15:01:22 -070020<dd><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021<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
Chris Tatea9194862009-04-02 15:01:22 -070050{@code &lt;receiver&gt;} elements must both set {@code android:enabled} equal to
51"{@code true}" for the broadcast receiver to be enabled. If either is "{@code false}",
52the receiver is disabled and cannot be instantiated.
53</p>
54
55<p>
56The default value depends on whether the broadcast receiver contains intent filters.
57If any intent filters are specified, the default value is "{@code true}". If no
58filters are specified, the default value is "{@code false}".
59</dd>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060
61<dt><a name="exported"></a>{@code android:exported}</dt>
62<dd>Whether or not the broadcast receiver can receive messages from sources
63outside its application &mdash; "{@code true}" if it can, and "{@code false}"
64if not. If "{@code false}", the only messages the broadcast receiver can
65receive are those sent by components of the same application or applications
66with the same user ID.
67
68<p>
69The default value depends on whether the broadcast receiver contains intent filters.
70The absence of any filters means that it can be invoked only by Intent objects that
71specify its exact class name. This implies that the receiver is intended only for
72application-internal use (since others would not normally know the class name).
73So in this case, the default value is "{@code false}".
74On the other hand, the presence of at least one filter implies that the broadcast
75receiver is intended to receive intents broadcast by the system or other applications,
76so the default value is "{@code true}".
77</p>
78
79<p>
80This attribute is not the only way to limit a broadcast receiver's external exposure.
81You can also use a permission to limit the external entities that can send it messages
82(see the <code><a href="{@docRoot}guide/topics/manifest/receiver-element.html#prmsn">permission</a></code> attribute).
83</p></dd>
84
85<dt><a name="icon"></a>{@code android:icon}</dt>
86<dd>An icon representing the broadcast receiver. This attribute must be set
87as a reference to a drawable resource containing the image definition.
88If it is not set, the icon specified for the application as a whole is used
89instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code>
90element's <code><a href="{@docRoot}guide/topics/manifest/application-element.html#icon">icon</a></code> attribute).
91
92<p>
93The broadcast receiver's icon &mdash; whether set here or by the
94<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element &mdash; is also the
95default icon for all the receiver's intent filters (see the
96<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element's
97<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#icon">icon</a></code> attribute).
98</p></dd>
99
100<dt><a name="label"></a>{@code android:label}</dt>
101<dd>A user-readable label for the broadcast receiver. If this attribute is not
102set, the label set for the application as a whole is
103used instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's
104<code><a href="{@docRoot}guide/topics/manifest/application-element.html#label">label</a></code> attribute).
105
106<p>
107The broadcast receiver's label &mdash; whether set here or by the
108<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element &mdash; is also the
109default label for all the receiver's intent filters (see the
110<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element's
111<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#label">label</a></code> attribute).
112</p>
113
114<p>
115The label should be set as a reference to a string resource, so that
116it can be localized like other strings in the user interface.
117However, as a convenience while you're developing the application,
118it can also be set as a raw string.
119</p></dd>
120
121<dt><a name="nm"></a>{@code android:name}</dt>
122<dd>The name of the class that implements the broadcast receiver, a subclass of
123{@link android.content.BroadcastReceiver}. This should be a fully qualified
124class name (such as, "{@code com.example.project.ReportReceiver}"). However,
125as a shorthand, if the first character of the name is a period (for example,
Chris Tatea9194862009-04-02 15:01:22 -0700126"{@code .ReportReceiver}"), it is appended to the package name specified in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127the <code><a href="{@docRoot}guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></code> element.
128
Chris Tatea9194862009-04-02 15:01:22 -0700129<p>The {@link android.content.BroadcastReceiver} subclass can be a static inner
130class, although it cannot be an ordinary (non-static) inner class.
131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132<p>
133There is no default. The name must be specified.
134</p></dd>
135
136<dt><a name="prmsn"></a>{@code android:permission}</dt>
137<dd>The name of a permission that broadcasters must have to send a
138message to the broadcast receiver.
139If this attribute is not set, the permission set by the
140<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's
141<code><a href="{@docRoot}guide/topics/manifest/application-element.html#prmsn">permission</a></code> attribute applies
142to the broadcast receiver. If neither attribute is set, the receiver
143is not protected by a permission.
144
145<p>
146For more information on permissions, see the
147<a href="{@docRoot}guide/topics/manifest/manifest-intro.html#sectperm">Permissions</a>
148section in the introduction and a separate document,
149<a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a>.
150</p></dd>
151
152<dt><a name="proc"></a>{@code android:process}</dt>
153<dd>The name of the process in which the broadcast receiver should run.
154Normally, all components of an application run in the default process created
155for the application. It has the same name as the application package. The
156<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's
157<code><a href="{@docRoot}guide/topics/manifest/application-element.html#proc">process</a></code> attribute can set a different
158default for all components. But each component can override the default
159with its own {@code process} attribute, allowing you to spread your
160application across multiple processes.
161
162<p>
163If the name assigned to this attribute begins with a colon (':'), a new
164process, private to the application, is created when it's needed and
165the broadcast receiver runs in that process.
166If the process name begins with a lowercase character, the receiver will run
167in a global process of that name, provided that it has permission to do so.
168This allows components in different applications to share a process, reducing
169resource usage.
170</p></dd>
171</dl></dd>
172
173</dl>