The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | page.title=<receiver> |
| 2 | @jd:body |
| 3 | |
| 4 | <dl class="xml"> |
| 5 | <dt>syntax:</dt> |
| 6 | <dd><pre class="stx"><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>" > |
| 13 | . . . |
| 14 | </receiver></pre></dd> |
| 15 | |
| 16 | <dt>contained in:</dt> |
| 17 | <dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code></dd> |
| 18 | |
| 19 | <dt>can contain:</dt> |
Chris Tate | a919486 | 2009-04-02 15:01:22 -0700 | [diff] [blame^] | 20 | <dd><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | <br/><code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data></a></code></dd> |
| 22 | |
| 23 | <dt>description:</dt> |
| 24 | <dd>Declares a broadcast receiver (a {@link android.content.BroadcastReceiver} |
| 25 | subclass) as one of the application's components. Broadcast receivers enable |
| 26 | applications to receive intents that are broadcast by the system or by other |
| 27 | applications, even when other components of the application are not running. |
| 28 | |
| 29 | <p> |
| 30 | There are two ways to make a broadcast receiver known to the system: One is |
| 31 | declare it in the manifest file with this element. The other is to create |
| 32 | the receiver dynamically in code and register it with the <code>{@link |
| 33 | android.content.Context#registerReceiver Context.registerReceiver()}</code> |
| 34 | method. See the {@link android.content.BroadcastReceiver} class description |
| 35 | for 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 — |
| 42 | "{@code true}" if it can be, and "{@code false}" if not. The default value |
| 43 | is "{@code true}". |
| 44 | |
| 45 | <p> |
| 46 | The <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></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 |
| 48 | application components, including broadcast receivers. The |
| 49 | <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> and |
Chris Tate | a919486 | 2009-04-02 15:01:22 -0700 | [diff] [blame^] | 50 | {@code <receiver>} elements must both set {@code android:enabled} equal to |
| 51 | "{@code true}" for the broadcast receiver to be enabled. If either is "{@code false}", |
| 52 | the receiver is disabled and cannot be instantiated. |
| 53 | </p> |
| 54 | |
| 55 | <p> |
| 56 | The default value depends on whether the broadcast receiver contains intent filters. |
| 57 | If any intent filters are specified, the default value is "{@code true}". If no |
| 58 | filters are specified, the default value is "{@code false}". |
| 59 | </dd> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | |
| 61 | <dt><a name="exported"></a>{@code android:exported}</dt> |
| 62 | <dd>Whether or not the broadcast receiver can receive messages from sources |
| 63 | outside its application — "{@code true}" if it can, and "{@code false}" |
| 64 | if not. If "{@code false}", the only messages the broadcast receiver can |
| 65 | receive are those sent by components of the same application or applications |
| 66 | with the same user ID. |
| 67 | |
| 68 | <p> |
| 69 | The default value depends on whether the broadcast receiver contains intent filters. |
| 70 | The absence of any filters means that it can be invoked only by Intent objects that |
| 71 | specify its exact class name. This implies that the receiver is intended only for |
| 72 | application-internal use (since others would not normally know the class name). |
| 73 | So in this case, the default value is "{@code false}". |
| 74 | On the other hand, the presence of at least one filter implies that the broadcast |
| 75 | receiver is intended to receive intents broadcast by the system or other applications, |
| 76 | so the default value is "{@code true}". |
| 77 | </p> |
| 78 | |
| 79 | <p> |
| 80 | This attribute is not the only way to limit a broadcast receiver's external exposure. |
| 81 | You 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 |
| 87 | as a reference to a drawable resource containing the image definition. |
| 88 | If it is not set, the icon specified for the application as a whole is used |
| 89 | instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> |
| 90 | element's <code><a href="{@docRoot}guide/topics/manifest/application-element.html#icon">icon</a></code> attribute). |
| 91 | |
| 92 | <p> |
| 93 | The broadcast receiver's icon — whether set here or by the |
| 94 | <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> element — is also the |
| 95 | default icon for all the receiver's intent filters (see the |
| 96 | <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></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 |
| 102 | set, the label set for the application as a whole is |
| 103 | used instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> element's |
| 104 | <code><a href="{@docRoot}guide/topics/manifest/application-element.html#label">label</a></code> attribute). |
| 105 | |
| 106 | <p> |
| 107 | The broadcast receiver's label — whether set here or by the |
| 108 | <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> element — is also the |
| 109 | default label for all the receiver's intent filters (see the |
| 110 | <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></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> |
| 115 | The label should be set as a reference to a string resource, so that |
| 116 | it can be localized like other strings in the user interface. |
| 117 | However, as a convenience while you're developing the application, |
| 118 | it 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 |
| 124 | class name (such as, "{@code com.example.project.ReportReceiver}"). However, |
| 125 | as a shorthand, if the first character of the name is a period (for example, |
Chris Tate | a919486 | 2009-04-02 15:01:22 -0700 | [diff] [blame^] | 126 | "{@code .ReportReceiver}"), it is appended to the package name specified in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | the <code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> element. |
| 128 | |
Chris Tate | a919486 | 2009-04-02 15:01:22 -0700 | [diff] [blame^] | 129 | <p>The {@link android.content.BroadcastReceiver} subclass can be a static inner |
| 130 | class, although it cannot be an ordinary (non-static) inner class. |
| 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | <p> |
| 133 | There 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 |
| 138 | message to the broadcast receiver. |
| 139 | If this attribute is not set, the permission set by the |
| 140 | <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> element's |
| 141 | <code><a href="{@docRoot}guide/topics/manifest/application-element.html#prmsn">permission</a></code> attribute applies |
| 142 | to the broadcast receiver. If neither attribute is set, the receiver |
| 143 | is not protected by a permission. |
| 144 | |
| 145 | <p> |
| 146 | For more information on permissions, see the |
| 147 | <a href="{@docRoot}guide/topics/manifest/manifest-intro.html#sectperm">Permissions</a> |
| 148 | section 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. |
| 154 | Normally, all components of an application run in the default process created |
| 155 | for the application. It has the same name as the application package. The |
| 156 | <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> element's |
| 157 | <code><a href="{@docRoot}guide/topics/manifest/application-element.html#proc">process</a></code> attribute can set a different |
| 158 | default for all components. But each component can override the default |
| 159 | with its own {@code process} attribute, allowing you to spread your |
| 160 | application across multiple processes. |
| 161 | |
| 162 | <p> |
| 163 | If the name assigned to this attribute begins with a colon (':'), a new |
| 164 | process, private to the application, is created when it's needed and |
| 165 | the broadcast receiver runs in that process. |
| 166 | If the process name begins with a lowercase character, the receiver will run |
| 167 | in a global process of that name, provided that it has permission to do so. |
| 168 | This allows components in different applications to share a process, reducing |
| 169 | resource usage. |
| 170 | </p></dd> |
| 171 | </dl></dd> |
| 172 | |
| 173 | </dl> |