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