blob: b3e81d7e1f0a2d91293a037784800a404a1310a5 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
19import org.xmlpull.v1.XmlPullParser;
20import org.xmlpull.v1.XmlPullParserException;
21
22import android.annotation.SdkConstant;
23import android.annotation.SdkConstant.SdkConstantType;
24import android.content.pm.ActivityInfo;
25import android.content.pm.PackageManager;
26import android.content.pm.ResolveInfo;
27import android.content.res.Resources;
28import android.content.res.TypedArray;
29import android.net.Uri;
30import android.os.Bundle;
31import android.os.IBinder;
32import android.os.Parcel;
33import android.os.Parcelable;
34import android.util.AttributeSet;
35import android.util.Log;
36import com.android.internal.util.XmlUtils;
37
38import java.io.IOException;
39import java.io.Serializable;
40import java.net.URISyntaxException;
41import java.util.ArrayList;
42import java.util.HashSet;
43import java.util.Iterator;
44import java.util.Set;
45
46/**
47 * An intent is an abstract description of an operation to be performed. It
48 * can be used with {@link Context#startActivity(Intent) startActivity} to
49 * launch an {@link android.app.Activity},
50 * {@link android.content.Context#sendBroadcast(Intent) broadcastIntent} to
51 * send it to any interested {@link BroadcastReceiver BroadcastReceiver} components,
52 * and {@link android.content.Context#startService} or
53 * {@link android.content.Context#bindService} to communicate with a
54 * background {@link android.app.Service}.
55 *
56 * <p>An Intent provides a facility for performing late runtime binding between
57 * the code in different applications. Its most significant use is in the
58 * launching of activities, where it can be thought of as the glue between
59 * activities. It is
60 * basically a passive data structure holding an abstract description of an
61 * action to be performed. The primary pieces of information in an intent
62 * are:</p>
63 *
64 * <ul>
65 * <li> <p><b>action</b> -- The general action to be performed, such as
66 * {@link #ACTION_VIEW}, {@link #ACTION_EDIT}, {@link #ACTION_MAIN},
67 * etc.</p>
68 * </li>
69 * <li> <p><b>data</b> -- The data to operate on, such as a person record
70 * in the contacts database, expressed as a {@link android.net.Uri}.</p>
71 * </li>
72 * </ul>
73 *
74 *
75 * <p>Some examples of action/data pairs are:</p>
76 *
77 * <ul>
78 * <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/1</i></b> -- Display
79 * information about the person whose identifier is "1".</p>
80 * </li>
81 * <li> <p><b>{@link #ACTION_DIAL} <i>content://contacts/1</i></b> -- Display
82 * the phone dialer with the person filled in.</p>
83 * </li>
84 * <li> <p><b>{@link #ACTION_VIEW} <i>tel:123</i></b> -- Display
85 * the phone dialer with the given number filled in. Note how the
86 * VIEW action does what what is considered the most reasonable thing for
87 * a particular URI.</p>
88 * </li>
89 * <li> <p><b>{@link #ACTION_DIAL} <i>tel:123</i></b> -- Display
90 * the phone dialer with the given number filled in.</p>
91 * </li>
92 * <li> <p><b>{@link #ACTION_EDIT} <i>content://contacts/1</i></b> -- Edit
93 * information about the person whose identifier is "1".</p>
94 * </li>
95 * <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/</i></b> -- Display
96 * a list of people, which the user can browse through. This example is a
97 * typical top-level entry into the Contacts application, showing you the
98 * list of people. Selecting a particular person to view would result in a
99 * new intent { <b>{@link #ACTION_VIEW} <i>content://contacts/N</i></b> }
100 * being used to start an activity to display that person.</p>
101 * </li>
102 * </ul>
103 *
104 * <p>In addition to these primary attributes, there are a number of secondary
105 * attributes that you can also include with an intent:</p>
106 *
107 * <ul>
108 * <li> <p><b>category</b> -- Gives additional information about the action
109 * to execute. For example, {@link #CATEGORY_LAUNCHER} means it should
110 * appear in the Launcher as a top-level application, while
111 * {@link #CATEGORY_ALTERNATIVE} means it should be included in a list
112 * of alternative actions the user can perform on a piece of data.</p>
113 * <li> <p><b>type</b> -- Specifies an explicit type (a MIME type) of the
114 * intent data. Normally the type is inferred from the data itself.
115 * By setting this attribute, you disable that evaluation and force
116 * an explicit type.</p>
117 * <li> <p><b>component</b> -- Specifies an explicit name of a component
118 * class to use for the intent. Normally this is determined by looking
119 * at the other information in the intent (the action, data/type, and
120 * categories) and matching that with a component that can handle it.
121 * If this attribute is set then none of the evaluation is performed,
122 * and this component is used exactly as is. By specifying this attribute,
123 * all of the other Intent attributes become optional.</p>
124 * <li> <p><b>extras</b> -- This is a {@link Bundle} of any additional information.
125 * This can be used to provide extended information to the component.
126 * For example, if we have a action to send an e-mail message, we could
127 * also include extra pieces of data here to supply a subject, body,
128 * etc.</p>
129 * </ul>
130 *
131 * <p>Here are some examples of other operations you can specify as intents
132 * using these additional parameters:</p>
133 *
134 * <ul>
135 * <li> <p><b>{@link #ACTION_MAIN} with category {@link #CATEGORY_HOME}</b> --
136 * Launch the home screen.</p>
137 * </li>
138 * <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
139 * <i>{@link android.provider.Contacts.Phones#CONTENT_URI
140 * vnd.android.cursor.item/phone}</i></b>
141 * -- Display the list of people's phone numbers, allowing the user to
142 * browse through them and pick one and return it to the parent activity.</p>
143 * </li>
144 * <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
145 * <i>*{@literal /}*</i> and category {@link #CATEGORY_OPENABLE}</b>
146 * -- Display all pickers for data that can be opened with
147 * {@link ContentResolver#openInputStream(Uri) ContentResolver.openInputStream()},
148 * allowing the user to pick one of them and then some data inside of it
149 * and returning the resulting URI to the caller. This can be used,
150 * for example, in an e-mail application to allow the user to pick some
151 * data to include as an attachment.</p>
152 * </li>
153 * </ul>
154 *
155 * <p>There are a variety of standard Intent action and category constants
156 * defined in the Intent class, but applications can also define their own.
157 * These strings use java style scoping, to ensure they are unique -- for
158 * example, the standard {@link #ACTION_VIEW} is called
159 * "android.app.action.VIEW".</p>
160 *
161 * <p>Put together, the set of actions, data types, categories, and extra data
162 * defines a language for the system allowing for the expression of phrases
163 * such as "call john smith's cell". As applications are added to the system,
164 * they can extend this language by adding new actions, types, and categories, or
165 * they can modify the behavior of existing phrases by supplying their own
166 * activities that handle them.</p>
167 *
168 * <a name="IntentResolution"></a>
169 * <h3>Intent Resolution</h3>
170 *
171 * <p>There are two primary forms of intents you will use.
172 *
173 * <ul>
174 * <li> <p><b>Explicit Intents</b> have specified a component (via
175 * {@link #setComponent} or {@link #setClass}), which provides the exact
176 * class to be run. Often these will not include any other information,
177 * simply being a way for an application to launch various internal
178 * activities it has as the user interacts with the application.
179 *
180 * <li> <p><b>Implicit Intents</b> have not specified a component;
181 * instead, they must include enough information for the system to
182 * determine which of the available components is best to run for that
183 * intent.
184 * </ul>
185 *
186 * <p>When using implicit intents, given such an arbitrary intent we need to
187 * know what to do with it. This is handled by the process of <em>Intent
188 * resolution</em>, which maps an Intent to an {@link android.app.Activity},
189 * {@link BroadcastReceiver}, or {@link android.app.Service} (or sometimes two or
190 * more activities/receivers) that can handle it.</p>
191 *
192 * <p>The intent resolution mechanism basically revolves around matching an
193 * Intent against all of the &lt;intent-filter&gt; descriptions in the
194 * installed application packages. (Plus, in the case of broadcasts, any {@link BroadcastReceiver}
195 * objects explicitly registered with {@link Context#registerReceiver}.) More
196 * details on this can be found in the documentation on the {@link
197 * IntentFilter} class.</p>
198 *
199 * <p>There are three pieces of information in the Intent that are used for
200 * resolution: the action, type, and category. Using this information, a query
201 * is done on the {@link PackageManager} for a component that can handle the
202 * intent. The appropriate component is determined based on the intent
203 * information supplied in the <code>AndroidManifest.xml</code> file as
204 * follows:</p>
205 *
206 * <ul>
207 * <li> <p>The <b>action</b>, if given, must be listed by the component as
208 * one it handles.</p>
209 * <li> <p>The <b>type</b> is retrieved from the Intent's data, if not
210 * already supplied in the Intent. Like the action, if a type is
211 * included in the intent (either explicitly or implicitly in its
212 * data), then this must be listed by the component as one it handles.</p>
213 * <li> For data that is not a <code>content:</code> URI and where no explicit
214 * type is included in the Intent, instead the <b>scheme</b> of the
215 * intent data (such as <code>http:</code> or <code>mailto:</code>) is
216 * considered. Again like the action, if we are matching a scheme it
217 * must be listed by the component as one it can handle.
218 * <li> <p>The <b>categories</b>, if supplied, must <em>all</em> be listed
219 * by the activity as categories it handles. That is, if you include
220 * the categories {@link #CATEGORY_LAUNCHER} and
221 * {@link #CATEGORY_ALTERNATIVE}, then you will only resolve to components
222 * with an intent that lists <em>both</em> of those categories.
223 * Activities will very often need to support the
224 * {@link #CATEGORY_DEFAULT} so that they can be found by
225 * {@link Context#startActivity Context.startActivity()}.</p>
226 * </ul>
227 *
228 * <p>For example, consider the Note Pad sample application that
229 * allows user to browse through a list of notes data and view details about
230 * individual items. Text in italics indicate places were you would replace a
231 * name with one specific to your own package.</p>
232 *
233 * <pre> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
234 * package="<i>com.android.notepad</i>"&gt;
235 * &lt;application android:icon="@drawable/app_notes"
236 * android:label="@string/app_name"&gt;
237 *
238 * &lt;provider class=".NotePadProvider"
239 * android:authorities="<i>com.google.provider.NotePad</i>" /&gt;
240 *
241 * &lt;activity class=".NotesList" android:label="@string/title_notes_list"&gt;
242 * &lt;intent-filter&gt;
243 * &lt;action android:value="android.intent.action.MAIN" /&gt;
244 * &lt;category android:value="android.intent.category.LAUNCHER" /&gt;
245 * &lt;/intent-filter&gt;
246 * &lt;intent-filter&gt;
247 * &lt;action android:value="android.intent.action.VIEW" /&gt;
248 * &lt;action android:value="android.intent.action.EDIT" /&gt;
249 * &lt;action android:value="android.intent.action.PICK" /&gt;
250 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
251 * &lt;type android:value="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
252 * &lt;/intent-filter&gt;
253 * &lt;intent-filter&gt;
254 * &lt;action android:value="android.intent.action.GET_CONTENT" /&gt;
255 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
256 * &lt;type android:value="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
257 * &lt;/intent-filter&gt;
258 * &lt;/activity&gt;
259 *
260 * &lt;activity class=".NoteEditor" android:label="@string/title_note"&gt;
261 * &lt;intent-filter android:label="@string/resolve_edit"&gt;
262 * &lt;action android:value="android.intent.action.VIEW" /&gt;
263 * &lt;action android:value="android.intent.action.EDIT" /&gt;
264 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
265 * &lt;type android:value="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
266 * &lt;/intent-filter&gt;
267 *
268 * &lt;intent-filter&gt;
269 * &lt;action android:value="android.intent.action.INSERT" /&gt;
270 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
271 * &lt;type android:value="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
272 * &lt;/intent-filter&gt;
273 *
274 * &lt;/activity&gt;
275 *
276 * &lt;activity class=".TitleEditor" android:label="@string/title_edit_title"
277 * android:theme="@android:style/Theme.Dialog"&gt;
278 * &lt;intent-filter android:label="@string/resolve_title"&gt;
279 * &lt;action android:value="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
280 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
281 * &lt;category android:value="android.intent.category.ALTERNATIVE" /&gt;
282 * &lt;category android:value="android.intent.category.SELECTED_ALTERNATIVE" /&gt;
283 * &lt;type android:value="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
284 * &lt;/intent-filter&gt;
285 * &lt;/activity&gt;
286 *
287 * &lt;/application&gt;
288 * &lt;/manifest&gt;</pre>
289 *
290 * <p>The first activity,
291 * <code>com.android.notepad.NotesList</code>, serves as our main
292 * entry into the app. It can do three things as described by its three intent
293 * templates:
294 * <ol>
295 * <li><pre>
296 * &lt;intent-filter&gt;
297 * &lt;action android:value="{@link #ACTION_MAIN android.intent.action.MAIN}" /&gt;
298 * &lt;category android:value="{@link #CATEGORY_LAUNCHER android.intent.category.LAUNCHER}" /&gt;
299 * &lt;/intent-filter&gt;</pre>
300 * <p>This provides a top-level entry into the NotePad application: the standard
301 * MAIN action is a main entry point (not requiring any other information in
302 * the Intent), and the LAUNCHER category says that this entry point should be
303 * listed in the application launcher.</p>
304 * <li><pre>
305 * &lt;intent-filter&gt;
306 * &lt;action android:value="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
307 * &lt;action android:value="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
308 * &lt;action android:value="{@link #ACTION_PICK android.intent.action.PICK}" /&gt;
309 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
310 * &lt;type android:value="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
311 * &lt;/intent-filter&gt;</pre>
312 * <p>This declares the things that the activity can do on a directory of
313 * notes. The type being supported is given with the &lt;type&gt; tag, where
314 * <code>vnd.android.cursor.dir/vnd.google.note</code> is a URI from which
315 * a Cursor of zero or more items (<code>vnd.android.cursor.dir</code>) can
316 * be retrieved which holds our note pad data (<code>vnd.google.note</code>).
317 * The activity allows the user to view or edit the directory of data (via
318 * the VIEW and EDIT actions), or to pick a particular note and return it
319 * to the caller (via the PICK action). Note also the DEFAULT category
320 * supplied here: this is <em>required</em> for the
321 * {@link Context#startActivity Context.startActivity} method to resolve your
322 * activity when its component name is not explicitly specified.</p>
323 * <li><pre>
324 * &lt;intent-filter&gt;
325 * &lt;action android:value="{@link #ACTION_GET_CONTENT android.intent.action.GET_CONTENT}" /&gt;
326 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
327 * &lt;type android:value="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
328 * &lt;/intent-filter&gt;</pre>
329 * <p>This filter describes the ability return to the caller a note selected by
330 * the user without needing to know where it came from. The data type
331 * <code>vnd.android.cursor.item/vnd.google.note</code> is a URI from which
332 * a Cursor of exactly one (<code>vnd.android.cursor.item</code>) item can
333 * be retrieved which contains our note pad data (<code>vnd.google.note</code>).
334 * The GET_CONTENT action is similar to the PICK action, where the activity
335 * will return to its caller a piece of data selected by the user. Here,
336 * however, the caller specifies the type of data they desire instead of
337 * the type of data the user will be picking from.</p>
338 * </ol>
339 *
340 * <p>Given these capabilities, the following intents will resolve to the
341 * NotesList activity:</p>
342 *
343 * <ul>
344 * <li> <p><b>{ action=android.app.action.MAIN }</b> matches all of the
345 * activities that can be used as top-level entry points into an
346 * application.</p>
347 * <li> <p><b>{ action=android.app.action.MAIN,
348 * category=android.app.category.LAUNCHER }</b> is the actual intent
349 * used by the Launcher to populate its top-level list.</p>
350 * <li> <p><b>{ action=android.app.action.VIEW
351 * data=content://com.google.provider.NotePad/notes }</b>
352 * displays a list of all the notes under
353 * "content://com.google.provider.NotePad/notes", which
354 * the user can browse through and see the details on.</p>
355 * <li> <p><b>{ action=android.app.action.PICK
356 * data=content://com.google.provider.NotePad/notes }</b>
357 * provides a list of the notes under
358 * "content://com.google.provider.NotePad/notes", from which
359 * the user can pick a note whose data URL is returned back to the caller.</p>
360 * <li> <p><b>{ action=android.app.action.GET_CONTENT
361 * type=vnd.android.cursor.item/vnd.google.note }</b>
362 * is similar to the pick action, but allows the caller to specify the
363 * kind of data they want back so that the system can find the appropriate
364 * activity to pick something of that data type.</p>
365 * </ul>
366 *
367 * <p>The second activity,
368 * <code>com.android.notepad.NoteEditor</code>, shows the user a single
369 * note entry and allows them to edit it. It can do two things as described
370 * by its two intent templates:
371 * <ol>
372 * <li><pre>
373 * &lt;intent-filter android:label="@string/resolve_edit"&gt;
374 * &lt;action android:value="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
375 * &lt;action android:value="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
376 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
377 * &lt;type android:value="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
378 * &lt;/intent-filter&gt;</pre>
379 * <p>The first, primary, purpose of this activity is to let the user interact
380 * with a single note, as decribed by the MIME type
381 * <code>vnd.android.cursor.item/vnd.google.note</code>. The activity can
382 * either VIEW a note or allow the user to EDIT it. Again we support the
383 * DEFAULT category to allow the activity to be launched without explicitly
384 * specifying its component.</p>
385 * <li><pre>
386 * &lt;intent-filter&gt;
387 * &lt;action android:value="{@link #ACTION_INSERT android.intent.action.INSERT}" /&gt;
388 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
389 * &lt;type android:value="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
390 * &lt;/intent-filter&gt;</pre>
391 * <p>The secondary use of this activity is to insert a new note entry into
392 * an existing directory of notes. This is used when the user creates a new
393 * note: the INSERT action is executed on the directory of notes, causing
394 * this activity to run and have the user create the new note data which
395 * it then adds to the content provider.</p>
396 * </ol>
397 *
398 * <p>Given these capabilities, the following intents will resolve to the
399 * NoteEditor activity:</p>
400 *
401 * <ul>
402 * <li> <p><b>{ action=android.app.action.VIEW
403 * data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
404 * shows the user the content of note <var>{ID}</var>.</p>
405 * <li> <p><b>{ action=android.app.action.EDIT
406 * data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
407 * allows the user to edit the content of note <var>{ID}</var>.</p>
408 * <li> <p><b>{ action=android.app.action.INSERT
409 * data=content://com.google.provider.NotePad/notes }</b>
410 * creates a new, empty note in the notes list at
411 * "content://com.google.provider.NotePad/notes"
412 * and allows the user to edit it. If they keep their changes, the URI
413 * of the newly created note is returned to the caller.</p>
414 * </ul>
415 *
416 * <p>The last activity,
417 * <code>com.android.notepad.TitleEditor</code>, allows the user to
418 * edit the title of a note. This could be implemented as a class that the
419 * application directly invokes (by explicitly setting its component in
420 * the Intent), but here we show a way you can publish alternative
421 * operations on existing data:</p>
422 *
423 * <pre>
424 * &lt;intent-filter android:label="@string/resolve_title"&gt;
425 * &lt;action android:value="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
426 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
427 * &lt;category android:value="{@link #CATEGORY_ALTERNATIVE android.intent.category.ALTERNATIVE}" /&gt;
428 * &lt;category android:value="{@link #CATEGORY_SELECTED_ALTERNATIVE android.intent.category.SELECTED_ALTERNATIVE}" /&gt;
429 * &lt;type android:value="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
430 * &lt;/intent-filter&gt;</pre>
431 *
432 * <p>In the single intent template here, we
433 * have created our own private action called
434 * <code>com.android.notepad.action.EDIT_TITLE</code> which means to
435 * edit the title of a note. It must be invoked on a specific note
436 * (data type <code>vnd.android.cursor.item/vnd.google.note</code>) like the previous
437 * view and edit actions, but here displays and edits the title contained
438 * in the note data.
439 *
440 * <p>In addition to supporting the default category as usual, our title editor
441 * also supports two other standard categories: ALTERNATIVE and
442 * SELECTED_ALTERNATIVE. Implementing
443 * these categories allows others to find the special action it provides
444 * without directly knowing about it, through the
445 * {@link android.content.pm.PackageManager#queryIntentActivityOptions} method, or
446 * more often to build dynamic menu items with
447 * {@link android.view.Menu#addIntentOptions}. Note that in the intent
448 * template here was also supply an explicit name for the template
449 * (via <code>android:label="@string/resolve_title"</code>) to better control
450 * what the user sees when presented with this activity as an alternative
451 * action to the data they are viewing.
452 *
453 * <p>Given these capabilities, the following intent will resolve to the
454 * TitleEditor activity:</p>
455 *
456 * <ul>
457 * <li> <p><b>{ action=com.android.notepad.action.EDIT_TITLE
458 * data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
459 * displays and allows the user to edit the title associated
460 * with note <var>{ID}</var>.</p>
461 * </ul>
462 *
463 * <h3>Standard Activity Actions</h3>
464 *
465 * <p>These are the current standard actions that Intent defines for launching
466 * activities (usually through {@link Context#startActivity}. The most
467 * important, and by far most frequently used, are {@link #ACTION_MAIN} and
468 * {@link #ACTION_EDIT}.
469 *
470 * <ul>
471 * <li> {@link #ACTION_MAIN}
472 * <li> {@link #ACTION_VIEW}
473 * <li> {@link #ACTION_ATTACH_DATA}
474 * <li> {@link #ACTION_EDIT}
475 * <li> {@link #ACTION_PICK}
476 * <li> {@link #ACTION_CHOOSER}
477 * <li> {@link #ACTION_GET_CONTENT}
478 * <li> {@link #ACTION_DIAL}
479 * <li> {@link #ACTION_CALL}
480 * <li> {@link #ACTION_SEND}
481 * <li> {@link #ACTION_SENDTO}
482 * <li> {@link #ACTION_ANSWER}
483 * <li> {@link #ACTION_INSERT}
484 * <li> {@link #ACTION_DELETE}
485 * <li> {@link #ACTION_RUN}
486 * <li> {@link #ACTION_SYNC}
487 * <li> {@link #ACTION_PICK_ACTIVITY}
488 * <li> {@link #ACTION_SEARCH}
489 * <li> {@link #ACTION_WEB_SEARCH}
490 * <li> {@link #ACTION_FACTORY_TEST}
491 * </ul>
492 *
493 * <h3>Standard Broadcast Actions</h3>
494 *
495 * <p>These are the current standard actions that Intent defines for receiving
496 * broadcasts (usually through {@link Context#registerReceiver} or a
497 * &lt;receiver&gt; tag in a manifest).
498 *
499 * <ul>
500 * <li> {@link #ACTION_TIME_TICK}
501 * <li> {@link #ACTION_TIME_CHANGED}
502 * <li> {@link #ACTION_TIMEZONE_CHANGED}
503 * <li> {@link #ACTION_BOOT_COMPLETED}
504 * <li> {@link #ACTION_PACKAGE_ADDED}
505 * <li> {@link #ACTION_PACKAGE_CHANGED}
506 * <li> {@link #ACTION_PACKAGE_REMOVED}
507 * <li> {@link #ACTION_PACKAGE_RESTARTED}
508 * <li> {@link #ACTION_PACKAGE_DATA_CLEARED}
509 * <li> {@link #ACTION_UID_REMOVED}
510 * <li> {@link #ACTION_BATTERY_CHANGED}
Christopher Tate06ba5542009-04-09 16:03:56 -0700511 * <li> {@link #ACTION_POWER_CONNECTED}
512 * <li> {@link #ACTION_POWER_DISCONNECTED}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 * </ul>
514 *
515 * <h3>Standard Categories</h3>
516 *
517 * <p>These are the current standard categories that can be used to further
518 * clarify an Intent via {@link #addCategory}.
519 *
520 * <ul>
521 * <li> {@link #CATEGORY_DEFAULT}
522 * <li> {@link #CATEGORY_BROWSABLE}
523 * <li> {@link #CATEGORY_TAB}
524 * <li> {@link #CATEGORY_ALTERNATIVE}
525 * <li> {@link #CATEGORY_SELECTED_ALTERNATIVE}
526 * <li> {@link #CATEGORY_LAUNCHER}
527 * <li> {@link #CATEGORY_INFO}
528 * <li> {@link #CATEGORY_HOME}
529 * <li> {@link #CATEGORY_PREFERENCE}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 * <li> {@link #CATEGORY_TEST}
531 * </ul>
532 *
533 * <h3>Standard Extra Data</h3>
534 *
535 * <p>These are the current standard fields that can be used as extra data via
536 * {@link #putExtra}.
537 *
538 * <ul>
539 * <li> {@link #EXTRA_TEMPLATE}
540 * <li> {@link #EXTRA_INTENT}
541 * <li> {@link #EXTRA_STREAM}
542 * <li> {@link #EXTRA_TEXT}
543 * </ul>
544 *
545 * <h3>Flags</h3>
546 *
547 * <p>These are the possible flags that can be used in the Intent via
548 * {@link #setFlags} and {@link #addFlags}. See {@link #setFlags} for a list
549 * of all possible flags.
550 */
551public class Intent implements Parcelable {
552 // ---------------------------------------------------------------------
553 // ---------------------------------------------------------------------
554 // Standard intent activity actions (see action variable).
555
556 /**
557 * Activity Action: Start as a main entry point, does not expect to
558 * receive data.
559 * <p>Input: nothing
560 * <p>Output: nothing
561 */
562 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
563 public static final String ACTION_MAIN = "android.intent.action.MAIN";
564
565 /**
566 * Activity Action: Display the data to the user. This is the most common
567 * action performed on data -- it is the generic action you can use on
568 * a piece of data to get the most reasonable thing to occur. For example,
569 * when used on a contacts entry it will view the entry; when used on a
570 * mailto: URI it will bring up a compose window filled with the information
571 * supplied by the URI; when used with a tel: URI it will invoke the
572 * dialer.
573 * <p>Input: {@link #getData} is URI from which to retrieve data.
574 * <p>Output: nothing.
575 */
576 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
577 public static final String ACTION_VIEW = "android.intent.action.VIEW";
578
579 /**
580 * A synonym for {@link #ACTION_VIEW}, the "standard" action that is
581 * performed on a piece of data.
582 */
583 public static final String ACTION_DEFAULT = ACTION_VIEW;
584
585 /**
586 * Used to indicate that some piece of data should be attached to some other
587 * place. For example, image data could be attached to a contact. It is up
588 * to the recipient to decide where the data should be attached; the intent
589 * does not specify the ultimate destination.
590 * <p>Input: {@link #getData} is URI of data to be attached.
591 * <p>Output: nothing.
592 */
593 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
594 public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
595
596 /**
597 * Activity Action: Provide explicit editable access to the given data.
598 * <p>Input: {@link #getData} is URI of data to be edited.
599 * <p>Output: nothing.
600 */
601 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
602 public static final String ACTION_EDIT = "android.intent.action.EDIT";
603
604 /**
605 * Activity Action: Pick an existing item, or insert a new item, and then edit it.
606 * <p>Input: {@link #getType} is the desired MIME type of the item to create or edit.
607 * The extras can contain type specific data to pass through to the editing/creating
608 * activity.
609 * <p>Output: The URI of the item that was picked. This must be a content:
610 * URI so that any receiver can access it.
611 */
612 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
613 public static final String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
614
615 /**
616 * Activity Action: Pick an item from the data, returning what was selected.
617 * <p>Input: {@link #getData} is URI containing a directory of data
618 * (vnd.android.cursor.dir/*) from which to pick an item.
619 * <p>Output: The URI of the item that was picked.
620 */
621 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
622 public static final String ACTION_PICK = "android.intent.action.PICK";
623
624 /**
625 * Activity Action: Creates a shortcut.
626 * <p>Input: Nothing.</p>
627 * <p>Output: An Intent representing the shortcut. The intent must contain three
628 * extras: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String),
629 * and SHORTCUT_ICON (value: Bitmap) or SHORTCUT_ICON_RESOURCE
630 * (value: ShortcutIconResource).</p>
631 *
632 * @see #EXTRA_SHORTCUT_INTENT
633 * @see #EXTRA_SHORTCUT_NAME
634 * @see #EXTRA_SHORTCUT_ICON
635 * @see #EXTRA_SHORTCUT_ICON_RESOURCE
636 * @see android.content.Intent.ShortcutIconResource
637 */
638 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
639 public static final String ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
640
641 /**
642 * The name of the extra used to define the Intent of a shortcut.
643 *
644 * @see #ACTION_CREATE_SHORTCUT
645 */
646 public static final String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
647 /**
648 * The name of the extra used to define the name of a shortcut.
649 *
650 * @see #ACTION_CREATE_SHORTCUT
651 */
652 public static final String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
653 /**
654 * The name of the extra used to define the icon, as a Bitmap, of a shortcut.
655 *
656 * @see #ACTION_CREATE_SHORTCUT
657 */
658 public static final String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
659 /**
660 * The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.
661 *
662 * @see #ACTION_CREATE_SHORTCUT
663 * @see android.content.Intent.ShortcutIconResource
664 */
665 public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
666 "android.intent.extra.shortcut.ICON_RESOURCE";
667
668 /**
669 * Represents a shortcut/live folder icon resource.
670 *
671 * @see Intent#ACTION_CREATE_SHORTCUT
672 * @see Intent#EXTRA_SHORTCUT_ICON_RESOURCE
673 * @see android.provider.LiveFolders#ACTION_CREATE_LIVE_FOLDER
674 * @see android.provider.LiveFolders#EXTRA_LIVE_FOLDER_ICON
675 */
676 public static class ShortcutIconResource implements Parcelable {
677 /**
678 * The package name of the application containing the icon.
679 */
680 public String packageName;
681
682 /**
683 * The resource name of the icon, including package, name and type.
684 */
685 public String resourceName;
686
687 /**
688 * Creates a new ShortcutIconResource for the specified context and resource
689 * identifier.
690 *
691 * @param context The context of the application.
692 * @param resourceId The resource idenfitier for the icon.
693 * @return A new ShortcutIconResource with the specified's context package name
694 * and icon resource idenfitier.
695 */
696 public static ShortcutIconResource fromContext(Context context, int resourceId) {
697 ShortcutIconResource icon = new ShortcutIconResource();
698 icon.packageName = context.getPackageName();
699 icon.resourceName = context.getResources().getResourceName(resourceId);
700 return icon;
701 }
702
703 /**
704 * Used to read a ShortcutIconResource from a Parcel.
705 */
706 public static final Parcelable.Creator<ShortcutIconResource> CREATOR =
707 new Parcelable.Creator<ShortcutIconResource>() {
708
709 public ShortcutIconResource createFromParcel(Parcel source) {
710 ShortcutIconResource icon = new ShortcutIconResource();
711 icon.packageName = source.readString();
712 icon.resourceName = source.readString();
713 return icon;
714 }
715
716 public ShortcutIconResource[] newArray(int size) {
717 return new ShortcutIconResource[size];
718 }
719 };
720
721 /**
722 * No special parcel contents.
723 */
724 public int describeContents() {
725 return 0;
726 }
727
728 public void writeToParcel(Parcel dest, int flags) {
729 dest.writeString(packageName);
730 dest.writeString(resourceName);
731 }
732
733 @Override
734 public String toString() {
735 return resourceName;
736 }
737 }
738
739 /**
740 * Activity Action: Display an activity chooser, allowing the user to pick
741 * what they want to before proceeding. This can be used as an alternative
742 * to the standard activity picker that is displayed by the system when
743 * you try to start an activity with multiple possible matches, with these
744 * differences in behavior:
745 * <ul>
746 * <li>You can specify the title that will appear in the activity chooser.
747 * <li>The user does not have the option to make one of the matching
748 * activities a preferred activity, and all possible activities will
749 * always be shown even if one of them is currently marked as the
750 * preferred activity.
751 * </ul>
752 * <p>
753 * This action should be used when the user will naturally expect to
754 * select an activity in order to proceed. An example if when not to use
755 * it is when the user clicks on a "mailto:" link. They would naturally
756 * expect to go directly to their mail app, so startActivity() should be
757 * called directly: it will
758 * either launch the current preferred app, or put up a dialog allowing the
759 * user to pick an app to use and optionally marking that as preferred.
760 * <p>
761 * In contrast, if the user is selecting a menu item to send a picture
762 * they are viewing to someone else, there are many different things they
763 * may want to do at this point: send it through e-mail, upload it to a
764 * web service, etc. In this case the CHOOSER action should be used, to
765 * always present to the user a list of the things they can do, with a
766 * nice title given by the caller such as "Send this photo with:".
767 * <p>
768 * As a convenience, an Intent of this form can be created with the
769 * {@link #createChooser} function.
770 * <p>Input: No data should be specified. get*Extra must have
771 * a {@link #EXTRA_INTENT} field containing the Intent being executed,
772 * and can optionally have a {@link #EXTRA_TITLE} field containing the
773 * title text to display in the chooser.
774 * <p>Output: Depends on the protocol of {@link #EXTRA_INTENT}.
775 */
776 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
777 public static final String ACTION_CHOOSER = "android.intent.action.CHOOSER";
778
779 /**
780 * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
781 *
782 * @param target The Intent that the user will be selecting an activity
783 * to perform.
784 * @param title Optional title that will be displayed in the chooser.
785 * @return Return a new Intent object that you can hand to
786 * {@link Context#startActivity(Intent) Context.startActivity()} and
787 * related methods.
788 */
789 public static Intent createChooser(Intent target, CharSequence title) {
790 Intent intent = new Intent(ACTION_CHOOSER);
791 intent.putExtra(EXTRA_INTENT, target);
792 if (title != null) {
793 intent.putExtra(EXTRA_TITLE, title);
794 }
795 return intent;
796 }
797 /**
798 * Activity Action: Allow the user to select a particular kind of data and
799 * return it. This is different than {@link #ACTION_PICK} in that here we
800 * just say what kind of data is desired, not a URI of existing data from
801 * which the user can pick. A ACTION_GET_CONTENT could allow the user to
802 * create the data as it runs (for example taking a picture or recording a
803 * sound), let them browser over the web and download the desired data,
804 * etc.
805 * <p>
806 * There are two main ways to use this action: if you want an specific kind
807 * of data, such as a person contact, you set the MIME type to the kind of
808 * data you want and launch it with {@link Context#startActivity(Intent)}.
809 * The system will then launch the best application to select that kind
810 * of data for you.
811 * <p>
812 * You may also be interested in any of a set of types of content the user
813 * can pick. For example, an e-mail application that wants to allow the
814 * user to add an attachment to an e-mail message can use this action to
815 * bring up a list of all of the types of content the user can attach.
816 * <p>
817 * In this case, you should wrap the GET_CONTENT intent with a chooser
818 * (through {@link #createChooser}), which will give the proper interface
819 * for the user to pick how to send your data and allow you to specify
820 * a prompt indicating what they are doing. You will usually specify a
821 * broad MIME type (such as image/* or {@literal *}/*), resulting in a
822 * broad range of content types the user can select from.
823 * <p>
824 * When using such a broad GET_CONTENT action, it is often desireable to
825 * only pick from data that can be represented as a stream. This is
826 * accomplished by requiring the {@link #CATEGORY_OPENABLE} in the Intent.
827 * <p>
828 * Input: {@link #getType} is the desired MIME type to retrieve. Note
829 * that no URI is supplied in the intent, as there are no constraints on
830 * where the returned data originally comes from. You may also include the
831 * {@link #CATEGORY_OPENABLE} if you can only accept data that can be
832 * opened as a stream.
833 * <p>
834 * Output: The URI of the item that was picked. This must be a content:
835 * URI so that any receiver can access it.
836 */
837 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
838 public static final String ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
839 /**
840 * Activity Action: Dial a number as specified by the data. This shows a
841 * UI with the number being dialed, allowing the user to explicitly
842 * initiate the call.
843 * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
844 * is URI of a phone number to be dialed or a tel: URI of an explicit phone
845 * number.
846 * <p>Output: nothing.
847 */
848 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
849 public static final String ACTION_DIAL = "android.intent.action.DIAL";
850 /**
851 * Activity Action: Perform a call to someone specified by the data.
852 * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
853 * is URI of a phone number to be dialed or a tel: URI of an explicit phone
854 * number.
855 * <p>Output: nothing.
856 *
857 * <p>Note: there will be restrictions on which applications can initiate a
858 * call; most applications should use the {@link #ACTION_DIAL}.
859 * <p>Note: this Intent <strong>cannot</strong> be used to call emergency
860 * numbers. Applications can <strong>dial</strong> emergency numbers using
861 * {@link #ACTION_DIAL}, however.
862 */
863 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
864 public static final String ACTION_CALL = "android.intent.action.CALL";
865 /**
866 * Activity Action: Perform a call to an emergency number specified by the
867 * data.
868 * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
869 * tel: URI of an explicit phone number.
870 * <p>Output: nothing.
871 * @hide
872 */
873 public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
874 /**
875 * Activity action: Perform a call to any number (emergency or not)
876 * specified by the data.
877 * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
878 * tel: URI of an explicit phone number.
879 * <p>Output: nothing.
880 * @hide
881 */
882 public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
883 /**
884 * Activity Action: Send a message to someone specified by the data.
885 * <p>Input: {@link #getData} is URI describing the target.
886 * <p>Output: nothing.
887 */
888 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
889 public static final String ACTION_SENDTO = "android.intent.action.SENDTO";
890 /**
891 * Activity Action: Deliver some data to someone else. Who the data is
892 * being delivered to is not specified; it is up to the receiver of this
893 * action to ask the user where the data should be sent.
894 * <p>
895 * When launching a SEND intent, you should usually wrap it in a chooser
896 * (through {@link #createChooser}), which will give the proper interface
897 * for the user to pick how to send your data and allow you to specify
898 * a prompt indicating what they are doing.
899 * <p>
900 * Input: {@link #getType} is the MIME type of the data being sent.
901 * get*Extra can have either a {@link #EXTRA_TEXT}
902 * or {@link #EXTRA_STREAM} field, containing the data to be sent. If
903 * using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it
904 * should be the MIME type of the data in EXTRA_STREAM. Use {@literal *}/*
905 * if the MIME type is unknown (this will only allow senders that can
906 * handle generic data streams).
907 * <p>
908 * Optional standard extras, which may be interpreted by some recipients as
909 * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
910 * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
911 * <p>
912 * Output: nothing.
913 */
914 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
915 public static final String ACTION_SEND = "android.intent.action.SEND";
916 /**
917 * Activity Action: Handle an incoming phone call.
918 * <p>Input: nothing.
919 * <p>Output: nothing.
920 */
921 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
922 public static final String ACTION_ANSWER = "android.intent.action.ANSWER";
923 /**
924 * Activity Action: Insert an empty item into the given container.
925 * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
926 * in which to place the data.
927 * <p>Output: URI of the new data that was created.
928 */
929 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
930 public static final String ACTION_INSERT = "android.intent.action.INSERT";
931 /**
932 * Activity Action: Delete the given data from its container.
933 * <p>Input: {@link #getData} is URI of data to be deleted.
934 * <p>Output: nothing.
935 */
936 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
937 public static final String ACTION_DELETE = "android.intent.action.DELETE";
938 /**
939 * Activity Action: Run the data, whatever that means.
940 * <p>Input: ? (Note: this is currently specific to the test harness.)
941 * <p>Output: nothing.
942 */
943 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
944 public static final String ACTION_RUN = "android.intent.action.RUN";
945 /**
946 * Activity Action: Perform a data synchronization.
947 * <p>Input: ?
948 * <p>Output: ?
949 */
950 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
951 public static final String ACTION_SYNC = "android.intent.action.SYNC";
952 /**
953 * Activity Action: Pick an activity given an intent, returning the class
954 * selected.
955 * <p>Input: get*Extra field {@link #EXTRA_INTENT} is an Intent
956 * used with {@link PackageManager#queryIntentActivities} to determine the
957 * set of activities from which to pick.
958 * <p>Output: Class name of the activity that was selected.
959 */
960 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
961 public static final String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
962 /**
963 * Activity Action: Perform a search.
964 * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
965 * is the text to search for. If empty, simply
966 * enter your search results Activity with the search UI activated.
967 * <p>Output: nothing.
968 */
969 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
970 public static final String ACTION_SEARCH = "android.intent.action.SEARCH";
971 /**
Jim Miller303736d2009-03-25 18:18:34 -0700972 * Activity Action: Start the platform-defined tutorial
973 * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
974 * is the text to search for. If empty, simply
975 * enter your search results Activity with the search UI activated.
976 * <p>Output: nothing.
977 */
978 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
979 public static final String ACTION_SYSTEM_TUTORIAL = "android.intent.action.SYSTEM_TUTORIAL";
980 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 * Activity Action: Perform a web search.
982 * <p>
983 * Input: {@link android.app.SearchManager#QUERY
984 * getStringExtra(SearchManager.QUERY)} is the text to search for. If it is
985 * a url starts with http or https, the site will be opened. If it is plain
986 * text, Google search will be applied.
987 * <p>
988 * Output: nothing.
989 */
990 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
991 public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
992 /**
993 * Activity Action: List all available applications
994 * <p>Input: Nothing.
995 * <p>Output: nothing.
996 */
997 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
998 public static final String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
999 /**
1000 * Activity Action: Show settings for choosing wallpaper
1001 * <p>Input: Nothing.
1002 * <p>Output: Nothing.
1003 */
1004 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1005 public static final String ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
1006
1007 /**
1008 * Activity Action: Show activity for reporting a bug.
1009 * <p>Input: Nothing.
1010 * <p>Output: Nothing.
1011 */
1012 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1013 public static final String ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
1014
1015 /**
1016 * Activity Action: Main entry point for factory tests. Only used when
1017 * the device is booting in factory test node. The implementing package
1018 * must be installed in the system image.
1019 * <p>Input: nothing
1020 * <p>Output: nothing
1021 */
1022 public static final String ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
1023
1024 /**
1025 * Activity Action: The user pressed the "call" button to go to the dialer
1026 * or other appropriate UI for placing a call.
1027 * <p>Input: Nothing.
1028 * <p>Output: Nothing.
1029 */
1030 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1031 public static final String ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
1032
1033 /**
1034 * Activity Action: Start Voice Command.
1035 * <p>Input: Nothing.
1036 * <p>Output: Nothing.
1037 */
1038 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1039 public static final String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001040
1041 /**
1042 * Activity Action: Start action associated with long pressing on the
1043 * search key.
1044 * <p>Input: Nothing.
1045 * <p>Output: Nothing.
1046 */
1047 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1048 public static final String ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";
The Android Open Source Project10592532009-03-18 17:39:46 -07001049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 // ---------------------------------------------------------------------
1051 // ---------------------------------------------------------------------
1052 // Standard intent broadcast actions (see action variable).
1053
1054 /**
1055 * Broadcast Action: Sent after the screen turns off.
1056 */
1057 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1058 public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
1059 /**
1060 * Broadcast Action: Sent after the screen turns on.
1061 */
1062 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1063 public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001064
1065 /**
The Android Open Source Project10592532009-03-18 17:39:46 -07001066 * Broadcast Action: Sent when the user is present after device wakes up (e.g when the
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001067 * keyguard is gone).
1068 */
1069 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1070 public static final String ACTION_USER_PRESENT= "android.intent.action.USER_PRESENT";
1071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 /**
1073 * Broadcast Action: The current time has changed. Sent every
1074 * minute. You can <em>not</em> receive this through components declared
1075 * in manifests, only by exlicitly registering for it with
1076 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1077 * Context.registerReceiver()}.
1078 */
1079 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1080 public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
1081 /**
1082 * Broadcast Action: The time was set.
1083 */
1084 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1085 public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
1086 /**
1087 * Broadcast Action: The date has changed.
1088 */
1089 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1090 public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
1091 /**
1092 * Broadcast Action: The timezone has changed. The intent will have the following extra values:</p>
1093 * <ul>
1094 * <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time zone.</li>
1095 * </ul>
1096 */
1097 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1098 public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
1099 /**
1100 * Alarm Changed Action: This is broadcast when the AlarmClock
1101 * application's alarm is set or unset. It is used by the
1102 * AlarmClock application and the StatusBar service.
1103 * @hide
1104 */
1105 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1106 public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
1107 /**
1108 * Sync State Changed Action: This is broadcast when the sync starts or stops or when one has
1109 * been failing for a long time. It is used by the SyncManager and the StatusBar service.
1110 * @hide
1111 */
1112 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1113 public static final String ACTION_SYNC_STATE_CHANGED
1114 = "android.intent.action.SYNC_STATE_CHANGED";
1115 /**
1116 * Broadcast Action: This is broadcast once, after the system has finished
1117 * booting. It can be used to perform application-specific initialization,
1118 * such as installing alarms. You must hold the
1119 * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
1120 * in order to receive this broadcast.
1121 */
1122 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1123 public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
1124 /**
1125 * Broadcast Action: This is broadcast when a user action should request a
1126 * temporary system dialog to dismiss. Some examples of temporary system
1127 * dialogs are the notification window-shade and the recent tasks dialog.
1128 */
1129 public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
1130 /**
1131 * Broadcast Action: Trigger the download and eventual installation
1132 * of a package.
1133 * <p>Input: {@link #getData} is the URI of the package file to download.
1134 */
1135 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1136 public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
1137 /**
1138 * Broadcast Action: A new application package has been installed on the
Dianne Hackbornf63220f2009-03-24 18:38:43 -07001139 * device. The data contains the name of the package. Note that the
1140 * newly installed package does <em>not</em> receive this broadcast.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 * <p>My include the following extras:
1142 * <ul>
1143 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1144 * <li> {@link #EXTRA_REPLACING} is set to true if this is following
1145 * an {@link #ACTION_PACKAGE_REMOVED} broadcast for the same package.
1146 * </ul>
1147 */
1148 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1149 public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
1150 /**
Dianne Hackbornf63220f2009-03-24 18:38:43 -07001151 * Broadcast Action: A new version of an application package has been
1152 * installed, replacing an existing version that was previously installed.
1153 * The data contains the name of the package.
1154 * <p>My include the following extras:
1155 * <ul>
1156 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1157 * </ul>
1158 */
1159 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1160 public static final String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
1161 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 * Broadcast Action: An existing application package has been removed from
1163 * the device. The data contains the name of the package. The package
1164 * that is being installed does <em>not</em> receive this Intent.
1165 * <ul>
1166 * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1167 * to the package.
1168 * <li> {@link #EXTRA_DATA_REMOVED} is set to true if the entire
1169 * application -- data and code -- is being removed.
1170 * <li> {@link #EXTRA_REPLACING} is set to true if this will be followed
1171 * by an {@link #ACTION_PACKAGE_ADDED} broadcast for the same package.
1172 * </ul>
1173 */
1174 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1175 public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
1176 /**
1177 * Broadcast Action: An existing application package has been changed (e.g. a component has been
1178 * enabled or disabled. The data contains the name of the package.
1179 * <ul>
1180 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1181 * </ul>
1182 */
1183 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1184 public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
1185 /**
1186 * Broadcast Action: The user has restarted a package, and all of its
1187 * processes have been killed. All runtime state
1188 * associated with it (processes, alarms, notifications, etc) should
Dianne Hackbornf63220f2009-03-24 18:38:43 -07001189 * be removed. Note that the restarted package does <em>not</em>
1190 * receive this broadcast.
1191 * The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 * <ul>
1193 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1194 * </ul>
1195 */
1196 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1197 public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
1198 /**
1199 * Broadcast Action: The user has cleared the data of a package. This should
1200 * be preceded by {@link #ACTION_PACKAGE_RESTARTED}, after which all of
Dianne Hackbornf63220f2009-03-24 18:38:43 -07001201 * its persistent data is erased and this broadcast sent.
1202 * Note that the cleared package does <em>not</em>
1203 * receive this broadcast. The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 * <ul>
1205 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1206 * </ul>
1207 */
1208 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1209 public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
1210 /**
1211 * Broadcast Action: A user ID has been removed from the system. The user
1212 * ID number is stored in the extra data under {@link #EXTRA_UID}.
1213 */
1214 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1215 public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
1216 /**
1217 * Broadcast Action: The current system wallpaper has changed. See
1218 * {@link Context#getWallpaper} for retrieving the new wallpaper.
1219 */
1220 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1221 public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
1222 /**
1223 * Broadcast Action: The current device {@link android.content.res.Configuration}
1224 * (orientation, locale, etc) has changed. When such a change happens, the
1225 * UIs (view hierarchy) will need to be rebuilt based on this new
1226 * information; for the most part, applications don't need to worry about
1227 * this, because the system will take care of stopping and restarting the
1228 * application to make sure it sees the new changes. Some system code that
1229 * can not be restarted will need to watch for this action and handle it
1230 * appropriately.
1231 *
1232 * @see android.content.res.Configuration
1233 */
1234 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1235 public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
1236 /**
1237 * Broadcast Action: The charging state, or charge level of the battery has
1238 * changed.
The Android Open Source Project10592532009-03-18 17:39:46 -07001239 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 * <p class="note">
1241 * You can <em>not</em> receive this through components declared
1242 * in manifests, only by exlicitly registering for it with
1243 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1244 * Context.registerReceiver()}.
1245 */
1246 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1247 public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
1248 /**
1249 * Broadcast Action: Indicates low battery condition on the device.
1250 * This broadcast corresponds to the "Low battery warning" system dialog.
1251 */
1252 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1253 public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
1254 /**
Christopher Tate06ba5542009-04-09 16:03:56 -07001255 * Broadcast Action: External power has been connected to the device.
1256 * This is intended for applications that wish to register specifically to this notification.
1257 * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1258 * stay active to receive this notification. This action can be used to implement actions
1259 * that wait until power is available to trigger.
1260 */
1261 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1262 public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
1263 /**
1264 * Broadcast Action: External power has been removed from the device.
1265 * This is intended for applications that wish to register specifically to this notification.
1266 * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1267 * stay active to receive this notification. This action can be used to implement actions
1268 * that wait until power is available to trigger.
1269 */
1270 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1271 public static final String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION_POWER_DISCONNECTED";
1272 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 * Broadcast Action: Indicates low memory condition on the device
1274 */
1275 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1276 public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
1277 /**
1278 * Broadcast Action: Indicates low memory condition on the device no longer exists
1279 */
1280 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1281 public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
1282 /**
1283 * Broadcast Action: Indicates low memory condition notification acknowledged by user
1284 * and package management should be started.
1285 * This is triggered by the user from the ACTION_DEVICE_STORAGE_LOW
1286 * notification.
1287 */
1288 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1289 public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
1290 /**
1291 * Broadcast Action: The device has entered USB Mass Storage mode.
1292 * This is used mainly for the USB Settings panel.
1293 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1294 * when the SD card file system is mounted or unmounted
1295 */
1296 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1297 public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
1298
1299 /**
1300 * Broadcast Action: The device has exited USB Mass Storage mode.
1301 * This is used mainly for the USB Settings panel.
1302 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1303 * when the SD card file system is mounted or unmounted
1304 */
1305 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1306 public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
1307
1308 /**
1309 * Broadcast Action: External media has been removed.
1310 * The path to the mount point for the removed media is contained in the Intent.mData field.
1311 */
1312 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1313 public static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
1314
1315 /**
1316 * Broadcast Action: External media is present, but not mounted at its mount point.
1317 * The path to the mount point for the removed media is contained in the Intent.mData field.
1318 */
1319 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1320 public static final String ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
1321
1322 /**
1323 * Broadcast Action: External media is present, and being disk-checked
1324 * The path to the mount point for the checking media is contained in the Intent.mData field.
1325 */
1326 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1327 public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
1328
1329 /**
1330 * Broadcast Action: External media is present, but is using an incompatible fs (or is blank)
1331 * The path to the mount point for the checking media is contained in the Intent.mData field.
1332 */
1333 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1334 public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
1335
1336 /**
1337 * Broadcast Action: External media is present and mounted at its mount point.
1338 * The path to the mount point for the removed media is contained in the Intent.mData field.
1339 * The Intent contains an extra with name "read-only" and Boolean value to indicate if the
1340 * media was mounted read only.
1341 */
1342 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1343 public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
1344
1345 /**
1346 * Broadcast Action: External media is unmounted because it is being shared via USB mass storage.
1347 * The path to the mount point for the removed media is contained in the Intent.mData field.
1348 */
1349 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1350 public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
1351
1352 /**
1353 * Broadcast Action: External media was removed from SD card slot, but mount point was not unmounted.
1354 * The path to the mount point for the removed media is contained in the Intent.mData field.
1355 */
1356 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1357 public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
1358
1359 /**
1360 * Broadcast Action: External media is present but cannot be mounted.
1361 * The path to the mount point for the removed media is contained in the Intent.mData field.
1362 */
1363 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1364 public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
1365
1366 /**
1367 * Broadcast Action: User has expressed the desire to remove the external storage media.
1368 * Applications should close all files they have open within the mount point when they receive this intent.
1369 * The path to the mount point for the media to be ejected is contained in the Intent.mData field.
1370 */
1371 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1372 public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
1373
1374 /**
1375 * Broadcast Action: The media scanner has started scanning a directory.
1376 * The path to the directory being scanned is contained in the Intent.mData field.
1377 */
1378 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1379 public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
1380
1381 /**
1382 * Broadcast Action: The media scanner has finished scanning a directory.
1383 * The path to the scanned directory is contained in the Intent.mData field.
1384 */
1385 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1386 public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
1387
1388 /**
1389 * Broadcast Action: Request the media scanner to scan a file and add it to the media database.
1390 * The path to the file is contained in the Intent.mData field.
1391 */
1392 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1393 public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
1394
1395 /**
1396 * Broadcast Action: The "Media Button" was pressed. Includes a single
1397 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1398 * caused the broadcast.
1399 */
1400 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1401 public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
1402
1403 /**
1404 * Broadcast Action: The "Camera Button" was pressed. Includes a single
1405 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1406 * caused the broadcast.
1407 */
1408 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1409 public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
1410
1411 // *** NOTE: @todo(*) The following really should go into a more domain-specific
1412 // location; they are not general-purpose actions.
1413
1414 /**
1415 * Broadcast Action: An GTalk connection has been established.
1416 */
1417 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1418 public static final String ACTION_GTALK_SERVICE_CONNECTED =
1419 "android.intent.action.GTALK_CONNECTED";
1420
1421 /**
1422 * Broadcast Action: An GTalk connection has been disconnected.
1423 */
1424 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1425 public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
1426 "android.intent.action.GTALK_DISCONNECTED";
The Android Open Source Project10592532009-03-18 17:39:46 -07001427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 /**
1429 * Broadcast Action: An input method has been changed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 */
1431 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1432 public static final String ACTION_INPUT_METHOD_CHANGED =
1433 "android.intent.action.INPUT_METHOD_CHANGED";
1434
1435 /**
1436 * <p>Broadcast Action: The user has switched the phone into or out of Airplane Mode. One or
1437 * more radios have been turned off or on. The intent will have the following extra value:</p>
1438 * <ul>
1439 * <li><em>state</em> - A boolean value indicating whether Airplane Mode is on. If true,
1440 * then cell radio and possibly other radios such as bluetooth or WiFi may have also been
1441 * turned off</li>
1442 * </ul>
1443 */
1444 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1445 public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
1446
1447 /**
1448 * Broadcast Action: Some content providers have parts of their namespace
1449 * where they publish new events or items that the user may be especially
1450 * interested in. For these things, they may broadcast this action when the
1451 * set of interesting items change.
1452 *
1453 * For example, GmailProvider sends this notification when the set of unread
1454 * mail in the inbox changes.
1455 *
1456 * <p>The data of the intent identifies which part of which provider
1457 * changed. When queried through the content resolver, the data URI will
1458 * return the data set in question.
1459 *
1460 * <p>The intent will have the following extra values:
1461 * <ul>
1462 * <li><em>count</em> - The number of items in the data set. This is the
1463 * same as the number of items in the cursor returned by querying the
1464 * data URI. </li>
1465 * </ul>
1466 *
1467 * This intent will be sent at boot (if the count is non-zero) and when the
1468 * data set changes. It is possible for the data set to change without the
1469 * count changing (for example, if a new unread message arrives in the same
1470 * sync operation in which a message is archived). The phone should still
1471 * ring/vibrate/etc as normal in this case.
1472 */
1473 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1474 public static final String ACTION_PROVIDER_CHANGED =
1475 "android.intent.action.PROVIDER_CHANGED";
1476
1477 /**
1478 * Broadcast Action: Wired Headset plugged in or unplugged.
1479 *
1480 * <p>The intent will have the following extra values:
1481 * <ul>
1482 * <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
1483 * <li><em>name</em> - Headset type, human readable string </li>
1484 * </ul>
1485 * </ul>
1486 */
1487 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1488 public static final String ACTION_HEADSET_PLUG =
1489 "android.intent.action.HEADSET_PLUG";
1490
1491 /**
1492 * Broadcast Action: An outgoing call is about to be placed.
1493 *
1494 * <p>The Intent will have the following extra value:
1495 * <ul>
The Android Open Source Project10592532009-03-18 17:39:46 -07001496 * <li><em>{@link android.content.Intent#EXTRA_PHONE_NUMBER}</em> -
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 * the phone number originally intended to be dialed.</li>
1498 * </ul>
1499 * <p>Once the broadcast is finished, the resultData is used as the actual
1500 * number to call. If <code>null</code>, no call will be placed.</p>
The Android Open Source Project10592532009-03-18 17:39:46 -07001501 * <p>It is perfectly acceptable for multiple receivers to process the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 * outgoing call in turn: for example, a parental control application
1503 * might verify that the user is authorized to place the call at that
1504 * time, then a number-rewriting application might add an area code if
1505 * one was not specified.</p>
1506 * <p>For consistency, any receiver whose purpose is to prohibit phone
1507 * calls should have a priority of 0, to ensure it will see the final
1508 * phone number to be dialed.
The Android Open Source Project10592532009-03-18 17:39:46 -07001509 * Any receiver whose purpose is to rewrite phone numbers to be called
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 * should have a positive priority.
1511 * Negative priorities are reserved for the system for this broadcast;
1512 * using them may cause problems.</p>
1513 * <p>Any BroadcastReceiver receiving this Intent <em>must not</em>
1514 * abort the broadcast.</p>
1515 * <p>Emergency calls cannot be intercepted using this mechanism, and
1516 * other calls cannot be modified to call emergency numbers using this
1517 * mechanism.
The Android Open Source Project10592532009-03-18 17:39:46 -07001518 * <p>You must hold the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 * {@link android.Manifest.permission#PROCESS_OUTGOING_CALLS}
1520 * permission to receive this Intent.</p>
1521 */
1522 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1523 public static final String ACTION_NEW_OUTGOING_CALL =
1524 "android.intent.action.NEW_OUTGOING_CALL";
1525
1526 /**
1527 * Broadcast Action: Have the device reboot. This is only for use by
1528 * system code.
1529 */
1530 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1531 public static final String ACTION_REBOOT =
1532 "android.intent.action.REBOOT";
1533
1534 // ---------------------------------------------------------------------
1535 // ---------------------------------------------------------------------
1536 // Standard intent categories (see addCategory()).
1537
1538 /**
1539 * Set if the activity should be an option for the default action
1540 * (center press) to perform on a piece of data. Setting this will
1541 * hide from the user any activities without it set when performing an
1542 * action on some data. Note that this is normal -not- set in the
1543 * Intent when initiating an action -- it is for use in intent filters
1544 * specified in packages.
1545 */
1546 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1547 public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
1548 /**
1549 * Activities that can be safely invoked from a browser must support this
1550 * category. For example, if the user is viewing a web page or an e-mail
1551 * and clicks on a link in the text, the Intent generated execute that
1552 * link will require the BROWSABLE category, so that only activities
1553 * supporting this category will be considered as possible actions. By
1554 * supporting this category, you are promising that there is nothing
1555 * damaging (without user intervention) that can happen by invoking any
1556 * matching Intent.
1557 */
1558 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1559 public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
1560 /**
1561 * Set if the activity should be considered as an alternative action to
1562 * the data the user is currently viewing. See also
1563 * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
1564 * applies to the selection in a list of items.
1565 *
1566 * <p>Supporting this category means that you would like your activity to be
1567 * displayed in the set of alternative things the user can do, usually as
1568 * part of the current activity's options menu. You will usually want to
1569 * include a specific label in the &lt;intent-filter&gt; of this action
1570 * describing to the user what it does.
1571 *
1572 * <p>The action of IntentFilter with this category is important in that it
1573 * describes the specific action the target will perform. This generally
1574 * should not be a generic action (such as {@link #ACTION_VIEW}, but rather
1575 * a specific name such as "com.android.camera.action.CROP. Only one
1576 * alternative of any particular action will be shown to the user, so using
1577 * a specific action like this makes sure that your alternative will be
1578 * displayed while also allowing other applications to provide their own
1579 * overrides of that particular action.
1580 */
1581 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1582 public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
1583 /**
1584 * Set if the activity should be considered as an alternative selection
1585 * action to the data the user has currently selected. This is like
1586 * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list
1587 * of items from which the user can select, giving them alternatives to the
1588 * default action that will be performed on it.
1589 */
1590 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1591 public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
1592 /**
1593 * Intended to be used as a tab inside of an containing TabActivity.
1594 */
1595 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1596 public static final String CATEGORY_TAB = "android.intent.category.TAB";
1597 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 * Should be displayed in the top-level launcher.
1599 */
1600 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1601 public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
1602 /**
1603 * Provides information about the package it is in; typically used if
1604 * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
1605 * a front-door to the user without having to be shown in the all apps list.
1606 */
1607 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1608 public static final String CATEGORY_INFO = "android.intent.category.INFO";
1609 /**
1610 * This is the home activity, that is the first activity that is displayed
1611 * when the device boots.
1612 */
1613 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1614 public static final String CATEGORY_HOME = "android.intent.category.HOME";
1615 /**
1616 * This activity is a preference panel.
1617 */
1618 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1619 public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
1620 /**
1621 * This activity is a development preference panel.
1622 */
1623 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1624 public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
1625 /**
1626 * Capable of running inside a parent activity container.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 */
1628 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1629 public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
1630 /**
1631 * This activity may be exercised by the monkey or other automated test tools.
1632 */
1633 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1634 public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
1635 /**
1636 * To be used as a test (not part of the normal user experience).
1637 */
1638 public static final String CATEGORY_TEST = "android.intent.category.TEST";
1639 /**
1640 * To be used as a unit test (run through the Test Harness).
1641 */
1642 public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
1643 /**
1644 * To be used as an sample code example (not part of the normal user
1645 * experience).
1646 */
1647 public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
1648 /**
1649 * Used to indicate that a GET_CONTENT intent only wants URIs that can be opened with
1650 * ContentResolver.openInputStream. Openable URIs must support the columns in OpenableColumns
1651 * when queried, though it is allowable for those columns to be blank.
1652 */
1653 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1654 public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
1655
1656 /**
1657 * To be used as code under test for framework instrumentation tests.
1658 */
1659 public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
1660 "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
1661 // ---------------------------------------------------------------------
1662 // ---------------------------------------------------------------------
1663 // Standard extra data keys.
1664
1665 /**
1666 * The initial data to place in a newly created record. Use with
1667 * {@link #ACTION_INSERT}. The data here is a Map containing the same
1668 * fields as would be given to the underlying ContentProvider.insert()
1669 * call.
1670 */
1671 public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
1672
1673 /**
1674 * A constant CharSequence that is associated with the Intent, used with
1675 * {@link #ACTION_SEND} to supply the literal data to be sent. Note that
1676 * this may be a styled CharSequence, so you must use
1677 * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to
1678 * retrieve it.
1679 */
1680 public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
1681
1682 /**
1683 * A content: URI holding a stream of data associated with the Intent,
1684 * used with {@link #ACTION_SEND} to supply the data being sent.
1685 */
1686 public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
1687
1688 /**
1689 * A String[] holding e-mail addresses that should be delivered to.
1690 */
1691 public static final String EXTRA_EMAIL = "android.intent.extra.EMAIL";
1692
1693 /**
1694 * A String[] holding e-mail addresses that should be carbon copied.
1695 */
1696 public static final String EXTRA_CC = "android.intent.extra.CC";
1697
1698 /**
1699 * A String[] holding e-mail addresses that should be blind carbon copied.
1700 */
1701 public static final String EXTRA_BCC = "android.intent.extra.BCC";
1702
1703 /**
1704 * A constant string holding the desired subject line of a message.
1705 */
1706 public static final String EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
1707
1708 /**
1709 * An Intent describing the choices you would like shown with
1710 * {@link #ACTION_PICK_ACTIVITY}.
1711 */
1712 public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
1713
1714 /**
1715 * A CharSequence dialog title to provide to the user when used with a
1716 * {@link #ACTION_CHOOSER}.
1717 */
1718 public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
1719
1720 /**
1721 * A {@link android.view.KeyEvent} object containing the event that
1722 * triggered the creation of the Intent it is in.
1723 */
1724 public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
1725
1726 /**
1727 * Used as an boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
1728 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
1729 * of restarting the application.
1730 */
1731 public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
1732
1733 /**
1734 * A String holding the phone number originally entered in
1735 * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual
1736 * number to call in a {@link android.content.Intent#ACTION_CALL}.
1737 */
1738 public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
1739 /**
1740 * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED}
1741 * intents to supply the uid the package had been assigned. Also an optional
1742 * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
1743 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same
1744 * purpose.
1745 */
1746 public static final String EXTRA_UID = "android.intent.extra.UID";
1747
1748 /**
1749 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
1750 * intents to indicate whether this represents a full uninstall (removing
1751 * both the code and its data) or a partial uninstall (leaving its data,
1752 * implying that this is an update).
1753 */
1754 public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
The Android Open Source Project10592532009-03-18 17:39:46 -07001755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 /**
1757 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
1758 * intents to indicate that this is a replacement of the package, so this
1759 * broadcast will immediately be followed by an add broadcast for a
1760 * different version of the same package.
1761 */
1762 public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
The Android Open Source Project10592532009-03-18 17:39:46 -07001763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 /**
1765 * Used as an int extra field in {@link android.app.AlarmManager} intents
1766 * to tell the application being invoked how many pending alarms are being
1767 * delievered with the intent. For one-shot alarms this will always be 1.
1768 * For recurring alarms, this might be greater than 1 if the device was
1769 * asleep or powered off at the time an earlier alarm would have been
1770 * delivered.
1771 */
1772 public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
1773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001774 // ---------------------------------------------------------------------
1775 // ---------------------------------------------------------------------
1776 // Intent flags (see mFlags variable).
1777
1778 /**
1779 * If set, the recipient of this Intent will be granted permission to
1780 * perform read operations on the Uri in the Intent's data.
1781 */
1782 public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
1783 /**
1784 * If set, the recipient of this Intent will be granted permission to
1785 * perform write operations on the Uri in the Intent's data.
1786 */
1787 public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
1788 /**
1789 * Can be set by the caller to indicate that this Intent is coming from
1790 * a background operation, not from direct user interaction.
1791 */
1792 public static final int FLAG_FROM_BACKGROUND = 0x00000004;
1793 /**
1794 * A flag you can enable for debugging: when set, log messages will be
1795 * printed during the resolution of this intent to show you what has
1796 * been found to create the final resolved list.
1797 */
1798 public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
1799
1800 /**
1801 * If set, the new activity is not kept in the history stack. As soon as
1802 * the user navigates away from it, the activity is finished. This may also
1803 * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
1804 * noHistory} attribute.
1805 */
1806 public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
1807 /**
1808 * If set, the activity will not be launched if it is already running
1809 * at the top of the history stack.
1810 */
1811 public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
1812 /**
1813 * If set, this activity will become the start of a new task on this
1814 * history stack. A task (from the activity that started it to the
1815 * next task activity) defines an atomic group of activities that the
1816 * user can move to. Tasks can be moved to the foreground and background;
1817 * all of the activities inside of a particular task always remain in
The Android Open Source Project10592532009-03-18 17:39:46 -07001818 * the same order. See
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 * <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
1820 * Activities and Tasks</a> for more details on tasks.
1821 *
1822 * <p>This flag is generally used by activities that want
1823 * to present a "launcher" style behavior: they give the user a list of
1824 * separate things that can be done, which otherwise run completely
1825 * independently of the activity launching them.
1826 *
1827 * <p>When using this flag, if a task is already running for the activity
1828 * you are now starting, then a new activity will not be started; instead,
1829 * the current task will simply be brought to the front of the screen with
1830 * the state it was last in. See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
1831 * to disable this behavior.
1832 *
1833 * <p>This flag can not be used when the caller is requesting a result from
1834 * the activity being launched.
1835 */
1836 public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
1837 /**
1838 * <strong>Do not use this flag unless you are implementing your own
1839 * top-level application launcher.</strong> Used in conjunction with
1840 * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the
1841 * behavior of bringing an existing task to the foreground. When set,
1842 * a new task is <em>always</em> started to host the Activity for the
1843 * Intent, regardless of whether there is already an existing task running
1844 * the same thing.
1845 *
1846 * <p><strong>Because the default system does not include graphical task management,
1847 * you should not use this flag unless you provide some way for a user to
1848 * return back to the tasks you have launched.</strong>
The Android Open Source Project10592532009-03-18 17:39:46 -07001849 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 * <p>This flag is ignored if
1851 * {@link #FLAG_ACTIVITY_NEW_TASK} is not set.
1852 *
1853 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
1854 * Activities and Tasks</a> for more details on tasks.
1855 */
1856 public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
1857 /**
1858 * If set, and the activity being launched is already running in the
1859 * current task, then instead of launching a new instance of that activity,
1860 * all of the other activities on top of it will be closed and this Intent
1861 * will be delivered to the (now on top) old activity as a new Intent.
1862 *
1863 * <p>For example, consider a task consisting of the activities: A, B, C, D.
1864 * If D calls startActivity() with an Intent that resolves to the component
1865 * of activity B, then C and D will be finished and B receive the given
1866 * Intent, resulting in the stack now being: A, B.
1867 *
1868 * <p>The currently running instance of task B in the above example will
1869 * either receive the new intent you are starting here in its
1870 * onNewIntent() method, or be itself finished and restarted with the
1871 * new intent. If it has declared its launch mode to be "multiple" (the
1872 * default) it will be finished and re-created; for all other launch modes
1873 * it will receive the Intent in the current instance.
1874 *
1875 * <p>This launch mode can also be used to good effect in conjunction with
1876 * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity
1877 * of a task, it will bring any currently running instance of that task
1878 * to the foreground, and then clear it to its root state. This is
1879 * especially useful, for example, when launching an activity from the
1880 * notification manager.
1881 *
1882 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
1883 * Activities and Tasks</a> for more details on tasks.
1884 */
1885 public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
1886 /**
1887 * If set and this intent is being used to launch a new activity from an
1888 * existing one, then the reply target of the existing activity will be
1889 * transfered to the new activity. This way the new activity can call
1890 * {@link android.app.Activity#setResult} and have that result sent back to
1891 * the reply target of the original activity.
1892 */
1893 public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
1894 /**
1895 * If set and this intent is being used to launch a new activity from an
1896 * existing one, the current activity will not be counted as the top
1897 * activity for deciding whether the new intent should be delivered to
1898 * the top instead of starting a new one. The previous activity will
1899 * be used as the top, with the assumption being that the current activity
1900 * will finish itself immediately.
1901 */
1902 public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
1903 /**
1904 * If set, the new activity is not kept in the list of recently launched
1905 * activities.
1906 */
1907 public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
1908 /**
1909 * This flag is not normally set by application code, but set for you by
1910 * the system as described in the
1911 * {@link android.R.styleable#AndroidManifestActivity_launchMode
1912 * launchMode} documentation for the singleTask mode.
1913 */
1914 public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
1915 /**
1916 * If set, and this activity is either being started in a new task or
1917 * bringing to the top an existing task, then it will be launched as
1918 * the front door of the task. This will result in the application of
1919 * any affinities needed to have that task in the proper state (either
1920 * moving activities to or from it), or simply resetting that task to
1921 * its initial state if needed.
1922 */
1923 public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
1924 /**
1925 * This flag is not normally set by application code, but set for you by
1926 * the system if this activity is being launched from history
1927 * (longpress home key).
1928 */
1929 public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
1930 /**
1931 * If set, this marks a point in the task's activity stack that should
1932 * be cleared when the task is reset. That is, the next time the task
1933 * is broad to the foreground with
1934 * {@link #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED} (typically as a result of
1935 * the user re-launching it from home), this activity and all on top of
1936 * it will be finished so that the user does not return to them, but
1937 * instead returns to whatever activity preceeded it.
The Android Open Source Project10592532009-03-18 17:39:46 -07001938 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 * <p>This is useful for cases where you have a logical break in your
1940 * application. For example, an e-mail application may have a command
1941 * to view an attachment, which launches an image view activity to
1942 * display it. This activity should be part of the e-mail application's
1943 * task, since it is a part of the task the user is involved in. However,
1944 * if the user leaves that task, and later selects the e-mail app from
1945 * home, we may like them to return to the conversation they were
1946 * viewing, not the picture attachment, since that is confusing. By
1947 * setting this flag when launching the image viewer, that viewer and
1948 * any activities it starts will be removed the next time the user returns
1949 * to mail.
1950 */
1951 public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
1952 /**
1953 * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint}
1954 * callback from occurring on the current frontmost activity before it is
1955 * paused as the newly-started activity is brought to the front.
The Android Open Source Project10592532009-03-18 17:39:46 -07001956 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 * <p>Typically, an activity can rely on that callback to indicate that an
1958 * explicit user action has caused their activity to be moved out of the
1959 * foreground. The callback marks an appropriate point in the activity's
1960 * lifecycle for it to dismiss any notifications that it intends to display
1961 * "until the user has seen them," such as a blinking LED.
The Android Open Source Project10592532009-03-18 17:39:46 -07001962 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 * <p>If an activity is ever started via any non-user-driven events such as
1964 * phone-call receipt or an alarm handler, this flag should be passed to {@link
1965 * Context#startActivity Context.startActivity}, ensuring that the pausing
The Android Open Source Project10592532009-03-18 17:39:46 -07001966 * activity does not think the user has acknowledged its notification.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 */
1968 public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
1969 /**
1970 * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
1971 * this flag will cause the launched activity to be brought to the front of its
1972 * task's history stack if it is already running.
The Android Open Source Project10592532009-03-18 17:39:46 -07001973 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 * <p>For example, consider a task consisting of four activities: A, B, C, D.
1975 * If D calls startActivity() with an Intent that resolves to the component
1976 * of activity B, then B will be brought to the front of the history stack,
1977 * with this resulting order: A, C, D, B.
The Android Open Source Project10592532009-03-18 17:39:46 -07001978 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also
The Android Open Source Project10592532009-03-18 17:39:46 -07001980 * specified.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 */
1982 public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
1983 /**
1984 * If set, when sending a broadcast only registered receivers will be
1985 * called -- no BroadcastReceiver components will be launched.
1986 */
1987 public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
1988 /**
1989 * If set, when sending a broadcast <i>before boot has completed</i> only
1990 * registered receivers will be called -- no BroadcastReceiver components
1991 * will be launched. Sticky intent state will be recorded properly even
1992 * if no receivers wind up being called. If {@link #FLAG_RECEIVER_REGISTERED_ONLY}
1993 * is specified in the broadcast intent, this flag is unnecessary.
The Android Open Source Project10592532009-03-18 17:39:46 -07001994 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 * <p>This flag is only for use by system sevices as a convenience to
1996 * avoid having to implement a more complex mechanism around detection
1997 * of boot completion.
The Android Open Source Project10592532009-03-18 17:39:46 -07001998 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 * @hide
2000 */
2001 public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x20000000;
2002
2003 // ---------------------------------------------------------------------
2004
2005 private String mAction;
2006 private Uri mData;
2007 private String mType;
2008 private ComponentName mComponent;
2009 private int mFlags;
2010 private HashSet<String> mCategories;
2011 private Bundle mExtras;
2012
2013 // ---------------------------------------------------------------------
2014
2015 /**
2016 * Create an empty intent.
2017 */
2018 public Intent() {
2019 }
2020
2021 /**
2022 * Copy constructor.
2023 */
2024 public Intent(Intent o) {
2025 this.mAction = o.mAction;
2026 this.mData = o.mData;
2027 this.mType = o.mType;
2028 this.mComponent = o.mComponent;
2029 this.mFlags = o.mFlags;
2030 if (o.mCategories != null) {
2031 this.mCategories = new HashSet<String>(o.mCategories);
2032 }
2033 if (o.mExtras != null) {
2034 this.mExtras = new Bundle(o.mExtras);
2035 }
2036 }
2037
2038 @Override
2039 public Object clone() {
2040 return new Intent(this);
2041 }
2042
2043 private Intent(Intent o, boolean all) {
2044 this.mAction = o.mAction;
2045 this.mData = o.mData;
2046 this.mType = o.mType;
2047 this.mComponent = o.mComponent;
2048 if (o.mCategories != null) {
2049 this.mCategories = new HashSet<String>(o.mCategories);
2050 }
2051 }
2052
2053 /**
2054 * Make a clone of only the parts of the Intent that are relevant for
2055 * filter matching: the action, data, type, component, and categories.
2056 */
2057 public Intent cloneFilter() {
2058 return new Intent(this, false);
2059 }
2060
2061 /**
2062 * Create an intent with a given action. All other fields (data, type,
2063 * class) are null. Note that the action <em>must</em> be in a
2064 * namespace because Intents are used globally in the system -- for
2065 * example the system VIEW action is android.intent.action.VIEW; an
2066 * application's custom action would be something like
2067 * com.google.app.myapp.CUSTOM_ACTION.
2068 *
2069 * @param action The Intent action, such as ACTION_VIEW.
2070 */
2071 public Intent(String action) {
2072 mAction = action;
2073 }
2074
2075 /**
2076 * Create an intent with a given action and for a given data url. Note
2077 * that the action <em>must</em> be in a namespace because Intents are
2078 * used globally in the system -- for example the system VIEW action is
2079 * android.intent.action.VIEW; an application's custom action would be
2080 * something like com.google.app.myapp.CUSTOM_ACTION.
2081 *
Dianne Hackborn06f36b42009-04-13 08:52:45 -07002082 * <p><em>Note: scheme and host name matching in the Android framework is
2083 * case-sensitive, unlike the formal RFC. As a result,
2084 * you should always ensure that you write your Uri with these elements
2085 * using lower case letters, and normalize any Uris you receive from
2086 * outside of Android to ensure the scheme and host is lower case.</em></p>
2087 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088 * @param action The Intent action, such as ACTION_VIEW.
2089 * @param uri The Intent data URI.
2090 */
2091 public Intent(String action, Uri uri) {
2092 mAction = action;
2093 mData = uri;
2094 }
2095
2096 /**
2097 * Create an intent for a specific component. All other fields (action, data,
2098 * type, class) are null, though they can be modified later with explicit
2099 * calls. This provides a convenient way to create an intent that is
2100 * intended to execute a hard-coded class name, rather than relying on the
2101 * system to find an appropriate class for you; see {@link #setComponent}
2102 * for more information on the repercussions of this.
2103 *
2104 * @param packageContext A Context of the application package implementing
2105 * this class.
2106 * @param cls The component class that is to be used for the intent.
2107 *
2108 * @see #setClass
2109 * @see #setComponent
2110 * @see #Intent(String, android.net.Uri , Context, Class)
2111 */
2112 public Intent(Context packageContext, Class<?> cls) {
2113 mComponent = new ComponentName(packageContext, cls);
2114 }
2115
2116 /**
2117 * Create an intent for a specific component with a specified action and data.
2118 * This is equivalent using {@link #Intent(String, android.net.Uri)} to
2119 * construct the Intent and then calling {@link #setClass} to set its
2120 * class.
2121 *
Dianne Hackborn06f36b42009-04-13 08:52:45 -07002122 * <p><em>Note: scheme and host name matching in the Android framework is
2123 * case-sensitive, unlike the formal RFC. As a result,
2124 * you should always ensure that you write your Uri with these elements
2125 * using lower case letters, and normalize any Uris you receive from
2126 * outside of Android to ensure the scheme and host is lower case.</em></p>
2127 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 * @param action The Intent action, such as ACTION_VIEW.
2129 * @param uri The Intent data URI.
2130 * @param packageContext A Context of the application package implementing
2131 * this class.
2132 * @param cls The component class that is to be used for the intent.
2133 *
2134 * @see #Intent(String, android.net.Uri)
2135 * @see #Intent(Context, Class)
2136 * @see #setClass
2137 * @see #setComponent
2138 */
2139 public Intent(String action, Uri uri,
2140 Context packageContext, Class<?> cls) {
2141 mAction = action;
2142 mData = uri;
2143 mComponent = new ComponentName(packageContext, cls);
2144 }
2145
2146 /**
2147 * Create an intent from a URI. This URI may encode the action,
2148 * category, and other intent fields, if it was returned by toURI(). If
2149 * the Intent was not generate by toURI(), its data will be the entire URI
2150 * and its action will be ACTION_VIEW.
2151 *
2152 * <p>The URI given here must not be relative -- that is, it must include
2153 * the scheme and full path.
2154 *
2155 * @param uri The URI to turn into an Intent.
2156 *
2157 * @return Intent The newly created Intent object.
2158 *
2159 * @see #toURI
2160 */
2161 public static Intent getIntent(String uri) throws URISyntaxException {
2162 int i = 0;
2163 try {
2164 // simple case
2165 i = uri.lastIndexOf("#");
2166 if (i == -1) return new Intent(ACTION_VIEW, Uri.parse(uri));
2167
2168 // old format Intent URI
2169 if (!uri.startsWith("#Intent;", i)) return getIntentOld(uri);
The Android Open Source Project10592532009-03-18 17:39:46 -07002170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 // new format
2172 Intent intent = new Intent(ACTION_VIEW);
2173
2174 // fetch data part, if present
2175 if (i > 0) {
2176 intent.mData = Uri.parse(uri.substring(0, i));
2177 }
2178 i += "#Intent;".length();
The Android Open Source Project10592532009-03-18 17:39:46 -07002179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 // loop over contents of Intent, all name=value;
2181 while (!uri.startsWith("end", i)) {
2182 int eq = uri.indexOf('=', i);
2183 int semi = uri.indexOf(';', eq);
2184 String value = uri.substring(eq + 1, semi);
2185
2186 // action
2187 if (uri.startsWith("action=", i)) {
2188 intent.mAction = value;
2189 }
2190
2191 // categories
2192 else if (uri.startsWith("category=", i)) {
2193 intent.addCategory(value);
2194 }
2195
2196 // type
2197 else if (uri.startsWith("type=", i)) {
2198 intent.mType = value;
2199 }
2200
2201 // launch flags
2202 else if (uri.startsWith("launchFlags=", i)) {
2203 intent.mFlags = Integer.decode(value).intValue();
2204 }
2205
2206 // component
2207 else if (uri.startsWith("component=", i)) {
2208 intent.mComponent = ComponentName.unflattenFromString(value);
2209 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 // extra
2212 else {
2213 String key = Uri.decode(uri.substring(i + 2, eq));
2214 value = Uri.decode(value);
2215 // create Bundle if it doesn't already exist
2216 if (intent.mExtras == null) intent.mExtras = new Bundle();
2217 Bundle b = intent.mExtras;
2218 // add EXTRA
2219 if (uri.startsWith("S.", i)) b.putString(key, value);
2220 else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
2221 else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
2222 else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
2223 else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
2224 else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
2225 else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
2226 else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
2227 else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
2228 else throw new URISyntaxException(uri, "unknown EXTRA type", i);
2229 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002231 // move to the next item
2232 i = semi + 1;
2233 }
2234
2235 return intent;
The Android Open Source Project10592532009-03-18 17:39:46 -07002236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 } catch (IndexOutOfBoundsException e) {
2238 throw new URISyntaxException(uri, "illegal Intent URI format", i);
2239 }
2240 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 public static Intent getIntentOld(String uri) throws URISyntaxException {
2243 Intent intent;
2244
2245 int i = uri.lastIndexOf('#');
2246 if (i >= 0) {
2247 Uri data = null;
2248 String action = null;
2249 if (i > 0) {
2250 data = Uri.parse(uri.substring(0, i));
2251 }
2252
2253 i++;
2254
2255 if (uri.regionMatches(i, "action(", 0, 7)) {
2256 i += 7;
2257 int j = uri.indexOf(')', i);
2258 action = uri.substring(i, j);
2259 i = j + 1;
2260 }
2261
2262 intent = new Intent(action, data);
2263
2264 if (uri.regionMatches(i, "categories(", 0, 11)) {
2265 i += 11;
2266 int j = uri.indexOf(')', i);
2267 while (i < j) {
2268 int sep = uri.indexOf('!', i);
2269 if (sep < 0) sep = j;
2270 if (i < sep) {
2271 intent.addCategory(uri.substring(i, sep));
2272 }
2273 i = sep + 1;
2274 }
2275 i = j + 1;
2276 }
2277
2278 if (uri.regionMatches(i, "type(", 0, 5)) {
2279 i += 5;
2280 int j = uri.indexOf(')', i);
2281 intent.mType = uri.substring(i, j);
2282 i = j + 1;
2283 }
2284
2285 if (uri.regionMatches(i, "launchFlags(", 0, 12)) {
2286 i += 12;
2287 int j = uri.indexOf(')', i);
2288 intent.mFlags = Integer.decode(uri.substring(i, j)).intValue();
2289 i = j + 1;
2290 }
2291
2292 if (uri.regionMatches(i, "component(", 0, 10)) {
2293 i += 10;
2294 int j = uri.indexOf(')', i);
2295 int sep = uri.indexOf('!', i);
2296 if (sep >= 0 && sep < j) {
2297 String pkg = uri.substring(i, sep);
2298 String cls = uri.substring(sep + 1, j);
2299 intent.mComponent = new ComponentName(pkg, cls);
2300 }
2301 i = j + 1;
2302 }
2303
2304 if (uri.regionMatches(i, "extras(", 0, 7)) {
2305 i += 7;
The Android Open Source Project10592532009-03-18 17:39:46 -07002306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 final int closeParen = uri.indexOf(')', i);
2308 if (closeParen == -1) throw new URISyntaxException(uri,
2309 "EXTRA missing trailing ')'", i);
2310
2311 while (i < closeParen) {
2312 // fetch the key value
2313 int j = uri.indexOf('=', i);
2314 if (j <= i + 1 || i >= closeParen) {
2315 throw new URISyntaxException(uri, "EXTRA missing '='", i);
2316 }
2317 char type = uri.charAt(i);
2318 i++;
2319 String key = uri.substring(i, j);
2320 i = j + 1;
The Android Open Source Project10592532009-03-18 17:39:46 -07002321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 // get type-value
2323 j = uri.indexOf('!', i);
2324 if (j == -1 || j >= closeParen) j = closeParen;
2325 if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2326 String value = uri.substring(i, j);
2327 i = j;
2328
2329 // create Bundle if it doesn't already exist
2330 if (intent.mExtras == null) intent.mExtras = new Bundle();
The Android Open Source Project10592532009-03-18 17:39:46 -07002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 // add item to bundle
2333 try {
2334 switch (type) {
2335 case 'S':
2336 intent.mExtras.putString(key, Uri.decode(value));
2337 break;
2338 case 'B':
2339 intent.mExtras.putBoolean(key, Boolean.parseBoolean(value));
2340 break;
2341 case 'b':
2342 intent.mExtras.putByte(key, Byte.parseByte(value));
2343 break;
2344 case 'c':
2345 intent.mExtras.putChar(key, Uri.decode(value).charAt(0));
2346 break;
2347 case 'd':
2348 intent.mExtras.putDouble(key, Double.parseDouble(value));
2349 break;
2350 case 'f':
2351 intent.mExtras.putFloat(key, Float.parseFloat(value));
2352 break;
2353 case 'i':
2354 intent.mExtras.putInt(key, Integer.parseInt(value));
2355 break;
2356 case 'l':
2357 intent.mExtras.putLong(key, Long.parseLong(value));
2358 break;
2359 case 's':
2360 intent.mExtras.putShort(key, Short.parseShort(value));
2361 break;
2362 default:
2363 throw new URISyntaxException(uri, "EXTRA has unknown type", i);
2364 }
2365 } catch (NumberFormatException e) {
2366 throw new URISyntaxException(uri, "EXTRA value can't be parsed", i);
2367 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 char ch = uri.charAt(i);
2370 if (ch == ')') break;
2371 if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2372 i++;
2373 }
2374 }
2375
2376 if (intent.mAction == null) {
2377 // By default, if no action is specified, then use VIEW.
2378 intent.mAction = ACTION_VIEW;
2379 }
2380
2381 } else {
2382 intent = new Intent(ACTION_VIEW, Uri.parse(uri));
2383 }
2384
2385 return intent;
2386 }
2387
2388 /**
2389 * Retrieve the general action to be performed, such as
2390 * {@link #ACTION_VIEW}. The action describes the general way the rest of
2391 * the information in the intent should be interpreted -- most importantly,
2392 * what to do with the data returned by {@link #getData}.
2393 *
2394 * @return The action of this intent or null if none is specified.
2395 *
2396 * @see #setAction
2397 */
2398 public String getAction() {
2399 return mAction;
2400 }
2401
2402 /**
2403 * Retrieve data this intent is operating on. This URI specifies the name
2404 * of the data; often it uses the content: scheme, specifying data in a
2405 * content provider. Other schemes may be handled by specific activities,
2406 * such as http: by the web browser.
2407 *
2408 * @return The URI of the data this intent is targeting or null.
2409 *
2410 * @see #getScheme
2411 * @see #setData
2412 */
2413 public Uri getData() {
2414 return mData;
2415 }
2416
2417 /**
2418 * The same as {@link #getData()}, but returns the URI as an encoded
2419 * String.
2420 */
2421 public String getDataString() {
2422 return mData != null ? mData.toString() : null;
2423 }
2424
2425 /**
2426 * Return the scheme portion of the intent's data. If the data is null or
2427 * does not include a scheme, null is returned. Otherwise, the scheme
2428 * prefix without the final ':' is returned, i.e. "http".
2429 *
2430 * <p>This is the same as calling getData().getScheme() (and checking for
2431 * null data).
2432 *
2433 * @return The scheme of this intent.
2434 *
2435 * @see #getData
2436 */
2437 public String getScheme() {
2438 return mData != null ? mData.getScheme() : null;
2439 }
2440
2441 /**
2442 * Retrieve any explicit MIME type included in the intent. This is usually
2443 * null, as the type is determined by the intent data.
2444 *
2445 * @return If a type was manually set, it is returned; else null is
2446 * returned.
2447 *
2448 * @see #resolveType(ContentResolver)
2449 * @see #setType
2450 */
2451 public String getType() {
2452 return mType;
2453 }
2454
2455 /**
2456 * Return the MIME data type of this intent. If the type field is
2457 * explicitly set, that is simply returned. Otherwise, if the data is set,
2458 * the type of that data is returned. If neither fields are set, a null is
2459 * returned.
2460 *
2461 * @return The MIME type of this intent.
2462 *
2463 * @see #getType
2464 * @see #resolveType(ContentResolver)
2465 */
2466 public String resolveType(Context context) {
2467 return resolveType(context.getContentResolver());
2468 }
2469
2470 /**
2471 * Return the MIME data type of this intent. If the type field is
2472 * explicitly set, that is simply returned. Otherwise, if the data is set,
2473 * the type of that data is returned. If neither fields are set, a null is
2474 * returned.
2475 *
2476 * @param resolver A ContentResolver that can be used to determine the MIME
2477 * type of the intent's data.
2478 *
2479 * @return The MIME type of this intent.
2480 *
2481 * @see #getType
2482 * @see #resolveType(Context)
2483 */
2484 public String resolveType(ContentResolver resolver) {
2485 if (mType != null) {
2486 return mType;
2487 }
2488 if (mData != null) {
2489 if ("content".equals(mData.getScheme())) {
2490 return resolver.getType(mData);
2491 }
2492 }
2493 return null;
2494 }
2495
2496 /**
2497 * Return the MIME data type of this intent, only if it will be needed for
2498 * intent resolution. This is not generally useful for application code;
2499 * it is used by the frameworks for communicating with back-end system
2500 * services.
2501 *
2502 * @param resolver A ContentResolver that can be used to determine the MIME
2503 * type of the intent's data.
2504 *
2505 * @return The MIME type of this intent, or null if it is unknown or not
2506 * needed.
2507 */
2508 public String resolveTypeIfNeeded(ContentResolver resolver) {
2509 if (mComponent != null) {
2510 return mType;
2511 }
2512 return resolveType(resolver);
2513 }
2514
2515 /**
2516 * Check if an category exists in the intent.
2517 *
2518 * @param category The category to check.
2519 *
2520 * @return boolean True if the intent contains the category, else false.
2521 *
2522 * @see #getCategories
2523 * @see #addCategory
2524 */
2525 public boolean hasCategory(String category) {
2526 return mCategories != null && mCategories.contains(category);
2527 }
2528
2529 /**
2530 * Return the set of all categories in the intent. If there are no categories,
2531 * returns NULL.
2532 *
2533 * @return Set The set of categories you can examine. Do not modify!
2534 *
2535 * @see #hasCategory
2536 * @see #addCategory
2537 */
2538 public Set<String> getCategories() {
2539 return mCategories;
2540 }
2541
2542 /**
2543 * Sets the ClassLoader that will be used when unmarshalling
2544 * any Parcelable values from the extras of this Intent.
2545 *
2546 * @param loader a ClassLoader, or null to use the default loader
2547 * at the time of unmarshalling.
2548 */
2549 public void setExtrasClassLoader(ClassLoader loader) {
2550 if (mExtras != null) {
2551 mExtras.setClassLoader(loader);
2552 }
2553 }
2554
2555 /**
2556 * Returns true if an extra value is associated with the given name.
2557 * @param name the extra's name
2558 * @return true if the given extra is present.
2559 */
2560 public boolean hasExtra(String name) {
2561 return mExtras != null && mExtras.containsKey(name);
2562 }
2563
2564 /**
2565 * Returns true if the Intent's extras contain a parcelled file descriptor.
2566 * @return true if the Intent contains a parcelled file descriptor.
2567 */
2568 public boolean hasFileDescriptors() {
2569 return mExtras != null && mExtras.hasFileDescriptors();
2570 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 /**
2573 * Retrieve extended data from the intent.
2574 *
2575 * @param name The name of the desired item.
2576 *
2577 * @return the value of an item that previously added with putExtra()
2578 * or null if none was found.
2579 *
2580 * @deprecated
2581 * @hide
2582 */
2583 @Deprecated
2584 public Object getExtra(String name) {
2585 return getExtra(name, null);
2586 }
2587
2588 /**
2589 * Retrieve extended data from the intent.
2590 *
2591 * @param name The name of the desired item.
2592 * @param defaultValue the value to be returned if no value of the desired
2593 * type is stored with the given name.
2594 *
2595 * @return the value of an item that previously added with putExtra()
2596 * or the default value if none was found.
2597 *
2598 * @see #putExtra(String, boolean)
2599 */
2600 public boolean getBooleanExtra(String name, boolean defaultValue) {
2601 return mExtras == null ? defaultValue :
2602 mExtras.getBoolean(name, defaultValue);
2603 }
2604
2605 /**
2606 * Retrieve extended data from the intent.
2607 *
2608 * @param name The name of the desired item.
2609 * @param defaultValue the value to be returned if no value of the desired
2610 * type is stored with the given name.
2611 *
2612 * @return the value of an item that previously added with putExtra()
2613 * or the default value if none was found.
2614 *
2615 * @see #putExtra(String, byte)
2616 */
2617 public byte getByteExtra(String name, byte defaultValue) {
2618 return mExtras == null ? defaultValue :
2619 mExtras.getByte(name, defaultValue);
2620 }
2621
2622 /**
2623 * Retrieve extended data from the intent.
2624 *
2625 * @param name The name of the desired item.
2626 * @param defaultValue the value to be returned if no value of the desired
2627 * type is stored with the given name.
2628 *
2629 * @return the value of an item that previously added with putExtra()
2630 * or the default value if none was found.
2631 *
2632 * @see #putExtra(String, short)
2633 */
2634 public short getShortExtra(String name, short defaultValue) {
2635 return mExtras == null ? defaultValue :
2636 mExtras.getShort(name, defaultValue);
2637 }
2638
2639 /**
2640 * Retrieve extended data from the intent.
2641 *
2642 * @param name The name of the desired item.
2643 * @param defaultValue the value to be returned if no value of the desired
2644 * type is stored with the given name.
2645 *
2646 * @return the value of an item that previously added with putExtra()
2647 * or the default value if none was found.
2648 *
2649 * @see #putExtra(String, char)
2650 */
2651 public char getCharExtra(String name, char defaultValue) {
2652 return mExtras == null ? defaultValue :
2653 mExtras.getChar(name, defaultValue);
2654 }
2655
2656 /**
2657 * Retrieve extended data from the intent.
2658 *
2659 * @param name The name of the desired item.
2660 * @param defaultValue the value to be returned if no value of the desired
2661 * type is stored with the given name.
2662 *
2663 * @return the value of an item that previously added with putExtra()
2664 * or the default value if none was found.
2665 *
2666 * @see #putExtra(String, int)
2667 */
2668 public int getIntExtra(String name, int defaultValue) {
2669 return mExtras == null ? defaultValue :
2670 mExtras.getInt(name, defaultValue);
2671 }
2672
2673 /**
2674 * Retrieve extended data from the intent.
2675 *
2676 * @param name The name of the desired item.
2677 * @param defaultValue the value to be returned if no value of the desired
2678 * type is stored with the given name.
2679 *
2680 * @return the value of an item that previously added with putExtra()
2681 * or the default value if none was found.
2682 *
2683 * @see #putExtra(String, long)
2684 */
2685 public long getLongExtra(String name, long defaultValue) {
2686 return mExtras == null ? defaultValue :
2687 mExtras.getLong(name, defaultValue);
2688 }
2689
2690 /**
2691 * Retrieve extended data from the intent.
2692 *
2693 * @param name The name of the desired item.
2694 * @param defaultValue the value to be returned if no value of the desired
2695 * type is stored with the given name.
2696 *
2697 * @return the value of an item that previously added with putExtra(),
2698 * or the default value if no such item is present
2699 *
2700 * @see #putExtra(String, float)
2701 */
2702 public float getFloatExtra(String name, float defaultValue) {
2703 return mExtras == null ? defaultValue :
2704 mExtras.getFloat(name, defaultValue);
2705 }
2706
2707 /**
2708 * Retrieve extended data from the intent.
2709 *
2710 * @param name The name of the desired item.
2711 * @param defaultValue the value to be returned if no value of the desired
2712 * type is stored with the given name.
2713 *
2714 * @return the value of an item that previously added with putExtra()
2715 * or the default value if none was found.
2716 *
2717 * @see #putExtra(String, double)
2718 */
2719 public double getDoubleExtra(String name, double defaultValue) {
2720 return mExtras == null ? defaultValue :
2721 mExtras.getDouble(name, defaultValue);
2722 }
2723
2724 /**
2725 * Retrieve extended data from the intent.
2726 *
2727 * @param name The name of the desired item.
2728 *
2729 * @return the value of an item that previously added with putExtra()
2730 * or null if no String value was found.
2731 *
2732 * @see #putExtra(String, String)
2733 */
2734 public String getStringExtra(String name) {
2735 return mExtras == null ? null : mExtras.getString(name);
2736 }
2737
2738 /**
2739 * Retrieve extended data from the intent.
2740 *
2741 * @param name The name of the desired item.
2742 *
2743 * @return the value of an item that previously added with putExtra()
2744 * or null if no CharSequence value was found.
2745 *
2746 * @see #putExtra(String, CharSequence)
2747 */
2748 public CharSequence getCharSequenceExtra(String name) {
2749 return mExtras == null ? null : mExtras.getCharSequence(name);
2750 }
2751
2752 /**
2753 * Retrieve extended data from the intent.
2754 *
2755 * @param name The name of the desired item.
2756 *
2757 * @return the value of an item that previously added with putExtra()
2758 * or null if no Parcelable value was found.
2759 *
2760 * @see #putExtra(String, Parcelable)
2761 */
2762 public <T extends Parcelable> T getParcelableExtra(String name) {
2763 return mExtras == null ? null : mExtras.<T>getParcelable(name);
2764 }
2765
2766 /**
2767 * Retrieve extended data from the intent.
2768 *
2769 * @param name The name of the desired item.
2770 *
2771 * @return the value of an item that previously added with putExtra()
2772 * or null if no Parcelable[] value was found.
2773 *
2774 * @see #putExtra(String, Parcelable[])
2775 */
2776 public Parcelable[] getParcelableArrayExtra(String name) {
2777 return mExtras == null ? null : mExtras.getParcelableArray(name);
2778 }
2779
2780 /**
2781 * Retrieve extended data from the intent.
2782 *
2783 * @param name The name of the desired item.
2784 *
2785 * @return the value of an item that previously added with putExtra()
2786 * or null if no ArrayList<Parcelable> value was found.
2787 *
2788 * @see #putParcelableArrayListExtra(String, ArrayList)
2789 */
2790 public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
2791 return mExtras == null ? null : mExtras.<T>getParcelableArrayList(name);
2792 }
2793
2794 /**
2795 * Retrieve extended data from the intent.
2796 *
2797 * @param name The name of the desired item.
2798 *
2799 * @return the value of an item that previously added with putExtra()
2800 * or null if no Serializable value was found.
2801 *
2802 * @see #putExtra(String, Serializable)
2803 */
2804 public Serializable getSerializableExtra(String name) {
2805 return mExtras == null ? null : mExtras.getSerializable(name);
2806 }
2807
2808 /**
2809 * Retrieve extended data from the intent.
2810 *
2811 * @param name The name of the desired item.
2812 *
2813 * @return the value of an item that previously added with putExtra()
2814 * or null if no ArrayList<Integer> value was found.
2815 *
2816 * @see #putIntegerArrayListExtra(String, ArrayList)
2817 */
2818 public ArrayList<Integer> getIntegerArrayListExtra(String name) {
2819 return mExtras == null ? null : mExtras.getIntegerArrayList(name);
2820 }
2821
2822 /**
2823 * Retrieve extended data from the intent.
2824 *
2825 * @param name The name of the desired item.
2826 *
2827 * @return the value of an item that previously added with putExtra()
2828 * or null if no ArrayList<String> value was found.
2829 *
2830 * @see #putStringArrayListExtra(String, ArrayList)
2831 */
2832 public ArrayList<String> getStringArrayListExtra(String name) {
2833 return mExtras == null ? null : mExtras.getStringArrayList(name);
2834 }
2835
2836 /**
2837 * Retrieve extended data from the intent.
2838 *
2839 * @param name The name of the desired item.
2840 *
2841 * @return the value of an item that previously added with putExtra()
2842 * or null if no boolean array value was found.
2843 *
2844 * @see #putExtra(String, boolean[])
2845 */
2846 public boolean[] getBooleanArrayExtra(String name) {
2847 return mExtras == null ? null : mExtras.getBooleanArray(name);
2848 }
2849
2850 /**
2851 * Retrieve extended data from the intent.
2852 *
2853 * @param name The name of the desired item.
2854 *
2855 * @return the value of an item that previously added with putExtra()
2856 * or null if no byte array value was found.
2857 *
2858 * @see #putExtra(String, byte[])
2859 */
2860 public byte[] getByteArrayExtra(String name) {
2861 return mExtras == null ? null : mExtras.getByteArray(name);
2862 }
2863
2864 /**
2865 * Retrieve extended data from the intent.
2866 *
2867 * @param name The name of the desired item.
2868 *
2869 * @return the value of an item that previously added with putExtra()
2870 * or null if no short array value was found.
2871 *
2872 * @see #putExtra(String, short[])
2873 */
2874 public short[] getShortArrayExtra(String name) {
2875 return mExtras == null ? null : mExtras.getShortArray(name);
2876 }
2877
2878 /**
2879 * Retrieve extended data from the intent.
2880 *
2881 * @param name The name of the desired item.
2882 *
2883 * @return the value of an item that previously added with putExtra()
2884 * or null if no char array value was found.
2885 *
2886 * @see #putExtra(String, char[])
2887 */
2888 public char[] getCharArrayExtra(String name) {
2889 return mExtras == null ? null : mExtras.getCharArray(name);
2890 }
2891
2892 /**
2893 * Retrieve extended data from the intent.
2894 *
2895 * @param name The name of the desired item.
2896 *
2897 * @return the value of an item that previously added with putExtra()
2898 * or null if no int array value was found.
2899 *
2900 * @see #putExtra(String, int[])
2901 */
2902 public int[] getIntArrayExtra(String name) {
2903 return mExtras == null ? null : mExtras.getIntArray(name);
2904 }
2905
2906 /**
2907 * Retrieve extended data from the intent.
2908 *
2909 * @param name The name of the desired item.
2910 *
2911 * @return the value of an item that previously added with putExtra()
2912 * or null if no long array value was found.
2913 *
2914 * @see #putExtra(String, long[])
2915 */
2916 public long[] getLongArrayExtra(String name) {
2917 return mExtras == null ? null : mExtras.getLongArray(name);
2918 }
2919
2920 /**
2921 * Retrieve extended data from the intent.
2922 *
2923 * @param name The name of the desired item.
2924 *
2925 * @return the value of an item that previously added with putExtra()
2926 * or null if no float array value was found.
2927 *
2928 * @see #putExtra(String, float[])
2929 */
2930 public float[] getFloatArrayExtra(String name) {
2931 return mExtras == null ? null : mExtras.getFloatArray(name);
2932 }
2933
2934 /**
2935 * Retrieve extended data from the intent.
2936 *
2937 * @param name The name of the desired item.
2938 *
2939 * @return the value of an item that previously added with putExtra()
2940 * or null if no double array value was found.
2941 *
2942 * @see #putExtra(String, double[])
2943 */
2944 public double[] getDoubleArrayExtra(String name) {
2945 return mExtras == null ? null : mExtras.getDoubleArray(name);
2946 }
2947
2948 /**
2949 * Retrieve extended data from the intent.
2950 *
2951 * @param name The name of the desired item.
2952 *
2953 * @return the value of an item that previously added with putExtra()
2954 * or null if no String array value was found.
2955 *
2956 * @see #putExtra(String, String[])
2957 */
2958 public String[] getStringArrayExtra(String name) {
2959 return mExtras == null ? null : mExtras.getStringArray(name);
2960 }
2961
2962 /**
2963 * Retrieve extended data from the intent.
2964 *
2965 * @param name The name of the desired item.
2966 *
2967 * @return the value of an item that previously added with putExtra()
2968 * or null if no Bundle value was found.
2969 *
2970 * @see #putExtra(String, Bundle)
2971 */
2972 public Bundle getBundleExtra(String name) {
2973 return mExtras == null ? null : mExtras.getBundle(name);
2974 }
2975
2976 /**
2977 * Retrieve extended data from the intent.
2978 *
2979 * @param name The name of the desired item.
2980 *
2981 * @return the value of an item that previously added with putExtra()
2982 * or null if no IBinder value was found.
2983 *
2984 * @see #putExtra(String, IBinder)
2985 *
2986 * @deprecated
2987 * @hide
2988 */
2989 @Deprecated
2990 public IBinder getIBinderExtra(String name) {
2991 return mExtras == null ? null : mExtras.getIBinder(name);
2992 }
2993
2994 /**
2995 * Retrieve extended data from the intent.
2996 *
2997 * @param name The name of the desired item.
2998 * @param defaultValue The default value to return in case no item is
2999 * associated with the key 'name'
3000 *
3001 * @return the value of an item that previously added with putExtra()
3002 * or defaultValue if none was found.
3003 *
3004 * @see #putExtra
3005 *
3006 * @deprecated
3007 * @hide
3008 */
3009 @Deprecated
3010 public Object getExtra(String name, Object defaultValue) {
3011 Object result = defaultValue;
3012 if (mExtras != null) {
3013 Object result2 = mExtras.get(name);
3014 if (result2 != null) {
3015 result = result2;
3016 }
3017 }
3018
3019 return result;
3020 }
3021
3022 /**
3023 * Retrieves a map of extended data from the intent.
3024 *
3025 * @return the map of all extras previously added with putExtra(),
3026 * or null if none have been added.
3027 */
3028 public Bundle getExtras() {
3029 return (mExtras != null)
3030 ? new Bundle(mExtras)
3031 : null;
3032 }
3033
3034 /**
3035 * Retrieve any special flags associated with this intent. You will
3036 * normally just set them with {@link #setFlags} and let the system
3037 * take the appropriate action with them.
3038 *
3039 * @return int The currently set flags.
3040 *
3041 * @see #setFlags
3042 */
3043 public int getFlags() {
3044 return mFlags;
3045 }
3046
3047 /**
3048 * Retrieve the concrete component associated with the intent. When receiving
3049 * an intent, this is the component that was found to best handle it (that is,
3050 * yourself) and will always be non-null; in all other cases it will be
3051 * null unless explicitly set.
3052 *
3053 * @return The name of the application component to handle the intent.
3054 *
3055 * @see #resolveActivity
3056 * @see #setComponent
3057 */
3058 public ComponentName getComponent() {
3059 return mComponent;
3060 }
3061
3062 /**
3063 * Return the Activity component that should be used to handle this intent.
3064 * The appropriate component is determined based on the information in the
3065 * intent, evaluated as follows:
3066 *
3067 * <p>If {@link #getComponent} returns an explicit class, that is returned
3068 * without any further consideration.
3069 *
3070 * <p>The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent
3071 * category to be considered.
3072 *
3073 * <p>If {@link #getAction} is non-NULL, the activity must handle this
3074 * action.
3075 *
3076 * <p>If {@link #resolveType} returns non-NULL, the activity must handle
3077 * this type.
3078 *
3079 * <p>If {@link #addCategory} has added any categories, the activity must
3080 * handle ALL of the categories specified.
3081 *
3082 * <p>If there are no activities that satisfy all of these conditions, a
3083 * null string is returned.
3084 *
3085 * <p>If multiple activities are found to satisfy the intent, the one with
3086 * the highest priority will be used. If there are multiple activities
3087 * with the same priority, the system will either pick the best activity
3088 * based on user preference, or resolve to a system class that will allow
3089 * the user to pick an activity and forward from there.
3090 *
3091 * <p>This method is implemented simply by calling
3092 * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter
3093 * true.</p>
3094 * <p> This API is called for you as part of starting an activity from an
3095 * intent. You do not normally need to call it yourself.</p>
3096 *
3097 * @param pm The package manager with which to resolve the Intent.
3098 *
3099 * @return Name of the component implementing an activity that can
3100 * display the intent.
3101 *
3102 * @see #setComponent
3103 * @see #getComponent
3104 * @see #resolveActivityInfo
3105 */
3106 public ComponentName resolveActivity(PackageManager pm) {
3107 if (mComponent != null) {
3108 return mComponent;
3109 }
3110
3111 ResolveInfo info = pm.resolveActivity(
3112 this, PackageManager.MATCH_DEFAULT_ONLY);
3113 if (info != null) {
3114 return new ComponentName(
3115 info.activityInfo.applicationInfo.packageName,
3116 info.activityInfo.name);
3117 }
3118
3119 return null;
3120 }
3121
3122 /**
3123 * Resolve the Intent into an {@link ActivityInfo}
3124 * describing the activity that should execute the intent. Resolution
3125 * follows the same rules as described for {@link #resolveActivity}, but
3126 * you get back the completely information about the resolved activity
3127 * instead of just its class name.
3128 *
3129 * @param pm The package manager with which to resolve the Intent.
3130 * @param flags Addition information to retrieve as per
3131 * {@link PackageManager#getActivityInfo(ComponentName, int)
3132 * PackageManager.getActivityInfo()}.
3133 *
3134 * @return PackageManager.ActivityInfo
3135 *
3136 * @see #resolveActivity
3137 */
3138 public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) {
3139 ActivityInfo ai = null;
3140 if (mComponent != null) {
3141 try {
3142 ai = pm.getActivityInfo(mComponent, flags);
3143 } catch (PackageManager.NameNotFoundException e) {
3144 // ignore
3145 }
3146 } else {
3147 ResolveInfo info = pm.resolveActivity(
3148 this, PackageManager.MATCH_DEFAULT_ONLY);
3149 if (info != null) {
3150 ai = info.activityInfo;
3151 }
3152 }
3153
3154 return ai;
3155 }
3156
3157 /**
3158 * Set the general action to be performed.
3159 *
3160 * @param action An action name, such as ACTION_VIEW. Application-specific
3161 * actions should be prefixed with the vendor's package name.
3162 *
3163 * @return Returns the same Intent object, for chaining multiple calls
3164 * into a single statement.
3165 *
3166 * @see #getAction
3167 */
3168 public Intent setAction(String action) {
3169 mAction = action;
3170 return this;
3171 }
3172
3173 /**
3174 * Set the data this intent is operating on. This method automatically
3175 * clears any type that was previously set by {@link #setType}.
3176 *
Dianne Hackborn06f36b42009-04-13 08:52:45 -07003177 * <p><em>Note: scheme and host name matching in the Android framework is
3178 * case-sensitive, unlike the formal RFC. As a result,
3179 * you should always ensure that you write your Uri with these elements
3180 * using lower case letters, and normalize any Uris you receive from
3181 * outside of Android to ensure the scheme and host is lower case.</em></p>
3182 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 * @param data The URI of the data this intent is now targeting.
3184 *
3185 * @return Returns the same Intent object, for chaining multiple calls
3186 * into a single statement.
3187 *
3188 * @see #getData
3189 * @see #setType
3190 * @see #setDataAndType
3191 */
3192 public Intent setData(Uri data) {
3193 mData = data;
3194 mType = null;
3195 return this;
3196 }
3197
3198 /**
3199 * Set an explicit MIME data type. This is used to create intents that
3200 * only specify a type and not data, for example to indicate the type of
3201 * data to return. This method automatically clears any data that was
3202 * previously set by {@link #setData}.
Dianne Hackborn06f36b42009-04-13 08:52:45 -07003203 *
3204 * <p><em>Note: MIME type matching in the Android framework is
3205 * case-sensitive, unlike formal RFC MIME types. As a result,
3206 * you should always write your MIME types with lower case letters,
3207 * and any MIME types you receive from outside of Android should be
3208 * converted to lower case before supplying them here.</em></p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 *
3210 * @param type The MIME type of the data being handled by this intent.
3211 *
3212 * @return Returns the same Intent object, for chaining multiple calls
3213 * into a single statement.
3214 *
3215 * @see #getType
3216 * @see #setData
3217 * @see #setDataAndType
3218 */
3219 public Intent setType(String type) {
3220 mData = null;
3221 mType = type;
3222 return this;
3223 }
3224
3225 /**
3226 * (Usually optional) Set the data for the intent along with an explicit
3227 * MIME data type. This method should very rarely be used -- it allows you
3228 * to override the MIME type that would ordinarily be inferred from the
3229 * data with your own type given here.
3230 *
Dianne Hackborn06f36b42009-04-13 08:52:45 -07003231 * <p><em>Note: MIME type, Uri scheme, and host name matching in the
3232 * Android framework is case-sensitive, unlike the formal RFC definitions.
3233 * As a result, you should always write these elements with lower case letters,
3234 * and normalize any MIME types or Uris you receive from
3235 * outside of Android to ensure these elements are lower case before
3236 * supplying them here.</em></p>
3237 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 * @param data The URI of the data this intent is now targeting.
3239 * @param type The MIME type of the data being handled by this intent.
3240 *
3241 * @return Returns the same Intent object, for chaining multiple calls
3242 * into a single statement.
3243 *
3244 * @see #setData
3245 * @see #setType
3246 */
3247 public Intent setDataAndType(Uri data, String type) {
3248 mData = data;
3249 mType = type;
3250 return this;
3251 }
3252
3253 /**
3254 * Add a new category to the intent. Categories provide additional detail
3255 * about the action the intent is perform. When resolving an intent, only
3256 * activities that provide <em>all</em> of the requested categories will be
3257 * used.
3258 *
3259 * @param category The desired category. This can be either one of the
3260 * predefined Intent categories, or a custom category in your own
3261 * namespace.
3262 *
3263 * @return Returns the same Intent object, for chaining multiple calls
3264 * into a single statement.
3265 *
3266 * @see #hasCategory
3267 * @see #removeCategory
3268 */
3269 public Intent addCategory(String category) {
3270 if (mCategories == null) {
3271 mCategories = new HashSet<String>();
3272 }
3273 mCategories.add(category);
3274 return this;
3275 }
3276
3277 /**
3278 * Remove an category from an intent.
3279 *
3280 * @param category The category to remove.
3281 *
3282 * @see #addCategory
3283 */
3284 public void removeCategory(String category) {
3285 if (mCategories != null) {
3286 mCategories.remove(category);
3287 if (mCategories.size() == 0) {
3288 mCategories = null;
3289 }
3290 }
3291 }
3292
3293 /**
3294 * Add extended data to the intent. The name must include a package
3295 * prefix, for example the app com.android.contacts would use names
3296 * like "com.android.contacts.ShowAll".
3297 *
3298 * @param name The name of the extra data, with package prefix.
3299 * @param value The boolean data value.
3300 *
3301 * @return Returns the same Intent object, for chaining multiple calls
3302 * into a single statement.
3303 *
3304 * @see #putExtras
3305 * @see #removeExtra
3306 * @see #getBooleanExtra(String, boolean)
3307 */
3308 public Intent putExtra(String name, boolean value) {
3309 if (mExtras == null) {
3310 mExtras = new Bundle();
3311 }
3312 mExtras.putBoolean(name, value);
3313 return this;
3314 }
3315
3316 /**
3317 * Add extended data to the intent. The name must include a package
3318 * prefix, for example the app com.android.contacts would use names
3319 * like "com.android.contacts.ShowAll".
3320 *
3321 * @param name The name of the extra data, with package prefix.
3322 * @param value The byte data value.
3323 *
3324 * @return Returns the same Intent object, for chaining multiple calls
3325 * into a single statement.
3326 *
3327 * @see #putExtras
3328 * @see #removeExtra
3329 * @see #getByteExtra(String, byte)
3330 */
3331 public Intent putExtra(String name, byte value) {
3332 if (mExtras == null) {
3333 mExtras = new Bundle();
3334 }
3335 mExtras.putByte(name, value);
3336 return this;
3337 }
3338
3339 /**
3340 * Add extended data to the intent. The name must include a package
3341 * prefix, for example the app com.android.contacts would use names
3342 * like "com.android.contacts.ShowAll".
3343 *
3344 * @param name The name of the extra data, with package prefix.
3345 * @param value The char data value.
3346 *
3347 * @return Returns the same Intent object, for chaining multiple calls
3348 * into a single statement.
3349 *
3350 * @see #putExtras
3351 * @see #removeExtra
3352 * @see #getCharExtra(String, char)
3353 */
3354 public Intent putExtra(String name, char value) {
3355 if (mExtras == null) {
3356 mExtras = new Bundle();
3357 }
3358 mExtras.putChar(name, value);
3359 return this;
3360 }
3361
3362 /**
3363 * Add extended data to the intent. The name must include a package
3364 * prefix, for example the app com.android.contacts would use names
3365 * like "com.android.contacts.ShowAll".
3366 *
3367 * @param name The name of the extra data, with package prefix.
3368 * @param value The short data value.
3369 *
3370 * @return Returns the same Intent object, for chaining multiple calls
3371 * into a single statement.
3372 *
3373 * @see #putExtras
3374 * @see #removeExtra
3375 * @see #getShortExtra(String, short)
3376 */
3377 public Intent putExtra(String name, short value) {
3378 if (mExtras == null) {
3379 mExtras = new Bundle();
3380 }
3381 mExtras.putShort(name, value);
3382 return this;
3383 }
3384
3385 /**
3386 * Add extended data to the intent. The name must include a package
3387 * prefix, for example the app com.android.contacts would use names
3388 * like "com.android.contacts.ShowAll".
3389 *
3390 * @param name The name of the extra data, with package prefix.
3391 * @param value The integer data value.
3392 *
3393 * @return Returns the same Intent object, for chaining multiple calls
3394 * into a single statement.
3395 *
3396 * @see #putExtras
3397 * @see #removeExtra
3398 * @see #getIntExtra(String, int)
3399 */
3400 public Intent putExtra(String name, int value) {
3401 if (mExtras == null) {
3402 mExtras = new Bundle();
3403 }
3404 mExtras.putInt(name, value);
3405 return this;
3406 }
3407
3408 /**
3409 * Add extended data to the intent. The name must include a package
3410 * prefix, for example the app com.android.contacts would use names
3411 * like "com.android.contacts.ShowAll".
3412 *
3413 * @param name The name of the extra data, with package prefix.
3414 * @param value The long data value.
3415 *
3416 * @return Returns the same Intent object, for chaining multiple calls
3417 * into a single statement.
3418 *
3419 * @see #putExtras
3420 * @see #removeExtra
3421 * @see #getLongExtra(String, long)
3422 */
3423 public Intent putExtra(String name, long value) {
3424 if (mExtras == null) {
3425 mExtras = new Bundle();
3426 }
3427 mExtras.putLong(name, value);
3428 return this;
3429 }
3430
3431 /**
3432 * Add extended data to the intent. The name must include a package
3433 * prefix, for example the app com.android.contacts would use names
3434 * like "com.android.contacts.ShowAll".
3435 *
3436 * @param name The name of the extra data, with package prefix.
3437 * @param value The float data value.
3438 *
3439 * @return Returns the same Intent object, for chaining multiple calls
3440 * into a single statement.
3441 *
3442 * @see #putExtras
3443 * @see #removeExtra
3444 * @see #getFloatExtra(String, float)
3445 */
3446 public Intent putExtra(String name, float value) {
3447 if (mExtras == null) {
3448 mExtras = new Bundle();
3449 }
3450 mExtras.putFloat(name, value);
3451 return this;
3452 }
3453
3454 /**
3455 * Add extended data to the intent. The name must include a package
3456 * prefix, for example the app com.android.contacts would use names
3457 * like "com.android.contacts.ShowAll".
3458 *
3459 * @param name The name of the extra data, with package prefix.
3460 * @param value The double data value.
3461 *
3462 * @return Returns the same Intent object, for chaining multiple calls
3463 * into a single statement.
3464 *
3465 * @see #putExtras
3466 * @see #removeExtra
3467 * @see #getDoubleExtra(String, double)
3468 */
3469 public Intent putExtra(String name, double value) {
3470 if (mExtras == null) {
3471 mExtras = new Bundle();
3472 }
3473 mExtras.putDouble(name, value);
3474 return this;
3475 }
3476
3477 /**
3478 * Add extended data to the intent. The name must include a package
3479 * prefix, for example the app com.android.contacts would use names
3480 * like "com.android.contacts.ShowAll".
3481 *
3482 * @param name The name of the extra data, with package prefix.
3483 * @param value The String data value.
3484 *
3485 * @return Returns the same Intent object, for chaining multiple calls
3486 * into a single statement.
3487 *
3488 * @see #putExtras
3489 * @see #removeExtra
3490 * @see #getStringExtra(String)
3491 */
3492 public Intent putExtra(String name, String value) {
3493 if (mExtras == null) {
3494 mExtras = new Bundle();
3495 }
3496 mExtras.putString(name, value);
3497 return this;
3498 }
3499
3500 /**
3501 * Add extended data to the intent. The name must include a package
3502 * prefix, for example the app com.android.contacts would use names
3503 * like "com.android.contacts.ShowAll".
3504 *
3505 * @param name The name of the extra data, with package prefix.
3506 * @param value The CharSequence data value.
3507 *
3508 * @return Returns the same Intent object, for chaining multiple calls
3509 * into a single statement.
3510 *
3511 * @see #putExtras
3512 * @see #removeExtra
3513 * @see #getCharSequenceExtra(String)
3514 */
3515 public Intent putExtra(String name, CharSequence value) {
3516 if (mExtras == null) {
3517 mExtras = new Bundle();
3518 }
3519 mExtras.putCharSequence(name, value);
3520 return this;
3521 }
3522
3523 /**
3524 * Add extended data to the intent. The name must include a package
3525 * prefix, for example the app com.android.contacts would use names
3526 * like "com.android.contacts.ShowAll".
3527 *
3528 * @param name The name of the extra data, with package prefix.
3529 * @param value The Parcelable data value.
3530 *
3531 * @return Returns the same Intent object, for chaining multiple calls
3532 * into a single statement.
3533 *
3534 * @see #putExtras
3535 * @see #removeExtra
3536 * @see #getParcelableExtra(String)
3537 */
3538 public Intent putExtra(String name, Parcelable value) {
3539 if (mExtras == null) {
3540 mExtras = new Bundle();
3541 }
3542 mExtras.putParcelable(name, value);
3543 return this;
3544 }
3545
3546 /**
3547 * Add extended data to the intent. The name must include a package
3548 * prefix, for example the app com.android.contacts would use names
3549 * like "com.android.contacts.ShowAll".
3550 *
3551 * @param name The name of the extra data, with package prefix.
3552 * @param value The Parcelable[] data value.
3553 *
3554 * @return Returns the same Intent object, for chaining multiple calls
3555 * into a single statement.
3556 *
3557 * @see #putExtras
3558 * @see #removeExtra
3559 * @see #getParcelableArrayExtra(String)
3560 */
3561 public Intent putExtra(String name, Parcelable[] value) {
3562 if (mExtras == null) {
3563 mExtras = new Bundle();
3564 }
3565 mExtras.putParcelableArray(name, value);
3566 return this;
3567 }
3568
3569 /**
3570 * Add extended data to the intent. The name must include a package
3571 * prefix, for example the app com.android.contacts would use names
3572 * like "com.android.contacts.ShowAll".
3573 *
3574 * @param name The name of the extra data, with package prefix.
3575 * @param value The ArrayList<Parcelable> data value.
3576 *
3577 * @return Returns the same Intent object, for chaining multiple calls
3578 * into a single statement.
3579 *
3580 * @see #putExtras
3581 * @see #removeExtra
3582 * @see #getParcelableArrayListExtra(String)
3583 */
3584 public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
3585 if (mExtras == null) {
3586 mExtras = new Bundle();
3587 }
3588 mExtras.putParcelableArrayList(name, value);
3589 return this;
3590 }
3591
3592 /**
3593 * Add extended data to the intent. The name must include a package
3594 * prefix, for example the app com.android.contacts would use names
3595 * like "com.android.contacts.ShowAll".
3596 *
3597 * @param name The name of the extra data, with package prefix.
3598 * @param value The ArrayList<Integer> data value.
3599 *
3600 * @return Returns the same Intent object, for chaining multiple calls
3601 * into a single statement.
3602 *
3603 * @see #putExtras
3604 * @see #removeExtra
3605 * @see #getIntegerArrayListExtra(String)
3606 */
3607 public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
3608 if (mExtras == null) {
3609 mExtras = new Bundle();
3610 }
3611 mExtras.putIntegerArrayList(name, value);
3612 return this;
3613 }
3614
3615 /**
3616 * Add extended data to the intent. The name must include a package
3617 * prefix, for example the app com.android.contacts would use names
3618 * like "com.android.contacts.ShowAll".
3619 *
3620 * @param name The name of the extra data, with package prefix.
3621 * @param value The ArrayList<String> data value.
3622 *
3623 * @return Returns the same Intent object, for chaining multiple calls
3624 * into a single statement.
3625 *
3626 * @see #putExtras
3627 * @see #removeExtra
3628 * @see #getStringArrayListExtra(String)
3629 */
3630 public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
3631 if (mExtras == null) {
3632 mExtras = new Bundle();
3633 }
3634 mExtras.putStringArrayList(name, value);
3635 return this;
3636 }
3637
3638 /**
3639 * Add extended data to the intent. The name must include a package
3640 * prefix, for example the app com.android.contacts would use names
3641 * like "com.android.contacts.ShowAll".
3642 *
3643 * @param name The name of the extra data, with package prefix.
3644 * @param value The Serializable data value.
3645 *
3646 * @return Returns the same Intent object, for chaining multiple calls
3647 * into a single statement.
3648 *
3649 * @see #putExtras
3650 * @see #removeExtra
3651 * @see #getSerializableExtra(String)
3652 */
3653 public Intent putExtra(String name, Serializable value) {
3654 if (mExtras == null) {
3655 mExtras = new Bundle();
3656 }
3657 mExtras.putSerializable(name, value);
3658 return this;
3659 }
3660
3661 /**
3662 * Add extended data to the intent. The name must include a package
3663 * prefix, for example the app com.android.contacts would use names
3664 * like "com.android.contacts.ShowAll".
3665 *
3666 * @param name The name of the extra data, with package prefix.
3667 * @param value The boolean array data value.
3668 *
3669 * @return Returns the same Intent object, for chaining multiple calls
3670 * into a single statement.
3671 *
3672 * @see #putExtras
3673 * @see #removeExtra
3674 * @see #getBooleanArrayExtra(String)
3675 */
3676 public Intent putExtra(String name, boolean[] value) {
3677 if (mExtras == null) {
3678 mExtras = new Bundle();
3679 }
3680 mExtras.putBooleanArray(name, value);
3681 return this;
3682 }
3683
3684 /**
3685 * Add extended data to the intent. The name must include a package
3686 * prefix, for example the app com.android.contacts would use names
3687 * like "com.android.contacts.ShowAll".
3688 *
3689 * @param name The name of the extra data, with package prefix.
3690 * @param value The byte array data value.
3691 *
3692 * @return Returns the same Intent object, for chaining multiple calls
3693 * into a single statement.
3694 *
3695 * @see #putExtras
3696 * @see #removeExtra
3697 * @see #getByteArrayExtra(String)
3698 */
3699 public Intent putExtra(String name, byte[] value) {
3700 if (mExtras == null) {
3701 mExtras = new Bundle();
3702 }
3703 mExtras.putByteArray(name, value);
3704 return this;
3705 }
3706
3707 /**
3708 * Add extended data to the intent. The name must include a package
3709 * prefix, for example the app com.android.contacts would use names
3710 * like "com.android.contacts.ShowAll".
3711 *
3712 * @param name The name of the extra data, with package prefix.
3713 * @param value The short array data value.
3714 *
3715 * @return Returns the same Intent object, for chaining multiple calls
3716 * into a single statement.
3717 *
3718 * @see #putExtras
3719 * @see #removeExtra
3720 * @see #getShortArrayExtra(String)
3721 */
3722 public Intent putExtra(String name, short[] value) {
3723 if (mExtras == null) {
3724 mExtras = new Bundle();
3725 }
3726 mExtras.putShortArray(name, value);
3727 return this;
3728 }
3729
3730 /**
3731 * Add extended data to the intent. The name must include a package
3732 * prefix, for example the app com.android.contacts would use names
3733 * like "com.android.contacts.ShowAll".
3734 *
3735 * @param name The name of the extra data, with package prefix.
3736 * @param value The char array data value.
3737 *
3738 * @return Returns the same Intent object, for chaining multiple calls
3739 * into a single statement.
3740 *
3741 * @see #putExtras
3742 * @see #removeExtra
3743 * @see #getCharArrayExtra(String)
3744 */
3745 public Intent putExtra(String name, char[] value) {
3746 if (mExtras == null) {
3747 mExtras = new Bundle();
3748 }
3749 mExtras.putCharArray(name, value);
3750 return this;
3751 }
3752
3753 /**
3754 * Add extended data to the intent. The name must include a package
3755 * prefix, for example the app com.android.contacts would use names
3756 * like "com.android.contacts.ShowAll".
3757 *
3758 * @param name The name of the extra data, with package prefix.
3759 * @param value The int array data value.
3760 *
3761 * @return Returns the same Intent object, for chaining multiple calls
3762 * into a single statement.
3763 *
3764 * @see #putExtras
3765 * @see #removeExtra
3766 * @see #getIntArrayExtra(String)
3767 */
3768 public Intent putExtra(String name, int[] value) {
3769 if (mExtras == null) {
3770 mExtras = new Bundle();
3771 }
3772 mExtras.putIntArray(name, value);
3773 return this;
3774 }
3775
3776 /**
3777 * Add extended data to the intent. The name must include a package
3778 * prefix, for example the app com.android.contacts would use names
3779 * like "com.android.contacts.ShowAll".
3780 *
3781 * @param name The name of the extra data, with package prefix.
3782 * @param value The byte array data value.
3783 *
3784 * @return Returns the same Intent object, for chaining multiple calls
3785 * into a single statement.
3786 *
3787 * @see #putExtras
3788 * @see #removeExtra
3789 * @see #getLongArrayExtra(String)
3790 */
3791 public Intent putExtra(String name, long[] value) {
3792 if (mExtras == null) {
3793 mExtras = new Bundle();
3794 }
3795 mExtras.putLongArray(name, value);
3796 return this;
3797 }
3798
3799 /**
3800 * Add extended data to the intent. The name must include a package
3801 * prefix, for example the app com.android.contacts would use names
3802 * like "com.android.contacts.ShowAll".
3803 *
3804 * @param name The name of the extra data, with package prefix.
3805 * @param value The float array data value.
3806 *
3807 * @return Returns the same Intent object, for chaining multiple calls
3808 * into a single statement.
3809 *
3810 * @see #putExtras
3811 * @see #removeExtra
3812 * @see #getFloatArrayExtra(String)
3813 */
3814 public Intent putExtra(String name, float[] value) {
3815 if (mExtras == null) {
3816 mExtras = new Bundle();
3817 }
3818 mExtras.putFloatArray(name, value);
3819 return this;
3820 }
3821
3822 /**
3823 * Add extended data to the intent. The name must include a package
3824 * prefix, for example the app com.android.contacts would use names
3825 * like "com.android.contacts.ShowAll".
3826 *
3827 * @param name The name of the extra data, with package prefix.
3828 * @param value The double array data value.
3829 *
3830 * @return Returns the same Intent object, for chaining multiple calls
3831 * into a single statement.
3832 *
3833 * @see #putExtras
3834 * @see #removeExtra
3835 * @see #getDoubleArrayExtra(String)
3836 */
3837 public Intent putExtra(String name, double[] value) {
3838 if (mExtras == null) {
3839 mExtras = new Bundle();
3840 }
3841 mExtras.putDoubleArray(name, value);
3842 return this;
3843 }
3844
3845 /**
3846 * Add extended data to the intent. The name must include a package
3847 * prefix, for example the app com.android.contacts would use names
3848 * like "com.android.contacts.ShowAll".
3849 *
3850 * @param name The name of the extra data, with package prefix.
3851 * @param value The String array data value.
3852 *
3853 * @return Returns the same Intent object, for chaining multiple calls
3854 * into a single statement.
3855 *
3856 * @see #putExtras
3857 * @see #removeExtra
3858 * @see #getStringArrayExtra(String)
3859 */
3860 public Intent putExtra(String name, String[] value) {
3861 if (mExtras == null) {
3862 mExtras = new Bundle();
3863 }
3864 mExtras.putStringArray(name, value);
3865 return this;
3866 }
3867
3868 /**
3869 * Add extended data to the intent. The name must include a package
3870 * prefix, for example the app com.android.contacts would use names
3871 * like "com.android.contacts.ShowAll".
3872 *
3873 * @param name The name of the extra data, with package prefix.
3874 * @param value The Bundle data value.
3875 *
3876 * @return Returns the same Intent object, for chaining multiple calls
3877 * into a single statement.
3878 *
3879 * @see #putExtras
3880 * @see #removeExtra
3881 * @see #getBundleExtra(String)
3882 */
3883 public Intent putExtra(String name, Bundle value) {
3884 if (mExtras == null) {
3885 mExtras = new Bundle();
3886 }
3887 mExtras.putBundle(name, value);
3888 return this;
3889 }
3890
3891 /**
3892 * Add extended data to the intent. The name must include a package
3893 * prefix, for example the app com.android.contacts would use names
3894 * like "com.android.contacts.ShowAll".
3895 *
3896 * @param name The name of the extra data, with package prefix.
3897 * @param value The IBinder data value.
3898 *
3899 * @return Returns the same Intent object, for chaining multiple calls
3900 * into a single statement.
3901 *
3902 * @see #putExtras
3903 * @see #removeExtra
3904 * @see #getIBinderExtra(String)
3905 *
3906 * @deprecated
3907 * @hide
3908 */
3909 @Deprecated
3910 public Intent putExtra(String name, IBinder value) {
3911 if (mExtras == null) {
3912 mExtras = new Bundle();
3913 }
3914 mExtras.putIBinder(name, value);
3915 return this;
3916 }
3917
3918 /**
3919 * Copy all extras in 'src' in to this intent.
3920 *
3921 * @param src Contains the extras to copy.
3922 *
3923 * @see #putExtra
3924 */
3925 public Intent putExtras(Intent src) {
3926 if (src.mExtras != null) {
3927 if (mExtras == null) {
3928 mExtras = new Bundle(src.mExtras);
3929 } else {
3930 mExtras.putAll(src.mExtras);
3931 }
3932 }
3933 return this;
3934 }
3935
3936 /**
3937 * Add a set of extended data to the intent. The keys must include a package
3938 * prefix, for example the app com.android.contacts would use names
3939 * like "com.android.contacts.ShowAll".
3940 *
3941 * @param extras The Bundle of extras to add to this intent.
3942 *
3943 * @see #putExtra
3944 * @see #removeExtra
3945 */
3946 public Intent putExtras(Bundle extras) {
3947 if (mExtras == null) {
3948 mExtras = new Bundle();
3949 }
3950 mExtras.putAll(extras);
3951 return this;
3952 }
3953
3954 /**
3955 * Completely replace the extras in the Intent with the extras in the
3956 * given Intent.
The Android Open Source Project10592532009-03-18 17:39:46 -07003957 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 * @param src The exact extras contained in this Intent are copied
3959 * into the target intent, replacing any that were previously there.
3960 */
3961 public Intent replaceExtras(Intent src) {
3962 mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null;
3963 return this;
3964 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 /**
3967 * Completely replace the extras in the Intent with the given Bundle of
3968 * extras.
The Android Open Source Project10592532009-03-18 17:39:46 -07003969 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 * @param extras The new set of extras in the Intent, or null to erase
3971 * all extras.
3972 */
3973 public Intent replaceExtras(Bundle extras) {
3974 mExtras = extras != null ? new Bundle(extras) : null;
3975 return this;
3976 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978 /**
3979 * Remove extended data from the intent.
3980 *
3981 * @see #putExtra
3982 */
3983 public void removeExtra(String name) {
3984 if (mExtras != null) {
3985 mExtras.remove(name);
3986 if (mExtras.size() == 0) {
3987 mExtras = null;
3988 }
3989 }
3990 }
3991
3992 /**
3993 * Set special flags controlling how this intent is handled. Most values
3994 * here depend on the type of component being executed by the Intent,
3995 * specifically the FLAG_ACTIVITY_* flags are all for use with
3996 * {@link Context#startActivity Context.startActivity()} and the
3997 * FLAG_RECEIVER_* flags are all for use with
3998 * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
3999 *
4000 * <p>See the <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
4001 * Activities and Tasks</a> documentation for important information on how some of these options impact
4002 * the behavior of your application.
4003 *
4004 * @param flags The desired flags.
4005 *
4006 * @return Returns the same Intent object, for chaining multiple calls
4007 * into a single statement.
4008 *
4009 * @see #getFlags
4010 * @see #addFlags
4011 *
4012 * @see #FLAG_GRANT_READ_URI_PERMISSION
4013 * @see #FLAG_GRANT_WRITE_URI_PERMISSION
4014 * @see #FLAG_DEBUG_LOG_RESOLUTION
4015 * @see #FLAG_FROM_BACKGROUND
4016 * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT
4017 * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
4018 * @see #FLAG_ACTIVITY_CLEAR_TOP
4019 * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
4020 * @see #FLAG_ACTIVITY_FORWARD_RESULT
4021 * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
4022 * @see #FLAG_ACTIVITY_MULTIPLE_TASK
4023 * @see #FLAG_ACTIVITY_NEW_TASK
4024 * @see #FLAG_ACTIVITY_NO_HISTORY
4025 * @see #FLAG_ACTIVITY_NO_USER_ACTION
4026 * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP
4027 * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
4028 * @see #FLAG_ACTIVITY_SINGLE_TOP
4029 * @see #FLAG_RECEIVER_REGISTERED_ONLY
4030 */
4031 public Intent setFlags(int flags) {
4032 mFlags = flags;
4033 return this;
4034 }
4035
4036 /**
4037 * Add additional flags to the intent (or with existing flags
4038 * value).
4039 *
4040 * @param flags The new flags to set.
4041 *
4042 * @return Returns the same Intent object, for chaining multiple calls
4043 * into a single statement.
4044 *
4045 * @see #setFlags
4046 */
4047 public Intent addFlags(int flags) {
4048 mFlags |= flags;
4049 return this;
4050 }
4051
4052 /**
4053 * (Usually optional) Explicitly set the component to handle the intent.
4054 * If left with the default value of null, the system will determine the
4055 * appropriate class to use based on the other fields (action, data,
4056 * type, categories) in the Intent. If this class is defined, the
4057 * specified class will always be used regardless of the other fields. You
4058 * should only set this value when you know you absolutely want a specific
4059 * class to be used; otherwise it is better to let the system find the
4060 * appropriate class so that you will respect the installed applications
4061 * and user preferences.
4062 *
4063 * @param component The name of the application component to handle the
4064 * intent, or null to let the system find one for you.
4065 *
4066 * @return Returns the same Intent object, for chaining multiple calls
4067 * into a single statement.
4068 *
4069 * @see #setClass
4070 * @see #setClassName(Context, String)
4071 * @see #setClassName(String, String)
4072 * @see #getComponent
4073 * @see #resolveActivity
4074 */
4075 public Intent setComponent(ComponentName component) {
4076 mComponent = component;
4077 return this;
4078 }
4079
4080 /**
4081 * Convenience for calling {@link #setComponent} with an
4082 * explicit class name.
4083 *
4084 * @param packageContext A Context of the application package implementing
4085 * this class.
4086 * @param className The name of a class inside of the application package
4087 * that will be used as the component for this Intent.
4088 *
4089 * @return Returns the same Intent object, for chaining multiple calls
4090 * into a single statement.
4091 *
4092 * @see #setComponent
4093 * @see #setClass
4094 */
4095 public Intent setClassName(Context packageContext, String className) {
4096 mComponent = new ComponentName(packageContext, className);
4097 return this;
4098 }
4099
4100 /**
4101 * Convenience for calling {@link #setComponent} with an
4102 * explicit application package name and class name.
4103 *
4104 * @param packageName The name of the package implementing the desired
4105 * component.
4106 * @param className The name of a class inside of the application package
4107 * that will be used as the component for this Intent.
4108 *
4109 * @return Returns the same Intent object, for chaining multiple calls
4110 * into a single statement.
4111 *
4112 * @see #setComponent
4113 * @see #setClass
4114 */
4115 public Intent setClassName(String packageName, String className) {
4116 mComponent = new ComponentName(packageName, className);
4117 return this;
4118 }
4119
4120 /**
4121 * Convenience for calling {@link #setComponent(ComponentName)} with the
4122 * name returned by a {@link Class} object.
4123 *
4124 * @param packageContext A Context of the application package implementing
4125 * this class.
4126 * @param cls The class name to set, equivalent to
4127 * <code>setClassName(context, cls.getName())</code>.
4128 *
4129 * @return Returns the same Intent object, for chaining multiple calls
4130 * into a single statement.
4131 *
4132 * @see #setComponent
4133 */
4134 public Intent setClass(Context packageContext, Class<?> cls) {
4135 mComponent = new ComponentName(packageContext, cls);
4136 return this;
4137 }
4138
4139 /**
4140 * Use with {@link #fillIn} to allow the current action value to be
4141 * overwritten, even if it is already set.
4142 */
4143 public static final int FILL_IN_ACTION = 1<<0;
4144
4145 /**
4146 * Use with {@link #fillIn} to allow the current data or type value
4147 * overwritten, even if it is already set.
4148 */
4149 public static final int FILL_IN_DATA = 1<<1;
4150
4151 /**
4152 * Use with {@link #fillIn} to allow the current categories to be
4153 * overwritten, even if they are already set.
4154 */
4155 public static final int FILL_IN_CATEGORIES = 1<<2;
4156
4157 /**
4158 * Use with {@link #fillIn} to allow the current component value to be
4159 * overwritten, even if it is already set.
4160 */
4161 public static final int FILL_IN_COMPONENT = 1<<3;
4162
4163 /**
4164 * Copy the contents of <var>other</var> in to this object, but only
4165 * where fields are not defined by this object. For purposes of a field
4166 * being defined, the following pieces of data in the Intent are
4167 * considered to be separate fields:
4168 *
4169 * <ul>
4170 * <li> action, as set by {@link #setAction}.
4171 * <li> data URI and MIME type, as set by {@link #setData(Uri)},
4172 * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}.
4173 * <li> categories, as set by {@link #addCategory}.
4174 * <li> component, as set by {@link #setComponent(ComponentName)} or
4175 * related methods.
4176 * <li> each top-level name in the associated extras.
4177 * </ul>
4178 *
4179 * <p>In addition, you can use the {@link #FILL_IN_ACTION},
4180 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, and
4181 * {@link #FILL_IN_COMPONENT} to override the restriction where the
4182 * corresponding field will not be replaced if it is already set.
4183 *
4184 * <p>For example, consider Intent A with {data="foo", categories="bar"}
4185 * and Intent B with {action="gotit", data-type="some/thing",
4186 * categories="one","two"}.
4187 *
4188 * <p>Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now
4189 * containing: {action="gotit", data-type="some/thing",
4190 * categories="bar"}.
4191 *
4192 * @param other Another Intent whose values are to be used to fill in
4193 * the current one.
4194 * @param flags Options to control which fields can be filled in.
4195 *
4196 * @return Returns a bit mask of {@link #FILL_IN_ACTION},
4197 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, and
4198 * {@link #FILL_IN_COMPONENT} indicating which fields were changed.
4199 */
4200 public int fillIn(Intent other, int flags) {
4201 int changes = 0;
4202 if ((mAction == null && other.mAction == null)
4203 || (flags&FILL_IN_ACTION) != 0) {
4204 mAction = other.mAction;
4205 changes |= FILL_IN_ACTION;
4206 }
4207 if ((mData == null && mType == null &&
4208 (other.mData != null || other.mType != null))
4209 || (flags&FILL_IN_DATA) != 0) {
4210 mData = other.mData;
4211 mType = other.mType;
4212 changes |= FILL_IN_DATA;
4213 }
4214 if ((mCategories == null && other.mCategories == null)
4215 || (flags&FILL_IN_CATEGORIES) != 0) {
4216 if (other.mCategories != null) {
4217 mCategories = new HashSet<String>(other.mCategories);
4218 }
4219 changes |= FILL_IN_CATEGORIES;
4220 }
4221 if ((mComponent == null && other.mComponent == null)
4222 || (flags&FILL_IN_COMPONENT) != 0) {
4223 mComponent = other.mComponent;
4224 changes |= FILL_IN_COMPONENT;
4225 }
4226 mFlags |= other.mFlags;
4227 if (mExtras == null) {
4228 if (other.mExtras != null) {
4229 mExtras = new Bundle(other.mExtras);
4230 }
4231 } else if (other.mExtras != null) {
4232 try {
4233 Bundle newb = new Bundle(other.mExtras);
4234 newb.putAll(mExtras);
4235 mExtras = newb;
4236 } catch (RuntimeException e) {
4237 // Modifying the extras can cause us to unparcel the contents
4238 // of the bundle, and if we do this in the system process that
4239 // may fail. We really should handle this (i.e., the Bundle
4240 // impl shouldn't be on top of a plain map), but for now just
4241 // ignore it and keep the original contents. :(
4242 Log.w("Intent", "Failure filling in extras", e);
4243 }
4244 }
4245 return changes;
4246 }
4247
4248 /**
4249 * Wrapper class holding an Intent and implementing comparisons on it for
4250 * the purpose of filtering. The class implements its
4251 * {@link #equals equals()} and {@link #hashCode hashCode()} methods as
4252 * simple calls to {@link Intent#filterEquals(Intent)} filterEquals()} and
4253 * {@link android.content.Intent#filterHashCode()} filterHashCode()}
4254 * on the wrapped Intent.
4255 */
4256 public static final class FilterComparison {
4257 private final Intent mIntent;
4258 private final int mHashCode;
4259
4260 public FilterComparison(Intent intent) {
4261 mIntent = intent;
4262 mHashCode = intent.filterHashCode();
4263 }
4264
4265 /**
4266 * Return the Intent that this FilterComparison represents.
4267 * @return Returns the Intent held by the FilterComparison. Do
4268 * not modify!
4269 */
4270 public Intent getIntent() {
4271 return mIntent;
4272 }
4273
4274 @Override
4275 public boolean equals(Object obj) {
4276 if (obj instanceof FilterComparison) {
4277 Intent other = ((FilterComparison)obj).mIntent;
4278 return mIntent.filterEquals(other);
4279 }
4280 return false;
4281 }
4282
4283 @Override
4284 public int hashCode() {
4285 return mHashCode;
4286 }
4287 }
4288
4289 /**
4290 * Determine if two intents are the same for the purposes of intent
4291 * resolution (filtering). That is, if their action, data, type,
4292 * class, and categories are the same. This does <em>not</em> compare
4293 * any extra data included in the intents.
4294 *
4295 * @param other The other Intent to compare against.
4296 *
4297 * @return Returns true if action, data, type, class, and categories
4298 * are the same.
4299 */
4300 public boolean filterEquals(Intent other) {
4301 if (other == null) {
4302 return false;
4303 }
4304 if (mAction != other.mAction) {
4305 if (mAction != null) {
4306 if (!mAction.equals(other.mAction)) {
4307 return false;
4308 }
4309 } else {
4310 if (!other.mAction.equals(mAction)) {
4311 return false;
4312 }
4313 }
4314 }
4315 if (mData != other.mData) {
4316 if (mData != null) {
4317 if (!mData.equals(other.mData)) {
4318 return false;
4319 }
4320 } else {
4321 if (!other.mData.equals(mData)) {
4322 return false;
4323 }
4324 }
4325 }
4326 if (mType != other.mType) {
4327 if (mType != null) {
4328 if (!mType.equals(other.mType)) {
4329 return false;
4330 }
4331 } else {
4332 if (!other.mType.equals(mType)) {
4333 return false;
4334 }
4335 }
4336 }
4337 if (mComponent != other.mComponent) {
4338 if (mComponent != null) {
4339 if (!mComponent.equals(other.mComponent)) {
4340 return false;
4341 }
4342 } else {
4343 if (!other.mComponent.equals(mComponent)) {
4344 return false;
4345 }
4346 }
4347 }
4348 if (mCategories != other.mCategories) {
4349 if (mCategories != null) {
4350 if (!mCategories.equals(other.mCategories)) {
4351 return false;
4352 }
4353 } else {
4354 if (!other.mCategories.equals(mCategories)) {
4355 return false;
4356 }
4357 }
4358 }
4359
4360 return true;
4361 }
4362
4363 /**
4364 * Generate hash code that matches semantics of filterEquals().
4365 *
4366 * @return Returns the hash value of the action, data, type, class, and
4367 * categories.
4368 *
4369 * @see #filterEquals
4370 */
4371 public int filterHashCode() {
4372 int code = 0;
4373 if (mAction != null) {
4374 code += mAction.hashCode();
4375 }
4376 if (mData != null) {
4377 code += mData.hashCode();
4378 }
4379 if (mType != null) {
4380 code += mType.hashCode();
4381 }
4382 if (mComponent != null) {
4383 code += mComponent.hashCode();
4384 }
4385 if (mCategories != null) {
4386 code += mCategories.hashCode();
4387 }
4388 return code;
4389 }
4390
4391 @Override
4392 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004393 StringBuilder b = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004395 b.append("Intent { ");
4396 toShortString(b, true, true);
4397 b.append(" }");
4398
4399 return b.toString();
4400 }
4401
4402 /** @hide */
4403 public String toShortString(boolean comp, boolean extras) {
4404 StringBuilder b = new StringBuilder(128);
4405 toShortString(b, comp, extras);
4406 return b.toString();
4407 }
4408
4409 /** @hide */
4410 public void toShortString(StringBuilder b, boolean comp, boolean extras) {
4411 boolean first = true;
4412 if (mAction != null) {
4413 b.append("act=").append(mAction);
4414 first = false;
4415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 if (mCategories != null) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004417 if (!first) {
4418 b.append(' ');
4419 }
4420 first = false;
4421 b.append("cat=[");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004422 Iterator<String> i = mCategories.iterator();
4423 boolean didone = false;
4424 while (i.hasNext()) {
4425 if (didone) b.append(",");
4426 didone = true;
4427 b.append(i.next());
4428 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004429 b.append("]");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004430 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004431 if (mData != null) {
4432 if (!first) {
4433 b.append(' ');
4434 }
4435 first = false;
4436 b.append("dat=").append(mData);
4437 }
4438 if (mType != null) {
4439 if (!first) {
4440 b.append(' ');
4441 }
4442 first = false;
4443 b.append("typ=").append(mType);
4444 }
4445 if (mFlags != 0) {
4446 if (!first) {
4447 b.append(' ');
4448 }
4449 first = false;
4450 b.append("flg=0x").append(Integer.toHexString(mFlags));
4451 }
4452 if (comp && mComponent != null) {
4453 if (!first) {
4454 b.append(' ');
4455 }
4456 first = false;
4457 b.append("cmp=").append(mComponent.flattenToShortString());
4458 }
4459 if (extras && mExtras != null) {
4460 if (!first) {
4461 b.append(' ');
4462 }
4463 first = false;
4464 b.append("(has extras)");
4465 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 }
4467
4468 public String toURI() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004469 StringBuilder uri = new StringBuilder(128);
4470 if (mData != null) uri.append(mData.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471
4472 uri.append("#Intent;");
4473
4474 if (mAction != null) {
4475 uri.append("action=").append(mAction).append(';');
4476 }
4477 if (mCategories != null) {
4478 for (String category : mCategories) {
4479 uri.append("category=").append(category).append(';');
4480 }
4481 }
4482 if (mType != null) {
4483 uri.append("type=").append(mType).append(';');
4484 }
4485 if (mFlags != 0) {
4486 uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
4487 }
4488 if (mComponent != null) {
4489 uri.append("component=").append(mComponent.flattenToShortString()).append(';');
4490 }
4491 if (mExtras != null) {
4492 for (String key : mExtras.keySet()) {
4493 final Object value = mExtras.get(key);
4494 char entryType =
4495 value instanceof String ? 'S' :
4496 value instanceof Boolean ? 'B' :
4497 value instanceof Byte ? 'b' :
4498 value instanceof Character ? 'c' :
4499 value instanceof Double ? 'd' :
4500 value instanceof Float ? 'f' :
4501 value instanceof Integer ? 'i' :
4502 value instanceof Long ? 'l' :
4503 value instanceof Short ? 's' :
4504 '\0';
4505
4506 if (entryType != '\0') {
4507 uri.append(entryType);
4508 uri.append('.');
4509 uri.append(Uri.encode(key));
4510 uri.append('=');
4511 uri.append(Uri.encode(value.toString()));
4512 uri.append(';');
4513 }
4514 }
4515 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 uri.append("end");
4518
4519 return uri.toString();
4520 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 public int describeContents() {
4523 return (mExtras != null) ? mExtras.describeContents() : 0;
4524 }
4525
4526 public void writeToParcel(Parcel out, int flags) {
4527 out.writeString(mAction);
4528 Uri.writeToParcel(out, mData);
4529 out.writeString(mType);
4530 out.writeInt(mFlags);
4531 ComponentName.writeToParcel(mComponent, out);
4532
4533 if (mCategories != null) {
4534 out.writeInt(mCategories.size());
4535 for (String category : mCategories) {
4536 out.writeString(category);
4537 }
4538 } else {
4539 out.writeInt(0);
4540 }
4541
4542 out.writeBundle(mExtras);
4543 }
4544
4545 public static final Parcelable.Creator<Intent> CREATOR
4546 = new Parcelable.Creator<Intent>() {
4547 public Intent createFromParcel(Parcel in) {
4548 return new Intent(in);
4549 }
4550 public Intent[] newArray(int size) {
4551 return new Intent[size];
4552 }
4553 };
4554
4555 private Intent(Parcel in) {
4556 readFromParcel(in);
4557 }
4558
4559 public void readFromParcel(Parcel in) {
4560 mAction = in.readString();
4561 mData = Uri.CREATOR.createFromParcel(in);
4562 mType = in.readString();
4563 mFlags = in.readInt();
4564 mComponent = ComponentName.readFromParcel(in);
4565
4566 int N = in.readInt();
4567 if (N > 0) {
4568 mCategories = new HashSet<String>();
4569 int i;
4570 for (i=0; i<N; i++) {
4571 mCategories.add(in.readString());
4572 }
4573 } else {
4574 mCategories = null;
4575 }
4576
4577 mExtras = in.readBundle();
4578 }
4579
4580 /**
4581 * Parses the "intent" element (and its children) from XML and instantiates
4582 * an Intent object. The given XML parser should be located at the tag
4583 * where parsing should start (often named "intent"), from which the
4584 * basic action, data, type, and package and class name will be
4585 * retrieved. The function will then parse in to any child elements,
4586 * looking for <category android:name="xxx"> tags to add categories and
4587 * <extra android:name="xxx" android:value="yyy"> to attach extra data
4588 * to the intent.
4589 *
4590 * @param resources The Resources to use when inflating resources.
4591 * @param parser The XML parser pointing at an "intent" tag.
4592 * @param attrs The AttributeSet interface for retrieving extended
4593 * attribute data at the current <var>parser</var> location.
4594 * @return An Intent object matching the XML data.
4595 * @throws XmlPullParserException If there was an XML parsing error.
4596 * @throws IOException If there was an I/O error.
4597 */
4598 public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
4599 throws XmlPullParserException, IOException {
4600 Intent intent = new Intent();
4601
4602 TypedArray sa = resources.obtainAttributes(attrs,
4603 com.android.internal.R.styleable.Intent);
4604
4605 intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action));
4606
4607 String data = sa.getString(com.android.internal.R.styleable.Intent_data);
4608 String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType);
4609 intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType);
4610
4611 String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage);
4612 String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass);
4613 if (packageName != null && className != null) {
4614 intent.setComponent(new ComponentName(packageName, className));
4615 }
4616
4617 sa.recycle();
4618
4619 int outerDepth = parser.getDepth();
4620 int type;
4621 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
4622 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
4623 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
4624 continue;
4625 }
4626
4627 String nodeName = parser.getName();
4628 if (nodeName.equals("category")) {
4629 sa = resources.obtainAttributes(attrs,
4630 com.android.internal.R.styleable.IntentCategory);
4631 String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name);
4632 sa.recycle();
4633
4634 if (cat != null) {
4635 intent.addCategory(cat);
4636 }
4637 XmlUtils.skipCurrentTag(parser);
4638
4639 } else if (nodeName.equals("extra")) {
4640 if (intent.mExtras == null) {
4641 intent.mExtras = new Bundle();
4642 }
4643 resources.parseBundleExtra("extra", attrs, intent.mExtras);
4644 XmlUtils.skipCurrentTag(parser);
4645
4646 } else {
4647 XmlUtils.skipCurrentTag(parser);
4648 }
4649 }
4650
4651 return intent;
4652 }
4653}