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