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