Intent.java revision 1c29700c5fe261f6829d95f22bd8c1fe6daf362e
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.graphics.Rect;
30import android.net.Uri;
31import android.os.Bundle;
32import android.os.IBinder;
33import android.os.Parcel;
34import android.os.Parcelable;
35import android.util.AttributeSet;
36import android.util.Log;
37
38import com.android.internal.util.XmlUtils;
39
40import java.io.IOException;
41import java.io.Serializable;
42import java.net.URISyntaxException;
43import java.util.ArrayList;
44import java.util.HashSet;
45import java.util.Iterator;
46import java.util.Locale;
47import java.util.Set;
48
49/**
50 * An intent is an abstract description of an operation to be performed.  It
51 * can be used with {@link Context#startActivity(Intent) startActivity} to
52 * launch an {@link android.app.Activity},
53 * {@link android.content.Context#sendBroadcast(Intent) broadcastIntent} to
54 * send it to any interested {@link BroadcastReceiver BroadcastReceiver} components,
55 * and {@link android.content.Context#startService} or
56 * {@link android.content.Context#bindService} to communicate with a
57 * background {@link android.app.Service}.
58 *
59 * <p>An Intent provides a facility for performing late runtime binding between the code in
60 * different applications. Its most significant use is in the launching of activities, where it
61 * can be thought of as the glue between activities. It is basically a passive data structure
62 * holding an abstract description of an action to be performed.</p>
63 *
64 * <div class="special reference">
65 * <h3>Developer Guides</h3>
66 * <p>For information about how to create and resolve intents, read the
67 * <a href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and Intent Filters</a>
68 * developer guide.</p>
69 * </div>
70 *
71 * <a name="IntentStructure"></a>
72 * <h3>Intent Structure</h3>
73 * <p>The primary pieces of information in an intent are:</p>
74 *
75 * <ul>
76 *   <li> <p><b>action</b> -- The general action to be performed, such as
77 *     {@link #ACTION_VIEW}, {@link #ACTION_EDIT}, {@link #ACTION_MAIN},
78 *     etc.</p>
79 *   </li>
80 *   <li> <p><b>data</b> -- The data to operate on, such as a person record
81 *     in the contacts database, expressed as a {@link android.net.Uri}.</p>
82 *   </li>
83 * </ul>
84 *
85 *
86 * <p>Some examples of action/data pairs are:</p>
87 *
88 * <ul>
89 *   <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/1</i></b> -- Display
90 *     information about the person whose identifier is "1".</p>
91 *   </li>
92 *   <li> <p><b>{@link #ACTION_DIAL} <i>content://contacts/people/1</i></b> -- Display
93 *     the phone dialer with the person filled in.</p>
94 *   </li>
95 *   <li> <p><b>{@link #ACTION_VIEW} <i>tel:123</i></b> -- Display
96 *     the phone dialer with the given number filled in.  Note how the
97 *     VIEW action does what what is considered the most reasonable thing for
98 *     a particular URI.</p>
99 *   </li>
100 *   <li> <p><b>{@link #ACTION_DIAL} <i>tel:123</i></b> -- Display
101 *     the phone dialer with the given number filled in.</p>
102 *   </li>
103 *   <li> <p><b>{@link #ACTION_EDIT} <i>content://contacts/people/1</i></b> -- Edit
104 *     information about the person whose identifier is "1".</p>
105 *   </li>
106 *   <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/</i></b> -- Display
107 *     a list of people, which the user can browse through.  This example is a
108 *     typical top-level entry into the Contacts application, showing you the
109 *     list of people. Selecting a particular person to view would result in a
110 *     new intent { <b>{@link #ACTION_VIEW} <i>content://contacts/N</i></b> }
111 *     being used to start an activity to display that person.</p>
112 *   </li>
113 * </ul>
114 *
115 * <p>In addition to these primary attributes, there are a number of secondary
116 * attributes that you can also include with an intent:</p>
117 *
118 * <ul>
119 *     <li> <p><b>category</b> -- Gives additional information about the action
120 *         to execute.  For example, {@link #CATEGORY_LAUNCHER} means it should
121 *         appear in the Launcher as a top-level application, while
122 *         {@link #CATEGORY_ALTERNATIVE} means it should be included in a list
123 *         of alternative actions the user can perform on a piece of data.</p>
124 *     <li> <p><b>type</b> -- Specifies an explicit type (a MIME type) of the
125 *         intent data.  Normally the type is inferred from the data itself.
126 *         By setting this attribute, you disable that evaluation and force
127 *         an explicit type.</p>
128 *     <li> <p><b>component</b> -- Specifies an explicit name of a component
129 *         class to use for the intent.  Normally this is determined by looking
130 *         at the other information in the intent (the action, data/type, and
131 *         categories) and matching that with a component that can handle it.
132 *         If this attribute is set then none of the evaluation is performed,
133 *         and this component is used exactly as is.  By specifying this attribute,
134 *         all of the other Intent attributes become optional.</p>
135 *     <li> <p><b>extras</b> -- This is a {@link Bundle} of any additional information.
136 *         This can be used to provide extended information to the component.
137 *         For example, if we have a action to send an e-mail message, we could
138 *         also include extra pieces of data here to supply a subject, body,
139 *         etc.</p>
140 * </ul>
141 *
142 * <p>Here are some examples of other operations you can specify as intents
143 * using these additional parameters:</p>
144 *
145 * <ul>
146 *   <li> <p><b>{@link #ACTION_MAIN} with category {@link #CATEGORY_HOME}</b> --
147 *     Launch the home screen.</p>
148 *   </li>
149 *   <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
150 *     <i>{@link android.provider.Contacts.Phones#CONTENT_URI
151 *     vnd.android.cursor.item/phone}</i></b>
152 *     -- Display the list of people's phone numbers, allowing the user to
153 *     browse through them and pick one and return it to the parent activity.</p>
154 *   </li>
155 *   <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
156 *     <i>*{@literal /}*</i> and category {@link #CATEGORY_OPENABLE}</b>
157 *     -- Display all pickers for data that can be opened with
158 *     {@link ContentResolver#openInputStream(Uri) ContentResolver.openInputStream()},
159 *     allowing the user to pick one of them and then some data inside of it
160 *     and returning the resulting URI to the caller.  This can be used,
161 *     for example, in an e-mail application to allow the user to pick some
162 *     data to include as an attachment.</p>
163 *   </li>
164 * </ul>
165 *
166 * <p>There are a variety of standard Intent action and category constants
167 * defined in the Intent class, but applications can also define their own.
168 * These strings use java style scoping, to ensure they are unique -- for
169 * example, the standard {@link #ACTION_VIEW} is called
170 * "android.intent.action.VIEW".</p>
171 *
172 * <p>Put together, the set of actions, data types, categories, and extra data
173 * defines a language for the system allowing for the expression of phrases
174 * such as "call john smith's cell".  As applications are added to the system,
175 * they can extend this language by adding new actions, types, and categories, or
176 * they can modify the behavior of existing phrases by supplying their own
177 * activities that handle them.</p>
178 *
179 * <a name="IntentResolution"></a>
180 * <h3>Intent Resolution</h3>
181 *
182 * <p>There are two primary forms of intents you will use.
183 *
184 * <ul>
185 *     <li> <p><b>Explicit Intents</b> have specified a component (via
186 *     {@link #setComponent} or {@link #setClass}), which provides the exact
187 *     class to be run.  Often these will not include any other information,
188 *     simply being a way for an application to launch various internal
189 *     activities it has as the user interacts with the application.
190 *
191 *     <li> <p><b>Implicit Intents</b> have not specified a component;
192 *     instead, they must include enough information for the system to
193 *     determine which of the available components is best to run for that
194 *     intent.
195 * </ul>
196 *
197 * <p>When using implicit intents, given such an arbitrary intent we need to
198 * know what to do with it. This is handled by the process of <em>Intent
199 * resolution</em>, which maps an Intent to an {@link android.app.Activity},
200 * {@link BroadcastReceiver}, or {@link android.app.Service} (or sometimes two or
201 * more activities/receivers) that can handle it.</p>
202 *
203 * <p>The intent resolution mechanism basically revolves around matching an
204 * Intent against all of the &lt;intent-filter&gt; descriptions in the
205 * installed application packages.  (Plus, in the case of broadcasts, any {@link BroadcastReceiver}
206 * objects explicitly registered with {@link Context#registerReceiver}.)  More
207 * details on this can be found in the documentation on the {@link
208 * IntentFilter} class.</p>
209 *
210 * <p>There are three pieces of information in the Intent that are used for
211 * resolution: the action, type, and category.  Using this information, a query
212 * is done on the {@link PackageManager} for a component that can handle the
213 * intent. The appropriate component is determined based on the intent
214 * information supplied in the <code>AndroidManifest.xml</code> file as
215 * follows:</p>
216 *
217 * <ul>
218 *     <li> <p>The <b>action</b>, if given, must be listed by the component as
219 *         one it handles.</p>
220 *     <li> <p>The <b>type</b> is retrieved from the Intent's data, if not
221 *         already supplied in the Intent.  Like the action, if a type is
222 *         included in the intent (either explicitly or implicitly in its
223 *         data), then this must be listed by the component as one it handles.</p>
224 *     <li> For data that is not a <code>content:</code> URI and where no explicit
225 *         type is included in the Intent, instead the <b>scheme</b> of the
226 *         intent data (such as <code>http:</code> or <code>mailto:</code>) is
227 *         considered. Again like the action, if we are matching a scheme it
228 *         must be listed by the component as one it can handle.
229 *     <li> <p>The <b>categories</b>, if supplied, must <em>all</em> be listed
230 *         by the activity as categories it handles.  That is, if you include
231 *         the categories {@link #CATEGORY_LAUNCHER} and
232 *         {@link #CATEGORY_ALTERNATIVE}, then you will only resolve to components
233 *         with an intent that lists <em>both</em> of those categories.
234 *         Activities will very often need to support the
235 *         {@link #CATEGORY_DEFAULT} so that they can be found by
236 *         {@link Context#startActivity Context.startActivity()}.</p>
237 * </ul>
238 *
239 * <p>For example, consider the Note Pad sample application that
240 * allows user to browse through a list of notes data and view details about
241 * individual items.  Text in italics indicate places were you would replace a
242 * name with one specific to your own package.</p>
243 *
244 * <pre> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
245 *       package="<i>com.android.notepad</i>"&gt;
246 *     &lt;application android:icon="@drawable/app_notes"
247 *             android:label="@string/app_name"&gt;
248 *
249 *         &lt;provider class=".NotePadProvider"
250 *                 android:authorities="<i>com.google.provider.NotePad</i>" /&gt;
251 *
252 *         &lt;activity class=".NotesList" android:label="@string/title_notes_list"&gt;
253 *             &lt;intent-filter&gt;
254 *                 &lt;action android:name="android.intent.action.MAIN" /&gt;
255 *                 &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
256 *             &lt;/intent-filter&gt;
257 *             &lt;intent-filter&gt;
258 *                 &lt;action android:name="android.intent.action.VIEW" /&gt;
259 *                 &lt;action android:name="android.intent.action.EDIT" /&gt;
260 *                 &lt;action android:name="android.intent.action.PICK" /&gt;
261 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
262 *                 &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
263 *             &lt;/intent-filter&gt;
264 *             &lt;intent-filter&gt;
265 *                 &lt;action android:name="android.intent.action.GET_CONTENT" /&gt;
266 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
267 *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
268 *             &lt;/intent-filter&gt;
269 *         &lt;/activity&gt;
270 *
271 *         &lt;activity class=".NoteEditor" android:label="@string/title_note"&gt;
272 *             &lt;intent-filter android:label="@string/resolve_edit"&gt;
273 *                 &lt;action android:name="android.intent.action.VIEW" /&gt;
274 *                 &lt;action android:name="android.intent.action.EDIT" /&gt;
275 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
276 *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
277 *             &lt;/intent-filter&gt;
278 *
279 *             &lt;intent-filter&gt;
280 *                 &lt;action android:name="android.intent.action.INSERT" /&gt;
281 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
282 *                 &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
283 *             &lt;/intent-filter&gt;
284 *
285 *         &lt;/activity&gt;
286 *
287 *         &lt;activity class=".TitleEditor" android:label="@string/title_edit_title"
288 *                 android:theme="@android:style/Theme.Dialog"&gt;
289 *             &lt;intent-filter android:label="@string/resolve_title"&gt;
290 *                 &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
291 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
292 *                 &lt;category android:name="android.intent.category.ALTERNATIVE" /&gt;
293 *                 &lt;category android:name="android.intent.category.SELECTED_ALTERNATIVE" /&gt;
294 *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
295 *             &lt;/intent-filter&gt;
296 *         &lt;/activity&gt;
297 *
298 *     &lt;/application&gt;
299 * &lt;/manifest&gt;</pre>
300 *
301 * <p>The first activity,
302 * <code>com.android.notepad.NotesList</code>, serves as our main
303 * entry into the app.  It can do three things as described by its three intent
304 * templates:
305 * <ol>
306 * <li><pre>
307 * &lt;intent-filter&gt;
308 *     &lt;action android:name="{@link #ACTION_MAIN android.intent.action.MAIN}" /&gt;
309 *     &lt;category android:name="{@link #CATEGORY_LAUNCHER android.intent.category.LAUNCHER}" /&gt;
310 * &lt;/intent-filter&gt;</pre>
311 * <p>This provides a top-level entry into the NotePad application: the standard
312 * MAIN action is a main entry point (not requiring any other information in
313 * the Intent), and the LAUNCHER category says that this entry point should be
314 * listed in the application launcher.</p>
315 * <li><pre>
316 * &lt;intent-filter&gt;
317 *     &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
318 *     &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
319 *     &lt;action android:name="{@link #ACTION_PICK android.intent.action.PICK}" /&gt;
320 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
321 *     &lt;data mimeType:name="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
322 * &lt;/intent-filter&gt;</pre>
323 * <p>This declares the things that the activity can do on a directory of
324 * notes.  The type being supported is given with the &lt;type&gt; tag, where
325 * <code>vnd.android.cursor.dir/vnd.google.note</code> is a URI from which
326 * a Cursor of zero or more items (<code>vnd.android.cursor.dir</code>) can
327 * be retrieved which holds our note pad data (<code>vnd.google.note</code>).
328 * The activity allows the user to view or edit the directory of data (via
329 * the VIEW and EDIT actions), or to pick a particular note and return it
330 * to the caller (via the PICK action).  Note also the DEFAULT category
331 * supplied here: this is <em>required</em> for the
332 * {@link Context#startActivity Context.startActivity} method to resolve your
333 * activity when its component name is not explicitly specified.</p>
334 * <li><pre>
335 * &lt;intent-filter&gt;
336 *     &lt;action android:name="{@link #ACTION_GET_CONTENT android.intent.action.GET_CONTENT}" /&gt;
337 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
338 *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
339 * &lt;/intent-filter&gt;</pre>
340 * <p>This filter describes the ability return to the caller a note selected by
341 * the user without needing to know where it came from.  The data type
342 * <code>vnd.android.cursor.item/vnd.google.note</code> is a URI from which
343 * a Cursor of exactly one (<code>vnd.android.cursor.item</code>) item can
344 * be retrieved which contains our note pad data (<code>vnd.google.note</code>).
345 * The GET_CONTENT action is similar to the PICK action, where the activity
346 * will return to its caller a piece of data selected by the user.  Here,
347 * however, the caller specifies the type of data they desire instead of
348 * the type of data the user will be picking from.</p>
349 * </ol>
350 *
351 * <p>Given these capabilities, the following intents will resolve to the
352 * NotesList activity:</p>
353 *
354 * <ul>
355 *     <li> <p><b>{ action=android.app.action.MAIN }</b> matches all of the
356 *         activities that can be used as top-level entry points into an
357 *         application.</p>
358 *     <li> <p><b>{ action=android.app.action.MAIN,
359 *         category=android.app.category.LAUNCHER }</b> is the actual intent
360 *         used by the Launcher to populate its top-level list.</p>
361 *     <li> <p><b>{ action=android.intent.action.VIEW
362 *          data=content://com.google.provider.NotePad/notes }</b>
363 *         displays a list of all the notes under
364 *         "content://com.google.provider.NotePad/notes", which
365 *         the user can browse through and see the details on.</p>
366 *     <li> <p><b>{ action=android.app.action.PICK
367 *          data=content://com.google.provider.NotePad/notes }</b>
368 *         provides a list of the notes under
369 *         "content://com.google.provider.NotePad/notes", from which
370 *         the user can pick a note whose data URL is returned back to the caller.</p>
371 *     <li> <p><b>{ action=android.app.action.GET_CONTENT
372 *          type=vnd.android.cursor.item/vnd.google.note }</b>
373 *         is similar to the pick action, but allows the caller to specify the
374 *         kind of data they want back so that the system can find the appropriate
375 *         activity to pick something of that data type.</p>
376 * </ul>
377 *
378 * <p>The second activity,
379 * <code>com.android.notepad.NoteEditor</code>, shows the user a single
380 * note entry and allows them to edit it.  It can do two things as described
381 * by its two intent templates:
382 * <ol>
383 * <li><pre>
384 * &lt;intent-filter android:label="@string/resolve_edit"&gt;
385 *     &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
386 *     &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
387 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
388 *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
389 * &lt;/intent-filter&gt;</pre>
390 * <p>The first, primary, purpose of this activity is to let the user interact
391 * with a single note, as decribed by the MIME type
392 * <code>vnd.android.cursor.item/vnd.google.note</code>.  The activity can
393 * either VIEW a note or allow the user to EDIT it.  Again we support the
394 * DEFAULT category to allow the activity to be launched without explicitly
395 * specifying its component.</p>
396 * <li><pre>
397 * &lt;intent-filter&gt;
398 *     &lt;action android:name="{@link #ACTION_INSERT android.intent.action.INSERT}" /&gt;
399 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
400 *     &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
401 * &lt;/intent-filter&gt;</pre>
402 * <p>The secondary use of this activity is to insert a new note entry into
403 * an existing directory of notes.  This is used when the user creates a new
404 * note: the INSERT action is executed on the directory of notes, causing
405 * this activity to run and have the user create the new note data which
406 * it then adds to the content provider.</p>
407 * </ol>
408 *
409 * <p>Given these capabilities, the following intents will resolve to the
410 * NoteEditor activity:</p>
411 *
412 * <ul>
413 *     <li> <p><b>{ action=android.intent.action.VIEW
414 *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
415 *         shows the user the content of note <var>{ID}</var>.</p>
416 *     <li> <p><b>{ action=android.app.action.EDIT
417 *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
418 *         allows the user to edit the content of note <var>{ID}</var>.</p>
419 *     <li> <p><b>{ action=android.app.action.INSERT
420 *          data=content://com.google.provider.NotePad/notes }</b>
421 *         creates a new, empty note in the notes list at
422 *         "content://com.google.provider.NotePad/notes"
423 *         and allows the user to edit it.  If they keep their changes, the URI
424 *         of the newly created note is returned to the caller.</p>
425 * </ul>
426 *
427 * <p>The last activity,
428 * <code>com.android.notepad.TitleEditor</code>, allows the user to
429 * edit the title of a note.  This could be implemented as a class that the
430 * application directly invokes (by explicitly setting its component in
431 * the Intent), but here we show a way you can publish alternative
432 * operations on existing data:</p>
433 *
434 * <pre>
435 * &lt;intent-filter android:label="@string/resolve_title"&gt;
436 *     &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
437 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
438 *     &lt;category android:name="{@link #CATEGORY_ALTERNATIVE android.intent.category.ALTERNATIVE}" /&gt;
439 *     &lt;category android:name="{@link #CATEGORY_SELECTED_ALTERNATIVE android.intent.category.SELECTED_ALTERNATIVE}" /&gt;
440 *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
441 * &lt;/intent-filter&gt;</pre>
442 *
443 * <p>In the single intent template here, we
444 * have created our own private action called
445 * <code>com.android.notepad.action.EDIT_TITLE</code> which means to
446 * edit the title of a note.  It must be invoked on a specific note
447 * (data type <code>vnd.android.cursor.item/vnd.google.note</code>) like the previous
448 * view and edit actions, but here displays and edits the title contained
449 * in the note data.
450 *
451 * <p>In addition to supporting the default category as usual, our title editor
452 * also supports two other standard categories: ALTERNATIVE and
453 * SELECTED_ALTERNATIVE.  Implementing
454 * these categories allows others to find the special action it provides
455 * without directly knowing about it, through the
456 * {@link android.content.pm.PackageManager#queryIntentActivityOptions} method, or
457 * more often to build dynamic menu items with
458 * {@link android.view.Menu#addIntentOptions}.  Note that in the intent
459 * template here was also supply an explicit name for the template
460 * (via <code>android:label="@string/resolve_title"</code>) to better control
461 * what the user sees when presented with this activity as an alternative
462 * action to the data they are viewing.
463 *
464 * <p>Given these capabilities, the following intent will resolve to the
465 * TitleEditor activity:</p>
466 *
467 * <ul>
468 *     <li> <p><b>{ action=com.android.notepad.action.EDIT_TITLE
469 *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
470 *         displays and allows the user to edit the title associated
471 *         with note <var>{ID}</var>.</p>
472 * </ul>
473 *
474 * <h3>Standard Activity Actions</h3>
475 *
476 * <p>These are the current standard actions that Intent defines for launching
477 * activities (usually through {@link Context#startActivity}.  The most
478 * important, and by far most frequently used, are {@link #ACTION_MAIN} and
479 * {@link #ACTION_EDIT}.
480 *
481 * <ul>
482 *     <li> {@link #ACTION_MAIN}
483 *     <li> {@link #ACTION_VIEW}
484 *     <li> {@link #ACTION_ATTACH_DATA}
485 *     <li> {@link #ACTION_EDIT}
486 *     <li> {@link #ACTION_PICK}
487 *     <li> {@link #ACTION_CHOOSER}
488 *     <li> {@link #ACTION_GET_CONTENT}
489 *     <li> {@link #ACTION_DIAL}
490 *     <li> {@link #ACTION_CALL}
491 *     <li> {@link #ACTION_SEND}
492 *     <li> {@link #ACTION_SENDTO}
493 *     <li> {@link #ACTION_ANSWER}
494 *     <li> {@link #ACTION_INSERT}
495 *     <li> {@link #ACTION_DELETE}
496 *     <li> {@link #ACTION_RUN}
497 *     <li> {@link #ACTION_SYNC}
498 *     <li> {@link #ACTION_PICK_ACTIVITY}
499 *     <li> {@link #ACTION_SEARCH}
500 *     <li> {@link #ACTION_WEB_SEARCH}
501 *     <li> {@link #ACTION_FACTORY_TEST}
502 * </ul>
503 *
504 * <h3>Standard Broadcast Actions</h3>
505 *
506 * <p>These are the current standard actions that Intent defines for receiving
507 * broadcasts (usually through {@link Context#registerReceiver} or a
508 * &lt;receiver&gt; tag in a manifest).
509 *
510 * <ul>
511 *     <li> {@link #ACTION_TIME_TICK}
512 *     <li> {@link #ACTION_TIME_CHANGED}
513 *     <li> {@link #ACTION_TIMEZONE_CHANGED}
514 *     <li> {@link #ACTION_BOOT_COMPLETED}
515 *     <li> {@link #ACTION_PACKAGE_ADDED}
516 *     <li> {@link #ACTION_PACKAGE_CHANGED}
517 *     <li> {@link #ACTION_PACKAGE_REMOVED}
518 *     <li> {@link #ACTION_PACKAGE_RESTARTED}
519 *     <li> {@link #ACTION_PACKAGE_DATA_CLEARED}
520 *     <li> {@link #ACTION_UID_REMOVED}
521 *     <li> {@link #ACTION_BATTERY_CHANGED}
522 *     <li> {@link #ACTION_POWER_CONNECTED}
523 *     <li> {@link #ACTION_POWER_DISCONNECTED}
524 *     <li> {@link #ACTION_SHUTDOWN}
525 * </ul>
526 *
527 * <h3>Standard Categories</h3>
528 *
529 * <p>These are the current standard categories that can be used to further
530 * clarify an Intent via {@link #addCategory}.
531 *
532 * <ul>
533 *     <li> {@link #CATEGORY_DEFAULT}
534 *     <li> {@link #CATEGORY_BROWSABLE}
535 *     <li> {@link #CATEGORY_TAB}
536 *     <li> {@link #CATEGORY_ALTERNATIVE}
537 *     <li> {@link #CATEGORY_SELECTED_ALTERNATIVE}
538 *     <li> {@link #CATEGORY_LAUNCHER}
539 *     <li> {@link #CATEGORY_INFO}
540 *     <li> {@link #CATEGORY_HOME}
541 *     <li> {@link #CATEGORY_PREFERENCE}
542 *     <li> {@link #CATEGORY_TEST}
543 *     <li> {@link #CATEGORY_CAR_DOCK}
544 *     <li> {@link #CATEGORY_DESK_DOCK}
545 *     <li> {@link #CATEGORY_LE_DESK_DOCK}
546 *     <li> {@link #CATEGORY_HE_DESK_DOCK}
547 *     <li> {@link #CATEGORY_CAR_MODE}
548 *     <li> {@link #CATEGORY_APP_MARKET}
549 * </ul>
550 *
551 * <h3>Standard Extra Data</h3>
552 *
553 * <p>These are the current standard fields that can be used as extra data via
554 * {@link #putExtra}.
555 *
556 * <ul>
557 *     <li> {@link #EXTRA_ALARM_COUNT}
558 *     <li> {@link #EXTRA_BCC}
559 *     <li> {@link #EXTRA_CC}
560 *     <li> {@link #EXTRA_CHANGED_COMPONENT_NAME}
561 *     <li> {@link #EXTRA_DATA_REMOVED}
562 *     <li> {@link #EXTRA_DOCK_STATE}
563 *     <li> {@link #EXTRA_DOCK_STATE_HE_DESK}
564 *     <li> {@link #EXTRA_DOCK_STATE_LE_DESK}
565 *     <li> {@link #EXTRA_DOCK_STATE_CAR}
566 *     <li> {@link #EXTRA_DOCK_STATE_DESK}
567 *     <li> {@link #EXTRA_DOCK_STATE_UNDOCKED}
568 *     <li> {@link #EXTRA_DONT_KILL_APP}
569 *     <li> {@link #EXTRA_EMAIL}
570 *     <li> {@link #EXTRA_INITIAL_INTENTS}
571 *     <li> {@link #EXTRA_INTENT}
572 *     <li> {@link #EXTRA_KEY_EVENT}
573 *     <li> {@link #EXTRA_PHONE_NUMBER}
574 *     <li> {@link #EXTRA_REMOTE_INTENT_TOKEN}
575 *     <li> {@link #EXTRA_REPLACING}
576 *     <li> {@link #EXTRA_SHORTCUT_ICON}
577 *     <li> {@link #EXTRA_SHORTCUT_ICON_RESOURCE}
578 *     <li> {@link #EXTRA_SHORTCUT_INTENT}
579 *     <li> {@link #EXTRA_STREAM}
580 *     <li> {@link #EXTRA_SHORTCUT_NAME}
581 *     <li> {@link #EXTRA_SUBJECT}
582 *     <li> {@link #EXTRA_TEMPLATE}
583 *     <li> {@link #EXTRA_TEXT}
584 *     <li> {@link #EXTRA_TITLE}
585 *     <li> {@link #EXTRA_UID}
586 * </ul>
587 *
588 * <h3>Flags</h3>
589 *
590 * <p>These are the possible flags that can be used in the Intent via
591 * {@link #setFlags} and {@link #addFlags}.  See {@link #setFlags} for a list
592 * of all possible flags.
593 */
594public class Intent implements Parcelable, Cloneable {
595    // ---------------------------------------------------------------------
596    // ---------------------------------------------------------------------
597    // Standard intent activity actions (see action variable).
598
599    /**
600     *  Activity Action: Start as a main entry point, does not expect to
601     *  receive data.
602     *  <p>Input: nothing
603     *  <p>Output: nothing
604     */
605    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
606    public static final String ACTION_MAIN = "android.intent.action.MAIN";
607
608    /**
609     * Activity Action: Display the data to the user.  This is the most common
610     * action performed on data -- it is the generic action you can use on
611     * a piece of data to get the most reasonable thing to occur.  For example,
612     * when used on a contacts entry it will view the entry; when used on a
613     * mailto: URI it will bring up a compose window filled with the information
614     * supplied by the URI; when used with a tel: URI it will invoke the
615     * dialer.
616     * <p>Input: {@link #getData} is URI from which to retrieve data.
617     * <p>Output: nothing.
618     */
619    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
620    public static final String ACTION_VIEW = "android.intent.action.VIEW";
621
622    /**
623     * A synonym for {@link #ACTION_VIEW}, the "standard" action that is
624     * performed on a piece of data.
625     */
626    public static final String ACTION_DEFAULT = ACTION_VIEW;
627
628    /**
629     * Used to indicate that some piece of data should be attached to some other
630     * place.  For example, image data could be attached to a contact.  It is up
631     * to the recipient to decide where the data should be attached; the intent
632     * does not specify the ultimate destination.
633     * <p>Input: {@link #getData} is URI of data to be attached.
634     * <p>Output: nothing.
635     */
636    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
637    public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
638
639    /**
640     * Activity Action: Provide explicit editable access to the given data.
641     * <p>Input: {@link #getData} is URI of data to be edited.
642     * <p>Output: nothing.
643     */
644    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
645    public static final String ACTION_EDIT = "android.intent.action.EDIT";
646
647    /**
648     * Activity Action: Pick an existing item, or insert a new item, and then edit it.
649     * <p>Input: {@link #getType} is the desired MIME type of the item to create or edit.
650     * The extras can contain type specific data to pass through to the editing/creating
651     * activity.
652     * <p>Output: The URI of the item that was picked.  This must be a content:
653     * URI so that any receiver can access it.
654     */
655    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
656    public static final String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
657
658    /**
659     * Activity Action: Pick an item from the data, returning what was selected.
660     * <p>Input: {@link #getData} is URI containing a directory of data
661     * (vnd.android.cursor.dir/*) from which to pick an item.
662     * <p>Output: The URI of the item that was picked.
663     */
664    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
665    public static final String ACTION_PICK = "android.intent.action.PICK";
666
667    /**
668     * Activity Action: Creates a shortcut.
669     * <p>Input: Nothing.</p>
670     * <p>Output: An Intent representing the shortcut. The intent must contain three
671     * extras: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String),
672     * and SHORTCUT_ICON (value: Bitmap) or SHORTCUT_ICON_RESOURCE
673     * (value: ShortcutIconResource).</p>
674     *
675     * @see #EXTRA_SHORTCUT_INTENT
676     * @see #EXTRA_SHORTCUT_NAME
677     * @see #EXTRA_SHORTCUT_ICON
678     * @see #EXTRA_SHORTCUT_ICON_RESOURCE
679     * @see android.content.Intent.ShortcutIconResource
680     */
681    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
682    public static final String ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
683
684    /**
685     * The name of the extra used to define the Intent of a shortcut.
686     *
687     * @see #ACTION_CREATE_SHORTCUT
688     */
689    public static final String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
690    /**
691     * The name of the extra used to define the name of a shortcut.
692     *
693     * @see #ACTION_CREATE_SHORTCUT
694     */
695    public static final String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
696    /**
697     * The name of the extra used to define the icon, as a Bitmap, of a shortcut.
698     *
699     * @see #ACTION_CREATE_SHORTCUT
700     */
701    public static final String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
702    /**
703     * The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.
704     *
705     * @see #ACTION_CREATE_SHORTCUT
706     * @see android.content.Intent.ShortcutIconResource
707     */
708    public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
709            "android.intent.extra.shortcut.ICON_RESOURCE";
710
711    /**
712     * Represents a shortcut/live folder icon resource.
713     *
714     * @see Intent#ACTION_CREATE_SHORTCUT
715     * @see Intent#EXTRA_SHORTCUT_ICON_RESOURCE
716     * @see android.provider.LiveFolders#ACTION_CREATE_LIVE_FOLDER
717     * @see android.provider.LiveFolders#EXTRA_LIVE_FOLDER_ICON
718     */
719    public static class ShortcutIconResource implements Parcelable {
720        /**
721         * The package name of the application containing the icon.
722         */
723        public String packageName;
724
725        /**
726         * The resource name of the icon, including package, name and type.
727         */
728        public String resourceName;
729
730        /**
731         * Creates a new ShortcutIconResource for the specified context and resource
732         * identifier.
733         *
734         * @param context The context of the application.
735         * @param resourceId The resource idenfitier for the icon.
736         * @return A new ShortcutIconResource with the specified's context package name
737         *         and icon resource idenfitier.
738         */
739        public static ShortcutIconResource fromContext(Context context, int resourceId) {
740            ShortcutIconResource icon = new ShortcutIconResource();
741            icon.packageName = context.getPackageName();
742            icon.resourceName = context.getResources().getResourceName(resourceId);
743            return icon;
744        }
745
746        /**
747         * Used to read a ShortcutIconResource from a Parcel.
748         */
749        public static final Parcelable.Creator<ShortcutIconResource> CREATOR =
750            new Parcelable.Creator<ShortcutIconResource>() {
751
752                public ShortcutIconResource createFromParcel(Parcel source) {
753                    ShortcutIconResource icon = new ShortcutIconResource();
754                    icon.packageName = source.readString();
755                    icon.resourceName = source.readString();
756                    return icon;
757                }
758
759                public ShortcutIconResource[] newArray(int size) {
760                    return new ShortcutIconResource[size];
761                }
762            };
763
764        /**
765         * No special parcel contents.
766         */
767        public int describeContents() {
768            return 0;
769        }
770
771        public void writeToParcel(Parcel dest, int flags) {
772            dest.writeString(packageName);
773            dest.writeString(resourceName);
774        }
775
776        @Override
777        public String toString() {
778            return resourceName;
779        }
780    }
781
782    /**
783     * Activity Action: Display an activity chooser, allowing the user to pick
784     * what they want to before proceeding.  This can be used as an alternative
785     * to the standard activity picker that is displayed by the system when
786     * you try to start an activity with multiple possible matches, with these
787     * differences in behavior:
788     * <ul>
789     * <li>You can specify the title that will appear in the activity chooser.
790     * <li>The user does not have the option to make one of the matching
791     * activities a preferred activity, and all possible activities will
792     * always be shown even if one of them is currently marked as the
793     * preferred activity.
794     * </ul>
795     * <p>
796     * This action should be used when the user will naturally expect to
797     * select an activity in order to proceed.  An example if when not to use
798     * it is when the user clicks on a "mailto:" link.  They would naturally
799     * expect to go directly to their mail app, so startActivity() should be
800     * called directly: it will
801     * either launch the current preferred app, or put up a dialog allowing the
802     * user to pick an app to use and optionally marking that as preferred.
803     * <p>
804     * In contrast, if the user is selecting a menu item to send a picture
805     * they are viewing to someone else, there are many different things they
806     * may want to do at this point: send it through e-mail, upload it to a
807     * web service, etc.  In this case the CHOOSER action should be used, to
808     * always present to the user a list of the things they can do, with a
809     * nice title given by the caller such as "Send this photo with:".
810     * <p>
811     * If you need to grant URI permissions through a chooser, you must specify
812     * the permissions to be granted on the ACTION_CHOOSER Intent
813     * <em>in addition</em> to the EXTRA_INTENT inside.  This means using
814     * {@link #setClipData} to specify the URIs to be granted as well as
815     * {@link #FLAG_GRANT_READ_URI_PERMISSION} and/or
816     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION} as appropriate.
817     * <p>
818     * As a convenience, an Intent of this form can be created with the
819     * {@link #createChooser} function.
820     * <p>
821     * Input: No data should be specified.  get*Extra must have
822     * a {@link #EXTRA_INTENT} field containing the Intent being executed,
823     * and can optionally have a {@link #EXTRA_TITLE} field containing the
824     * title text to display in the chooser.
825     * <p>
826     * Output: Depends on the protocol of {@link #EXTRA_INTENT}.
827     */
828    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
829    public static final String ACTION_CHOOSER = "android.intent.action.CHOOSER";
830
831    /**
832     * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
833     *
834     * <p>Builds a new {@link #ACTION_CHOOSER} Intent that wraps the given
835     * target intent, also optionally supplying a title.  If the target
836     * intent has specified {@link #FLAG_GRANT_READ_URI_PERMISSION} or
837     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION}, then these flags will also be
838     * set in the returned chooser intent, with its ClipData set appropriately:
839     * either a direct reflection of {@link #getClipData()} if that is non-null,
840     * or a new ClipData build from {@link #getData()}.
841     *
842     * @param target The Intent that the user will be selecting an activity
843     * to perform.
844     * @param title Optional title that will be displayed in the chooser.
845     * @return Return a new Intent object that you can hand to
846     * {@link Context#startActivity(Intent) Context.startActivity()} and
847     * related methods.
848     */
849    public static Intent createChooser(Intent target, CharSequence title) {
850        Intent intent = new Intent(ACTION_CHOOSER);
851        intent.putExtra(EXTRA_INTENT, target);
852        if (title != null) {
853            intent.putExtra(EXTRA_TITLE, title);
854        }
855
856        // Migrate any clip data and flags from target.
857        int permFlags = target.getFlags()
858                & (FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION);
859        if (permFlags != 0) {
860            ClipData targetClipData = target.getClipData();
861            if (targetClipData == null && target.getData() != null) {
862                ClipData.Item item = new ClipData.Item(target.getData());
863                String[] mimeTypes;
864                if (target.getType() != null) {
865                    mimeTypes = new String[] { target.getType() };
866                } else {
867                    mimeTypes = new String[] { };
868                }
869                targetClipData = new ClipData(null, mimeTypes, item);
870            }
871            if (targetClipData != null) {
872                intent.setClipData(targetClipData);
873                intent.addFlags(permFlags);
874            }
875        }
876
877        return intent;
878    }
879
880    /**
881     * Activity Action: Allow the user to select a particular kind of data and
882     * return it.  This is different than {@link #ACTION_PICK} in that here we
883     * just say what kind of data is desired, not a URI of existing data from
884     * which the user can pick.  A ACTION_GET_CONTENT could allow the user to
885     * create the data as it runs (for example taking a picture or recording a
886     * sound), let them browse over the web and download the desired data,
887     * etc.
888     * <p>
889     * There are two main ways to use this action: if you want a specific kind
890     * of data, such as a person contact, you set the MIME type to the kind of
891     * data you want and launch it with {@link Context#startActivity(Intent)}.
892     * The system will then launch the best application to select that kind
893     * of data for you.
894     * <p>
895     * You may also be interested in any of a set of types of content the user
896     * can pick.  For example, an e-mail application that wants to allow the
897     * user to add an attachment to an e-mail message can use this action to
898     * bring up a list of all of the types of content the user can attach.
899     * <p>
900     * In this case, you should wrap the GET_CONTENT intent with a chooser
901     * (through {@link #createChooser}), which will give the proper interface
902     * for the user to pick how to send your data and allow you to specify
903     * a prompt indicating what they are doing.  You will usually specify a
904     * broad MIME type (such as image/* or {@literal *}/*), resulting in a
905     * broad range of content types the user can select from.
906     * <p>
907     * When using such a broad GET_CONTENT action, it is often desirable to
908     * only pick from data that can be represented as a stream.  This is
909     * accomplished by requiring the {@link #CATEGORY_OPENABLE} in the Intent.
910     * <p>
911     * Callers can optionally specify {@link #EXTRA_LOCAL_ONLY} to request that
912     * the launched content chooser only returns results representing data that
913     * is locally available on the device.  For example, if this extra is set
914     * to true then an image picker should not show any pictures that are available
915     * from a remote server but not already on the local device (thus requiring
916     * they be downloaded when opened).
917     * <p>
918     * Input: {@link #getType} is the desired MIME type to retrieve.  Note
919     * that no URI is supplied in the intent, as there are no constraints on
920     * where the returned data originally comes from.  You may also include the
921     * {@link #CATEGORY_OPENABLE} if you can only accept data that can be
922     * opened as a stream.  You may use {@link #EXTRA_LOCAL_ONLY} to limit content
923     * selection to local data.
924     * <p>
925     * Output: The URI of the item that was picked.  This must be a content:
926     * URI so that any receiver can access it.
927     */
928    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
929    public static final String ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
930    /**
931     * Activity Action: Dial a number as specified by the data.  This shows a
932     * UI with the number being dialed, allowing the user to explicitly
933     * initiate the call.
934     * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
935     * is URI of a phone number to be dialed or a tel: URI of an explicit phone
936     * number.
937     * <p>Output: nothing.
938     */
939    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
940    public static final String ACTION_DIAL = "android.intent.action.DIAL";
941    /**
942     * Activity Action: Perform a call to someone specified by the data.
943     * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
944     * is URI of a phone number to be dialed or a tel: URI of an explicit phone
945     * number.
946     * <p>Output: nothing.
947     *
948     * <p>Note: there will be restrictions on which applications can initiate a
949     * call; most applications should use the {@link #ACTION_DIAL}.
950     * <p>Note: this Intent <strong>cannot</strong> be used to call emergency
951     * numbers.  Applications can <strong>dial</strong> emergency numbers using
952     * {@link #ACTION_DIAL}, however.
953     */
954    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
955    public static final String ACTION_CALL = "android.intent.action.CALL";
956    /**
957     * Activity Action: Perform a call to an emergency number specified by the
958     * data.
959     * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
960     * tel: URI of an explicit phone number.
961     * <p>Output: nothing.
962     * @hide
963     */
964    public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
965    /**
966     * Activity action: Perform a call to any number (emergency or not)
967     * specified by the data.
968     * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
969     * tel: URI of an explicit phone number.
970     * <p>Output: nothing.
971     * @hide
972     */
973    public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
974    /**
975     * Activity Action: Send a message to someone specified by the data.
976     * <p>Input: {@link #getData} is URI describing the target.
977     * <p>Output: nothing.
978     */
979    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
980    public static final String ACTION_SENDTO = "android.intent.action.SENDTO";
981    /**
982     * Activity Action: Deliver some data to someone else.  Who the data is
983     * being delivered to is not specified; it is up to the receiver of this
984     * action to ask the user where the data should be sent.
985     * <p>
986     * When launching a SEND intent, you should usually wrap it in a chooser
987     * (through {@link #createChooser}), which will give the proper interface
988     * for the user to pick how to send your data and allow you to specify
989     * a prompt indicating what they are doing.
990     * <p>
991     * Input: {@link #getType} is the MIME type of the data being sent.
992     * get*Extra can have either a {@link #EXTRA_TEXT}
993     * or {@link #EXTRA_STREAM} field, containing the data to be sent.  If
994     * using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it
995     * should be the MIME type of the data in EXTRA_STREAM.  Use {@literal *}/*
996     * if the MIME type is unknown (this will only allow senders that can
997     * handle generic data streams).  If using {@link #EXTRA_TEXT}, you can
998     * also optionally supply {@link #EXTRA_HTML_TEXT} for clients to retrieve
999     * your text with HTML formatting.
1000     * <p>
1001     * As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, the data
1002     * being sent can be supplied through {@link #setClipData(ClipData)}.  This
1003     * allows you to use {@link #FLAG_GRANT_READ_URI_PERMISSION} when sharing
1004     * content: URIs and other advanced features of {@link ClipData}.  If
1005     * using this approach, you still must supply the same data through the
1006     * {@link #EXTRA_TEXT} or {@link #EXTRA_STREAM} fields described below
1007     * for compatibility with old applications.  If you don't set a ClipData,
1008     * it will be copied there for you when calling {@link Context#startActivity(Intent)}.
1009     * <p>
1010     * Optional standard extras, which may be interpreted by some recipients as
1011     * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
1012     * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
1013     * <p>
1014     * Output: nothing.
1015     */
1016    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1017    public static final String ACTION_SEND = "android.intent.action.SEND";
1018    /**
1019     * Activity Action: Deliver multiple data to someone else.
1020     * <p>
1021     * Like {@link #ACTION_SEND}, except the data is multiple.
1022     * <p>
1023     * Input: {@link #getType} is the MIME type of the data being sent.
1024     * get*ArrayListExtra can have either a {@link #EXTRA_TEXT} or {@link
1025     * #EXTRA_STREAM} field, containing the data to be sent.  If using
1026     * {@link #EXTRA_TEXT}, you can also optionally supply {@link #EXTRA_HTML_TEXT}
1027     * for clients to retrieve your text with HTML formatting.
1028     * <p>
1029     * Multiple types are supported, and receivers should handle mixed types
1030     * whenever possible. The right way for the receiver to check them is to
1031     * use the content resolver on each URI. The intent sender should try to
1032     * put the most concrete mime type in the intent type, but it can fall
1033     * back to {@literal <type>/*} or {@literal *}/* as needed.
1034     * <p>
1035     * e.g. if you are sending image/jpg and image/jpg, the intent's type can
1036     * be image/jpg, but if you are sending image/jpg and image/png, then the
1037     * intent's type should be image/*.
1038     * <p>
1039     * As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, the data
1040     * being sent can be supplied through {@link #setClipData(ClipData)}.  This
1041     * allows you to use {@link #FLAG_GRANT_READ_URI_PERMISSION} when sharing
1042     * content: URIs and other advanced features of {@link ClipData}.  If
1043     * using this approach, you still must supply the same data through the
1044     * {@link #EXTRA_TEXT} or {@link #EXTRA_STREAM} fields described below
1045     * for compatibility with old applications.  If you don't set a ClipData,
1046     * it will be copied there for you when calling {@link Context#startActivity(Intent)}.
1047     * <p>
1048     * Optional standard extras, which may be interpreted by some recipients as
1049     * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
1050     * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
1051     * <p>
1052     * Output: nothing.
1053     */
1054    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1055    public static final String ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE";
1056    /**
1057     * Activity Action: Handle an incoming phone call.
1058     * <p>Input: nothing.
1059     * <p>Output: nothing.
1060     */
1061    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1062    public static final String ACTION_ANSWER = "android.intent.action.ANSWER";
1063    /**
1064     * Activity Action: Insert an empty item into the given container.
1065     * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
1066     * in which to place the data.
1067     * <p>Output: URI of the new data that was created.
1068     */
1069    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1070    public static final String ACTION_INSERT = "android.intent.action.INSERT";
1071    /**
1072     * Activity Action: Create a new item in the given container, initializing it
1073     * from the current contents of the clipboard.
1074     * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
1075     * in which to place the data.
1076     * <p>Output: URI of the new data that was created.
1077     */
1078    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1079    public static final String ACTION_PASTE = "android.intent.action.PASTE";
1080    /**
1081     * Activity Action: Delete the given data from its container.
1082     * <p>Input: {@link #getData} is URI of data to be deleted.
1083     * <p>Output: nothing.
1084     */
1085    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1086    public static final String ACTION_DELETE = "android.intent.action.DELETE";
1087    /**
1088     * Activity Action: Run the data, whatever that means.
1089     * <p>Input: ?  (Note: this is currently specific to the test harness.)
1090     * <p>Output: nothing.
1091     */
1092    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1093    public static final String ACTION_RUN = "android.intent.action.RUN";
1094    /**
1095     * Activity Action: Perform a data synchronization.
1096     * <p>Input: ?
1097     * <p>Output: ?
1098     */
1099    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1100    public static final String ACTION_SYNC = "android.intent.action.SYNC";
1101    /**
1102     * Activity Action: Pick an activity given an intent, returning the class
1103     * selected.
1104     * <p>Input: get*Extra field {@link #EXTRA_INTENT} is an Intent
1105     * used with {@link PackageManager#queryIntentActivities} to determine the
1106     * set of activities from which to pick.
1107     * <p>Output: Class name of the activity that was selected.
1108     */
1109    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1110    public static final String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
1111    /**
1112     * Activity Action: Perform a search.
1113     * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
1114     * is the text to search for.  If empty, simply
1115     * enter your search results Activity with the search UI activated.
1116     * <p>Output: nothing.
1117     */
1118    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1119    public static final String ACTION_SEARCH = "android.intent.action.SEARCH";
1120    /**
1121     * Activity Action: Start the platform-defined tutorial
1122     * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
1123     * is the text to search for.  If empty, simply
1124     * enter your search results Activity with the search UI activated.
1125     * <p>Output: nothing.
1126     */
1127    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1128    public static final String ACTION_SYSTEM_TUTORIAL = "android.intent.action.SYSTEM_TUTORIAL";
1129    /**
1130     * Activity Action: Perform a web search.
1131     * <p>
1132     * Input: {@link android.app.SearchManager#QUERY
1133     * getStringExtra(SearchManager.QUERY)} is the text to search for. If it is
1134     * a url starts with http or https, the site will be opened. If it is plain
1135     * text, Google search will be applied.
1136     * <p>
1137     * Output: nothing.
1138     */
1139    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1140    public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
1141    /**
1142     * Activity Action: Perform assist action.
1143     * <p>
1144     * Input: nothing
1145     * Output: nothing.
1146     */
1147    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1148    public static final String ACTION_ASSIST = "android.intent.action.ASSIST";
1149    /**
1150     * Activity Action: List all available applications
1151     * <p>Input: Nothing.
1152     * <p>Output: nothing.
1153     */
1154    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1155    public static final String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
1156    /**
1157     * Activity Action: Show settings for choosing wallpaper
1158     * <p>Input: Nothing.
1159     * <p>Output: Nothing.
1160     */
1161    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1162    public static final String ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
1163
1164    /**
1165     * Activity Action: Show activity for reporting a bug.
1166     * <p>Input: Nothing.
1167     * <p>Output: Nothing.
1168     */
1169    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1170    public static final String ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
1171
1172    /**
1173     *  Activity Action: Main entry point for factory tests.  Only used when
1174     *  the device is booting in factory test node.  The implementing package
1175     *  must be installed in the system image.
1176     *  <p>Input: nothing
1177     *  <p>Output: nothing
1178     */
1179    public static final String ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
1180
1181    /**
1182     * Activity Action: The user pressed the "call" button to go to the dialer
1183     * or other appropriate UI for placing a call.
1184     * <p>Input: Nothing.
1185     * <p>Output: Nothing.
1186     */
1187    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1188    public static final String ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
1189
1190    /**
1191     * Activity Action: Start Voice Command.
1192     * <p>Input: Nothing.
1193     * <p>Output: Nothing.
1194     */
1195    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1196    public static final String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
1197
1198    /**
1199     * Activity Action: Start action associated with long pressing on the
1200     * search key.
1201     * <p>Input: Nothing.
1202     * <p>Output: Nothing.
1203     */
1204    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1205    public static final String ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";
1206
1207    /**
1208     * Activity Action: The user pressed the "Report" button in the crash/ANR dialog.
1209     * This intent is delivered to the package which installed the application, usually
1210     * Google Play.
1211     * <p>Input: No data is specified. The bug report is passed in using
1212     * an {@link #EXTRA_BUG_REPORT} field.
1213     * <p>Output: Nothing.
1214     *
1215     * @see #EXTRA_BUG_REPORT
1216     */
1217    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1218    public static final String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
1219
1220    /**
1221     * Activity Action: Show power usage information to the user.
1222     * <p>Input: Nothing.
1223     * <p>Output: Nothing.
1224     */
1225    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1226    public static final String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
1227
1228    /**
1229     * Activity Action: Setup wizard to launch after a platform update.  This
1230     * activity should have a string meta-data field associated with it,
1231     * {@link #METADATA_SETUP_VERSION}, which defines the current version of
1232     * the platform for setup.  The activity will be launched only if
1233     * {@link android.provider.Settings.Secure#LAST_SETUP_SHOWN} is not the
1234     * same value.
1235     * <p>Input: Nothing.
1236     * <p>Output: Nothing.
1237     * @hide
1238     */
1239    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1240    public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
1241
1242    /**
1243     * Activity Action: Show settings for managing network data usage of a
1244     * specific application. Applications should define an activity that offers
1245     * options to control data usage.
1246     */
1247    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1248    public static final String ACTION_MANAGE_NETWORK_USAGE =
1249            "android.intent.action.MANAGE_NETWORK_USAGE";
1250
1251    /**
1252     * Activity Action: Launch application installer.
1253     * <p>
1254     * Input: The data must be a content: or file: URI at which the application
1255     * can be retrieved.  You can optionally supply
1256     * {@link #EXTRA_INSTALLER_PACKAGE_NAME}, {@link #EXTRA_NOT_UNKNOWN_SOURCE},
1257     * {@link #EXTRA_ALLOW_REPLACE}, and {@link #EXTRA_RETURN_RESULT}.
1258     * <p>
1259     * Output: If {@link #EXTRA_RETURN_RESULT}, returns whether the install
1260     * succeeded.
1261     *
1262     * @see #EXTRA_INSTALLER_PACKAGE_NAME
1263     * @see #EXTRA_NOT_UNKNOWN_SOURCE
1264     * @see #EXTRA_RETURN_RESULT
1265     */
1266    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1267    public static final String ACTION_INSTALL_PACKAGE = "android.intent.action.INSTALL_PACKAGE";
1268
1269    /**
1270     * Used as a string extra field with {@link #ACTION_INSTALL_PACKAGE} to install a
1271     * package.  Specifies the installer package name; this package will receive the
1272     * {@link #ACTION_APP_ERROR} intent.
1273     */
1274    public static final String EXTRA_INSTALLER_PACKAGE_NAME
1275            = "android.intent.extra.INSTALLER_PACKAGE_NAME";
1276
1277    /**
1278     * Used as a boolean extra field with {@link #ACTION_INSTALL_PACKAGE} to install a
1279     * package.  Specifies that the application being installed should not be
1280     * treated as coming from an unknown source, but as coming from the app
1281     * invoking the Intent.  For this to work you must start the installer with
1282     * startActivityForResult().
1283     */
1284    public static final String EXTRA_NOT_UNKNOWN_SOURCE
1285            = "android.intent.extra.NOT_UNKNOWN_SOURCE";
1286
1287    /**
1288     * Used as a boolean extra field with {@link #ACTION_INSTALL_PACKAGE} to install a
1289     * package.  Tells the installer UI to skip the confirmation with the user
1290     * if the .apk is replacing an existing one.
1291     * @deprecated As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, Android
1292     * will no longer show an interstitial message about updating existing
1293     * applications so this is no longer needed.
1294     */
1295    @Deprecated
1296    public static final String EXTRA_ALLOW_REPLACE
1297            = "android.intent.extra.ALLOW_REPLACE";
1298
1299    /**
1300     * Used as a boolean extra field with {@link #ACTION_INSTALL_PACKAGE} or
1301     * {@link #ACTION_UNINSTALL_PACKAGE}.  Specifies that the installer UI should
1302     * return to the application the result code of the install/uninstall.  The returned result
1303     * code will be {@link android.app.Activity#RESULT_OK} on success or
1304     * {@link android.app.Activity#RESULT_FIRST_USER} on failure.
1305     */
1306    public static final String EXTRA_RETURN_RESULT
1307            = "android.intent.extra.RETURN_RESULT";
1308
1309    /**
1310     * Package manager install result code.  @hide because result codes are not
1311     * yet ready to be exposed.
1312     */
1313    public static final String EXTRA_INSTALL_RESULT
1314            = "android.intent.extra.INSTALL_RESULT";
1315
1316    /**
1317     * Activity Action: Launch application uninstaller.
1318     * <p>
1319     * Input: The data must be a package: URI whose scheme specific part is
1320     * the package name of the current installed package to be uninstalled.
1321     * You can optionally supply {@link #EXTRA_RETURN_RESULT}.
1322     * <p>
1323     * Output: If {@link #EXTRA_RETURN_RESULT}, returns whether the install
1324     * succeeded.
1325     */
1326    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1327    public static final String ACTION_UNINSTALL_PACKAGE = "android.intent.action.UNINSTALL_PACKAGE";
1328
1329    /**
1330     * A string associated with a {@link #ACTION_UPGRADE_SETUP} activity
1331     * describing the last run version of the platform that was setup.
1332     * @hide
1333     */
1334    public static final String METADATA_SETUP_VERSION = "android.SETUP_VERSION";
1335
1336    // ---------------------------------------------------------------------
1337    // ---------------------------------------------------------------------
1338    // Standard intent broadcast actions (see action variable).
1339
1340    /**
1341     * Broadcast Action: Sent after the screen turns off.
1342     *
1343     * <p class="note">This is a protected intent that can only be sent
1344     * by the system.
1345     */
1346    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1347    public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
1348    /**
1349     * Broadcast Action: Sent after the screen turns on.
1350     *
1351     * <p class="note">This is a protected intent that can only be sent
1352     * by the system.
1353     */
1354    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1355    public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
1356
1357    /**
1358     * Broadcast Action: Sent when the user is present after device wakes up (e.g when the
1359     * keyguard is gone).
1360     *
1361     * <p class="note">This is a protected intent that can only be sent
1362     * by the system.
1363     */
1364    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1365    public static final String ACTION_USER_PRESENT = "android.intent.action.USER_PRESENT";
1366
1367    /**
1368     * Broadcast Action: The current time has changed.  Sent every
1369     * minute.  You can <em>not</em> receive this through components declared
1370     * in manifests, only by exlicitly registering for it with
1371     * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1372     * Context.registerReceiver()}.
1373     *
1374     * <p class="note">This is a protected intent that can only be sent
1375     * by the system.
1376     */
1377    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1378    public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
1379    /**
1380     * Broadcast Action: The time was set.
1381     */
1382    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1383    public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
1384    /**
1385     * Broadcast Action: The date has changed.
1386     */
1387    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1388    public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
1389    /**
1390     * Broadcast Action: The timezone has changed. The intent will have the following extra values:</p>
1391     * <ul>
1392     *   <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time zone.</li>
1393     * </ul>
1394     *
1395     * <p class="note">This is a protected intent that can only be sent
1396     * by the system.
1397     */
1398    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1399    public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
1400    /**
1401     * Clear DNS Cache Action: This is broadcast when networks have changed and old
1402     * DNS entries should be tossed.
1403     * @hide
1404     */
1405    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1406    public static final String ACTION_CLEAR_DNS_CACHE = "android.intent.action.CLEAR_DNS_CACHE";
1407    /**
1408     * Alarm Changed Action: This is broadcast when the AlarmClock
1409     * application's alarm is set or unset.  It is used by the
1410     * AlarmClock application and the StatusBar service.
1411     * @hide
1412     */
1413    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1414    public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
1415    /**
1416     * Sync State Changed Action: This is broadcast when the sync starts or stops or when one has
1417     * been failing for a long time.  It is used by the SyncManager and the StatusBar service.
1418     * @hide
1419     */
1420    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1421    public static final String ACTION_SYNC_STATE_CHANGED
1422            = "android.intent.action.SYNC_STATE_CHANGED";
1423    /**
1424     * Broadcast Action: This is broadcast once, after the system has finished
1425     * booting.  It can be used to perform application-specific initialization,
1426     * such as installing alarms.  You must hold the
1427     * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
1428     * in order to receive this broadcast.
1429     *
1430     * <p class="note">This is a protected intent that can only be sent
1431     * by the system.
1432     */
1433    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1434    public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
1435    /**
1436     * Broadcast Action: This is broadcast when a user action should request a
1437     * temporary system dialog to dismiss.  Some examples of temporary system
1438     * dialogs are the notification window-shade and the recent tasks dialog.
1439     */
1440    public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
1441    /**
1442     * Broadcast Action: Trigger the download and eventual installation
1443     * of a package.
1444     * <p>Input: {@link #getData} is the URI of the package file to download.
1445     *
1446     * <p class="note">This is a protected intent that can only be sent
1447     * by the system.
1448     *
1449     * @deprecated This constant has never been used.
1450     */
1451    @Deprecated
1452    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1453    public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
1454    /**
1455     * Broadcast Action: A new application package has been installed on the
1456     * device. The data contains the name of the package.  Note that the
1457     * newly installed package does <em>not</em> receive this broadcast.
1458     * <p>My include the following extras:
1459     * <ul>
1460     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1461     * <li> {@link #EXTRA_REPLACING} is set to true if this is following
1462     * an {@link #ACTION_PACKAGE_REMOVED} broadcast for the same package.
1463     * </ul>
1464     *
1465     * <p class="note">This is a protected intent that can only be sent
1466     * by the system.
1467     */
1468    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1469    public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
1470    /**
1471     * Broadcast Action: A new version of an application package has been
1472     * installed, replacing an existing version that was previously installed.
1473     * The data contains the name of the package.
1474     * <p>My include the following extras:
1475     * <ul>
1476     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1477     * </ul>
1478     *
1479     * <p class="note">This is a protected intent that can only be sent
1480     * by the system.
1481     */
1482    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1483    public static final String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
1484    /**
1485     * Broadcast Action: A new version of your application has been installed
1486     * over an existing one.  This is only sent to the application that was
1487     * replaced.  It does not contain any additional data; to receive it, just
1488     * use an intent filter for this action.
1489     *
1490     * <p class="note">This is a protected intent that can only be sent
1491     * by the system.
1492     */
1493    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1494    public static final String ACTION_MY_PACKAGE_REPLACED = "android.intent.action.MY_PACKAGE_REPLACED";
1495    /**
1496     * Broadcast Action: An existing application package has been removed from
1497     * the device.  The data contains the name of the package.  The package
1498     * that is being installed does <em>not</em> receive this Intent.
1499     * <ul>
1500     * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1501     * to the package.
1502     * <li> {@link #EXTRA_DATA_REMOVED} is set to true if the entire
1503     * application -- data and code -- is being removed.
1504     * <li> {@link #EXTRA_REPLACING} is set to true if this will be followed
1505     * by an {@link #ACTION_PACKAGE_ADDED} broadcast for the same package.
1506     * </ul>
1507     *
1508     * <p class="note">This is a protected intent that can only be sent
1509     * by the system.
1510     */
1511    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1512    public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
1513    /**
1514     * Broadcast Action: An existing application package has been completely
1515     * removed from the device.  The data contains the name of the package.
1516     * This is like {@link #ACTION_PACKAGE_REMOVED}, but only set when
1517     * {@link #EXTRA_DATA_REMOVED} is true and
1518     * {@link #EXTRA_REPLACING} is false of that broadcast.
1519     *
1520     * <ul>
1521     * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1522     * to the package.
1523     * </ul>
1524     *
1525     * <p class="note">This is a protected intent that can only be sent
1526     * by the system.
1527     */
1528    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1529    public static final String ACTION_PACKAGE_FULLY_REMOVED
1530            = "android.intent.action.PACKAGE_FULLY_REMOVED";
1531    /**
1532     * Broadcast Action: An existing application package has been changed (e.g.
1533     * a component has been enabled or disabled).  The data contains the name of
1534     * the package.
1535     * <ul>
1536     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1537     * <li> {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST} containing the class name
1538     * of the changed components.
1539     * <li> {@link #EXTRA_DONT_KILL_APP} containing boolean field to override the
1540     * default action of restarting the application.
1541     * </ul>
1542     *
1543     * <p class="note">This is a protected intent that can only be sent
1544     * by the system.
1545     */
1546    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1547    public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
1548    /**
1549     * @hide
1550     * Broadcast Action: Ask system services if there is any reason to
1551     * restart the given package.  The data contains the name of the
1552     * package.
1553     * <ul>
1554     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1555     * <li> {@link #EXTRA_PACKAGES} String array of all packages to check.
1556     * </ul>
1557     *
1558     * <p class="note">This is a protected intent that can only be sent
1559     * by the system.
1560     */
1561    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1562    public static final String ACTION_QUERY_PACKAGE_RESTART = "android.intent.action.QUERY_PACKAGE_RESTART";
1563    /**
1564     * Broadcast Action: The user has restarted a package, and all of its
1565     * processes have been killed.  All runtime state
1566     * associated with it (processes, alarms, notifications, etc) should
1567     * be removed.  Note that the restarted package does <em>not</em>
1568     * receive this broadcast.
1569     * The data contains the name of the package.
1570     * <ul>
1571     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1572     * </ul>
1573     *
1574     * <p class="note">This is a protected intent that can only be sent
1575     * by the system.
1576     */
1577    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1578    public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
1579    /**
1580     * Broadcast Action: The user has cleared the data of a package.  This should
1581     * be preceded by {@link #ACTION_PACKAGE_RESTARTED}, after which all of
1582     * its persistent data is erased and this broadcast sent.
1583     * Note that the cleared package does <em>not</em>
1584     * receive this broadcast. The data contains the name of the package.
1585     * <ul>
1586     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1587     * </ul>
1588     *
1589     * <p class="note">This is a protected intent that can only be sent
1590     * by the system.
1591     */
1592    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1593    public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
1594    /**
1595     * Broadcast Action: A user ID has been removed from the system.  The user
1596     * ID number is stored in the extra data under {@link #EXTRA_UID}.
1597     *
1598     * <p class="note">This is a protected intent that can only be sent
1599     * by the system.
1600     */
1601    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1602    public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
1603
1604    /**
1605     * Broadcast Action: Sent to the installer package of an application
1606     * when that application is first launched (that is the first time it
1607     * is moved out of the stopped state).  The data contains the name of the package.
1608     *
1609     * <p class="note">This is a protected intent that can only be sent
1610     * by the system.
1611     */
1612    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1613    public static final String ACTION_PACKAGE_FIRST_LAUNCH = "android.intent.action.PACKAGE_FIRST_LAUNCH";
1614
1615    /**
1616     * Broadcast Action: Sent to the system package verifier when a package
1617     * needs to be verified. The data contains the package URI.
1618     * <p class="note">
1619     * This is a protected intent that can only be sent by the system.
1620     * </p>
1621     */
1622    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1623    public static final String ACTION_PACKAGE_NEEDS_VERIFICATION = "android.intent.action.PACKAGE_NEEDS_VERIFICATION";
1624
1625    /**
1626     * Broadcast Action: Resources for a set of packages (which were
1627     * previously unavailable) are currently
1628     * available since the media on which they exist is available.
1629     * The extra data {@link #EXTRA_CHANGED_PACKAGE_LIST} contains a
1630     * list of packages whose availability changed.
1631     * The extra data {@link #EXTRA_CHANGED_UID_LIST} contains a
1632     * list of uids of packages whose availability changed.
1633     * Note that the
1634     * packages in this list do <em>not</em> receive this broadcast.
1635     * The specified set of packages are now available on the system.
1636     * <p>Includes the following extras:
1637     * <ul>
1638     * <li> {@link #EXTRA_CHANGED_PACKAGE_LIST} is the set of packages
1639     * whose resources(were previously unavailable) are currently available.
1640     * {@link #EXTRA_CHANGED_UID_LIST} is the set of uids of the
1641     * packages whose resources(were previously unavailable)
1642     * are  currently available.
1643     * </ul>
1644     *
1645     * <p class="note">This is a protected intent that can only be sent
1646     * by the system.
1647     */
1648    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1649    public static final String ACTION_EXTERNAL_APPLICATIONS_AVAILABLE =
1650        "android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE";
1651
1652    /**
1653     * Broadcast Action: Resources for a set of packages are currently
1654     * unavailable since the media on which they exist is unavailable.
1655     * The extra data {@link #EXTRA_CHANGED_PACKAGE_LIST} contains a
1656     * list of packages whose availability changed.
1657     * The extra data {@link #EXTRA_CHANGED_UID_LIST} contains a
1658     * list of uids of packages whose availability changed.
1659     * The specified set of packages can no longer be
1660     * launched and are practically unavailable on the system.
1661     * <p>Inclues the following extras:
1662     * <ul>
1663     * <li> {@link #EXTRA_CHANGED_PACKAGE_LIST} is the set of packages
1664     * whose resources are no longer available.
1665     * {@link #EXTRA_CHANGED_UID_LIST} is the set of packages
1666     * whose resources are no longer available.
1667     * </ul>
1668     *
1669     * <p class="note">This is a protected intent that can only be sent
1670     * by the system.
1671     */
1672    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1673    public static final String ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE =
1674        "android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE";
1675
1676    /**
1677     * Broadcast Action:  The current system wallpaper has changed.  See
1678     * {@link android.app.WallpaperManager} for retrieving the new wallpaper.
1679     * This should <em>only</em> be used to determine when the wallpaper
1680     * has changed to show the new wallpaper to the user.  You should certainly
1681     * never, in response to this, change the wallpaper or other attributes of
1682     * it such as the suggested size.  That would be crazy, right?  You'd cause
1683     * all kinds of loops, especially if other apps are doing similar things,
1684     * right?  Of course.  So please don't do this.
1685     *
1686     * @deprecated Modern applications should use
1687     * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WALLPAPER
1688     * WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER} to have the wallpaper
1689     * shown behind their UI, rather than watching for this broadcast and
1690     * rendering the wallpaper on their own.
1691     */
1692    @Deprecated @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1693    public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
1694    /**
1695     * Broadcast Action: The current device {@link android.content.res.Configuration}
1696     * (orientation, locale, etc) has changed.  When such a change happens, the
1697     * UIs (view hierarchy) will need to be rebuilt based on this new
1698     * information; for the most part, applications don't need to worry about
1699     * this, because the system will take care of stopping and restarting the
1700     * application to make sure it sees the new changes.  Some system code that
1701     * can not be restarted will need to watch for this action and handle it
1702     * appropriately.
1703     *
1704     * <p class="note">
1705     * You can <em>not</em> receive this through components declared
1706     * in manifests, only by explicitly registering for it with
1707     * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1708     * Context.registerReceiver()}.
1709     *
1710     * <p class="note">This is a protected intent that can only be sent
1711     * by the system.
1712     *
1713     * @see android.content.res.Configuration
1714     */
1715    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1716    public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
1717    /**
1718     * Broadcast Action: The current device's locale has changed.
1719     *
1720     * <p class="note">This is a protected intent that can only be sent
1721     * by the system.
1722     */
1723    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1724    public static final String ACTION_LOCALE_CHANGED = "android.intent.action.LOCALE_CHANGED";
1725    /**
1726     * Broadcast Action:  This is a <em>sticky broadcast</em> containing the
1727     * charging state, level, and other information about the battery.
1728     * See {@link android.os.BatteryManager} for documentation on the
1729     * contents of the Intent.
1730     *
1731     * <p class="note">
1732     * You can <em>not</em> receive this through components declared
1733     * in manifests, only by explicitly registering for it with
1734     * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1735     * Context.registerReceiver()}.  See {@link #ACTION_BATTERY_LOW},
1736     * {@link #ACTION_BATTERY_OKAY}, {@link #ACTION_POWER_CONNECTED},
1737     * and {@link #ACTION_POWER_DISCONNECTED} for distinct battery-related
1738     * broadcasts that are sent and can be received through manifest
1739     * receivers.
1740     *
1741     * <p class="note">This is a protected intent that can only be sent
1742     * by the system.
1743     */
1744    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1745    public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
1746    /**
1747     * Broadcast Action:  Indicates low battery condition on the device.
1748     * This broadcast corresponds to the "Low battery warning" system dialog.
1749     *
1750     * <p class="note">This is a protected intent that can only be sent
1751     * by the system.
1752     */
1753    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1754    public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
1755    /**
1756     * Broadcast Action:  Indicates the battery is now okay after being low.
1757     * This will be sent after {@link #ACTION_BATTERY_LOW} once the battery has
1758     * gone back up to an okay state.
1759     *
1760     * <p class="note">This is a protected intent that can only be sent
1761     * by the system.
1762     */
1763    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1764    public static final String ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";
1765    /**
1766     * Broadcast Action:  External power has been connected to the device.
1767     * This is intended for applications that wish to register specifically to this notification.
1768     * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1769     * stay active to receive this notification.  This action can be used to implement actions
1770     * that wait until power is available to trigger.
1771     *
1772     * <p class="note">This is a protected intent that can only be sent
1773     * by the system.
1774     */
1775    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1776    public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
1777    /**
1778     * Broadcast Action:  External power has been removed from the device.
1779     * This is intended for applications that wish to register specifically to this notification.
1780     * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1781     * stay active to receive this notification.  This action can be used to implement actions
1782     * that wait until power is available to trigger.
1783     *
1784     * <p class="note">This is a protected intent that can only be sent
1785     * by the system.
1786     */
1787    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1788    public static final String ACTION_POWER_DISCONNECTED =
1789            "android.intent.action.ACTION_POWER_DISCONNECTED";
1790    /**
1791     * Broadcast Action:  Device is shutting down.
1792     * This is broadcast when the device is being shut down (completely turned
1793     * off, not sleeping).  Once the broadcast is complete, the final shutdown
1794     * will proceed and all unsaved data lost.  Apps will not normally need
1795     * to handle this, since the foreground activity will be paused as well.
1796     *
1797     * <p class="note">This is a protected intent that can only be sent
1798     * by the system.
1799     */
1800    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1801    public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
1802    /**
1803     * Activity Action:  Start this activity to request system shutdown.
1804     * The optional boolean extra field {@link #EXTRA_KEY_CONFIRM} can be set to true
1805     * to request confirmation from the user before shutting down.
1806     *
1807     * <p class="note">This is a protected intent that can only be sent
1808     * by the system.
1809     *
1810     * {@hide}
1811     */
1812    public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
1813    /**
1814     * Broadcast Action:  A sticky broadcast that indicates low memory
1815     * condition on the device
1816     *
1817     * <p class="note">This is a protected intent that can only be sent
1818     * by the system.
1819     */
1820    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1821    public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
1822    /**
1823     * Broadcast Action:  Indicates low memory condition on the device no longer exists
1824     *
1825     * <p class="note">This is a protected intent that can only be sent
1826     * by the system.
1827     */
1828    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1829    public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
1830    /**
1831     * Broadcast Action:  A sticky broadcast that indicates a memory full
1832     * condition on the device. This is intended for activities that want
1833     * to be able to fill the data partition completely, leaving only
1834     * enough free space to prevent system-wide SQLite failures.
1835     *
1836     * <p class="note">This is a protected intent that can only be sent
1837     * by the system.
1838     *
1839     * {@hide}
1840     */
1841    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1842    public static final String ACTION_DEVICE_STORAGE_FULL = "android.intent.action.DEVICE_STORAGE_FULL";
1843    /**
1844     * Broadcast Action:  Indicates memory full condition on the device
1845     * no longer exists.
1846     *
1847     * <p class="note">This is a protected intent that can only be sent
1848     * by the system.
1849     *
1850     * {@hide}
1851     */
1852    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1853    public static final String ACTION_DEVICE_STORAGE_NOT_FULL = "android.intent.action.DEVICE_STORAGE_NOT_FULL";
1854    /**
1855     * Broadcast Action:  Indicates low memory condition notification acknowledged by user
1856     * and package management should be started.
1857     * This is triggered by the user from the ACTION_DEVICE_STORAGE_LOW
1858     * notification.
1859     */
1860    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1861    public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
1862    /**
1863     * Broadcast Action:  The device has entered USB Mass Storage mode.
1864     * This is used mainly for the USB Settings panel.
1865     * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1866     * when the SD card file system is mounted or unmounted
1867     * @deprecated replaced by android.os.storage.StorageEventListener
1868     */
1869    @Deprecated
1870    public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
1871
1872    /**
1873     * Broadcast Action:  The device has exited USB Mass Storage mode.
1874     * This is used mainly for the USB Settings panel.
1875     * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1876     * when the SD card file system is mounted or unmounted
1877     * @deprecated replaced by android.os.storage.StorageEventListener
1878     */
1879    @Deprecated
1880    public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
1881
1882    /**
1883     * Broadcast Action:  External media has been removed.
1884     * The path to the mount point for the removed media is contained in the Intent.mData field.
1885     */
1886    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1887    public static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
1888
1889    /**
1890     * Broadcast Action:  External media is present, but not mounted at its mount point.
1891     * The path to the mount point for the removed media is contained in the Intent.mData field.
1892     */
1893    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1894    public static final String ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
1895
1896    /**
1897     * Broadcast Action:  External media is present, and being disk-checked
1898     * The path to the mount point for the checking media is contained in the Intent.mData field.
1899     */
1900    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1901    public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
1902
1903    /**
1904     * Broadcast Action:  External media is present, but is using an incompatible fs (or is blank)
1905     * The path to the mount point for the checking media is contained in the Intent.mData field.
1906     */
1907    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1908    public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
1909
1910    /**
1911     * Broadcast Action:  External media is present and mounted at its mount point.
1912     * The path to the mount point for the removed media is contained in the Intent.mData field.
1913     * The Intent contains an extra with name "read-only" and Boolean value to indicate if the
1914     * media was mounted read only.
1915     */
1916    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1917    public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
1918
1919    /**
1920     * Broadcast Action:  External media is unmounted because it is being shared via USB mass storage.
1921     * The path to the mount point for the shared media is contained in the Intent.mData field.
1922     */
1923    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1924    public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
1925
1926    /**
1927     * Broadcast Action:  External media is no longer being shared via USB mass storage.
1928     * The path to the mount point for the previously shared media is contained in the Intent.mData field.
1929     *
1930     * @hide
1931     */
1932    public static final String ACTION_MEDIA_UNSHARED = "android.intent.action.MEDIA_UNSHARED";
1933
1934    /**
1935     * Broadcast Action:  External media was removed from SD card slot, but mount point was not unmounted.
1936     * The path to the mount point for the removed media is contained in the Intent.mData field.
1937     */
1938    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1939    public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
1940
1941    /**
1942     * Broadcast Action:  External media is present but cannot be mounted.
1943     * The path to the mount point for the removed media is contained in the Intent.mData field.
1944     */
1945    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1946    public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
1947
1948   /**
1949     * Broadcast Action:  User has expressed the desire to remove the external storage media.
1950     * Applications should close all files they have open within the mount point when they receive this intent.
1951     * The path to the mount point for the media to be ejected is contained in the Intent.mData field.
1952     */
1953    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1954    public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
1955
1956    /**
1957     * Broadcast Action:  The media scanner has started scanning a directory.
1958     * The path to the directory being scanned is contained in the Intent.mData field.
1959     */
1960    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1961    public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
1962
1963   /**
1964     * Broadcast Action:  The media scanner has finished scanning a directory.
1965     * The path to the scanned directory is contained in the Intent.mData field.
1966     */
1967    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1968    public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
1969
1970   /**
1971     * Broadcast Action:  Request the media scanner to scan a file and add it to the media database.
1972     * The path to the file is contained in the Intent.mData field.
1973     */
1974    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1975    public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
1976
1977   /**
1978     * Broadcast Action:  The "Media Button" was pressed.  Includes a single
1979     * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1980     * caused the broadcast.
1981     */
1982    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1983    public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
1984
1985    /**
1986     * Broadcast Action:  The "Camera Button" was pressed.  Includes a single
1987     * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1988     * caused the broadcast.
1989     */
1990    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1991    public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
1992
1993    // *** NOTE: @todo(*) The following really should go into a more domain-specific
1994    // location; they are not general-purpose actions.
1995
1996    /**
1997     * Broadcast Action: A GTalk connection has been established.
1998     */
1999    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2000    public static final String ACTION_GTALK_SERVICE_CONNECTED =
2001            "android.intent.action.GTALK_CONNECTED";
2002
2003    /**
2004     * Broadcast Action: A GTalk connection has been disconnected.
2005     */
2006    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2007    public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
2008            "android.intent.action.GTALK_DISCONNECTED";
2009
2010    /**
2011     * Broadcast Action: An input method has been changed.
2012     */
2013    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2014    public static final String ACTION_INPUT_METHOD_CHANGED =
2015            "android.intent.action.INPUT_METHOD_CHANGED";
2016
2017    /**
2018     * <p>Broadcast Action: The user has switched the phone into or out of Airplane Mode. One or
2019     * more radios have been turned off or on. The intent will have the following extra value:</p>
2020     * <ul>
2021     *   <li><em>state</em> - A boolean value indicating whether Airplane Mode is on. If true,
2022     *   then cell radio and possibly other radios such as bluetooth or WiFi may have also been
2023     *   turned off</li>
2024     * </ul>
2025     *
2026     * <p class="note">This is a protected intent that can only be sent
2027     * by the system.
2028     */
2029    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2030    public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
2031
2032    /**
2033     * Broadcast Action: Some content providers have parts of their namespace
2034     * where they publish new events or items that the user may be especially
2035     * interested in. For these things, they may broadcast this action when the
2036     * set of interesting items change.
2037     *
2038     * For example, GmailProvider sends this notification when the set of unread
2039     * mail in the inbox changes.
2040     *
2041     * <p>The data of the intent identifies which part of which provider
2042     * changed. When queried through the content resolver, the data URI will
2043     * return the data set in question.
2044     *
2045     * <p>The intent will have the following extra values:
2046     * <ul>
2047     *   <li><em>count</em> - The number of items in the data set. This is the
2048     *       same as the number of items in the cursor returned by querying the
2049     *       data URI. </li>
2050     * </ul>
2051     *
2052     * This intent will be sent at boot (if the count is non-zero) and when the
2053     * data set changes. It is possible for the data set to change without the
2054     * count changing (for example, if a new unread message arrives in the same
2055     * sync operation in which a message is archived). The phone should still
2056     * ring/vibrate/etc as normal in this case.
2057     */
2058    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2059    public static final String ACTION_PROVIDER_CHANGED =
2060            "android.intent.action.PROVIDER_CHANGED";
2061
2062    /**
2063     * Broadcast Action: Wired Headset plugged in or unplugged.
2064     *
2065     * <p>The intent will have the following extra values:
2066     * <ul>
2067     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
2068     *   <li><em>name</em> - Headset type, human readable string </li>
2069     *   <li><em>microphone</em> - 1 if headset has a microphone, 0 otherwise </li>
2070     * </ul>
2071     * </ul>
2072     */
2073    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2074    public static final String ACTION_HEADSET_PLUG =
2075            "android.intent.action.HEADSET_PLUG";
2076
2077    /**
2078     * Broadcast Action: An analog audio speaker/headset plugged in or unplugged.
2079     *
2080     * <p>The intent will have the following extra values:
2081     * <ul>
2082     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
2083     *   <li><em>name</em> - Headset type, human readable string </li>
2084     * </ul>
2085     * </ul>
2086     * @hide
2087     */
2088    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2089    public static final String ACTION_ANALOG_AUDIO_DOCK_PLUG =
2090            "android.intent.action.ANALOG_AUDIO_DOCK_PLUG";
2091
2092    /**
2093     * Broadcast Action: A digital audio speaker/headset plugged in or unplugged.
2094     *
2095     * <p>The intent will have the following extra values:
2096     * <ul>
2097     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
2098     *   <li><em>name</em> - Headset type, human readable string </li>
2099     * </ul>
2100     * </ul>
2101     * @hide
2102     */
2103    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2104    public static final String ACTION_DIGITAL_AUDIO_DOCK_PLUG =
2105            "android.intent.action.DIGITAL_AUDIO_DOCK_PLUG";
2106
2107    /**
2108     * Broadcast Action: A HMDI cable was plugged or unplugged
2109     *
2110     * <p>The intent will have the following extra values:
2111     * <ul>
2112     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
2113     *   <li><em>name</em> - HDMI cable, human readable string </li>
2114     * </ul>
2115     * </ul>
2116     * @hide
2117     */
2118    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2119    public static final String ACTION_HDMI_AUDIO_PLUG =
2120            "android.intent.action.HDMI_AUDIO_PLUG";
2121
2122    /**
2123     * Broadcast Action: A USB audio accessory was plugged in or unplugged.
2124     *
2125     * <p>The intent will have the following extra values:
2126     * <ul>
2127     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
2128     *   <li><em>card</em> - ALSA card number (integer) </li>
2129     *   <li><em>device</em> - ALSA device number (integer) </li>
2130     * </ul>
2131     * </ul>
2132     * @hide
2133     */
2134    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2135    public static final String ACTION_USB_AUDIO_ACCESSORY_PLUG =
2136            "android.intent.action.USB_AUDIO_ACCESSORY_PLUG";
2137
2138    /**
2139     * Broadcast Action: A USB audio device was plugged in or unplugged.
2140     *
2141     * <p>The intent will have the following extra values:
2142     * <ul>
2143     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
2144     *   <li><em>card</em> - ALSA card number (integer) </li>
2145     *   <li><em>device</em> - ALSA device number (integer) </li>
2146     * </ul>
2147     * </ul>
2148     * @hide
2149     */
2150    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2151    public static final String ACTION_USB_AUDIO_DEVICE_PLUG =
2152            "android.intent.action.USB_AUDIO_DEVICE_PLUG";
2153
2154    /**
2155     * <p>Broadcast Action: The user has switched on advanced settings in the settings app:</p>
2156     * <ul>
2157     *   <li><em>state</em> - A boolean value indicating whether the settings is on or off.</li>
2158     * </ul>
2159     *
2160     * <p class="note">This is a protected intent that can only be sent
2161     * by the system.
2162     *
2163     * @hide
2164     */
2165    //@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2166    public static final String ACTION_ADVANCED_SETTINGS_CHANGED
2167            = "android.intent.action.ADVANCED_SETTINGS";
2168
2169    /**
2170     * Broadcast Action: An outgoing call is about to be placed.
2171     *
2172     * <p>The Intent will have the following extra value:
2173     * <ul>
2174     *   <li><em>{@link android.content.Intent#EXTRA_PHONE_NUMBER}</em> -
2175     *       the phone number originally intended to be dialed.</li>
2176     * </ul>
2177     * <p>Once the broadcast is finished, the resultData is used as the actual
2178     * number to call.  If  <code>null</code>, no call will be placed.</p>
2179     * <p>It is perfectly acceptable for multiple receivers to process the
2180     * outgoing call in turn: for example, a parental control application
2181     * might verify that the user is authorized to place the call at that
2182     * time, then a number-rewriting application might add an area code if
2183     * one was not specified.</p>
2184     * <p>For consistency, any receiver whose purpose is to prohibit phone
2185     * calls should have a priority of 0, to ensure it will see the final
2186     * phone number to be dialed.
2187     * Any receiver whose purpose is to rewrite phone numbers to be called
2188     * should have a positive priority.
2189     * Negative priorities are reserved for the system for this broadcast;
2190     * using them may cause problems.</p>
2191     * <p>Any BroadcastReceiver receiving this Intent <em>must not</em>
2192     * abort the broadcast.</p>
2193     * <p>Emergency calls cannot be intercepted using this mechanism, and
2194     * other calls cannot be modified to call emergency numbers using this
2195     * mechanism.
2196     * <p>You must hold the
2197     * {@link android.Manifest.permission#PROCESS_OUTGOING_CALLS}
2198     * permission to receive this Intent.</p>
2199     *
2200     * <p class="note">This is a protected intent that can only be sent
2201     * by the system.
2202     */
2203    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2204    public static final String ACTION_NEW_OUTGOING_CALL =
2205            "android.intent.action.NEW_OUTGOING_CALL";
2206
2207    /**
2208     * Broadcast Action: Have the device reboot.  This is only for use by
2209     * system code.
2210     *
2211     * <p class="note">This is a protected intent that can only be sent
2212     * by the system.
2213     */
2214    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2215    public static final String ACTION_REBOOT =
2216            "android.intent.action.REBOOT";
2217
2218    /**
2219     * Broadcast Action:  A sticky broadcast for changes in the physical
2220     * docking state of the device.
2221     *
2222     * <p>The intent will have the following extra values:
2223     * <ul>
2224     *   <li><em>{@link #EXTRA_DOCK_STATE}</em> - the current dock
2225     *       state, indicating which dock the device is physically in.</li>
2226     * </ul>
2227     * <p>This is intended for monitoring the current physical dock state.
2228     * See {@link android.app.UiModeManager} for the normal API dealing with
2229     * dock mode changes.
2230     */
2231    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2232    public static final String ACTION_DOCK_EVENT =
2233            "android.intent.action.DOCK_EVENT";
2234
2235    /**
2236     * Broadcast Action: a remote intent is to be broadcasted.
2237     *
2238     * A remote intent is used for remote RPC between devices. The remote intent
2239     * is serialized and sent from one device to another device. The receiving
2240     * device parses the remote intent and broadcasts it. Note that anyone can
2241     * broadcast a remote intent. However, if the intent receiver of the remote intent
2242     * does not trust intent broadcasts from arbitrary intent senders, it should require
2243     * the sender to hold certain permissions so only trusted sender's broadcast will be
2244     * let through.
2245     * @hide
2246     */
2247    public static final String ACTION_REMOTE_INTENT =
2248            "com.google.android.c2dm.intent.RECEIVE";
2249
2250    /**
2251     * Broadcast Action: hook for permforming cleanup after a system update.
2252     *
2253     * The broadcast is sent when the system is booting, before the
2254     * BOOT_COMPLETED broadcast.  It is only sent to receivers in the system
2255     * image.  A receiver for this should do its work and then disable itself
2256     * so that it does not get run again at the next boot.
2257     * @hide
2258     */
2259    public static final String ACTION_PRE_BOOT_COMPLETED =
2260            "android.intent.action.PRE_BOOT_COMPLETED";
2261
2262    /**
2263     * Broadcast sent to the system when a user is added. Carries an extra EXTRA_USERID that has the
2264     * userid of the new user.
2265     * @hide
2266     */
2267    public static final String ACTION_USER_ADDED =
2268            "android.intent.action.USER_ADDED";
2269
2270    /**
2271     * Broadcast sent to the system when a user is removed. Carries an extra EXTRA_USERID that has
2272     * the userid of the user.
2273     * @hide
2274     */
2275    public static final String ACTION_USER_REMOVED =
2276            "android.intent.action.USER_REMOVED";
2277
2278    /**
2279     * Broadcast sent to the system when the user switches. Carries an extra EXTRA_USERID that has
2280     * the userid of the user to become the current one.
2281     * @hide
2282     */
2283    public static final String ACTION_USER_SWITCHED =
2284            "android.intent.action.USER_SWITCHED";
2285
2286    // ---------------------------------------------------------------------
2287    // ---------------------------------------------------------------------
2288    // Standard intent categories (see addCategory()).
2289
2290    /**
2291     * Set if the activity should be an option for the default action
2292     * (center press) to perform on a piece of data.  Setting this will
2293     * hide from the user any activities without it set when performing an
2294     * action on some data.  Note that this is normal -not- set in the
2295     * Intent when initiating an action -- it is for use in intent filters
2296     * specified in packages.
2297     */
2298    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2299    public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
2300    /**
2301     * Activities that can be safely invoked from a browser must support this
2302     * category.  For example, if the user is viewing a web page or an e-mail
2303     * and clicks on a link in the text, the Intent generated execute that
2304     * link will require the BROWSABLE category, so that only activities
2305     * supporting this category will be considered as possible actions.  By
2306     * supporting this category, you are promising that there is nothing
2307     * damaging (without user intervention) that can happen by invoking any
2308     * matching Intent.
2309     */
2310    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2311    public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
2312    /**
2313     * Set if the activity should be considered as an alternative action to
2314     * the data the user is currently viewing.  See also
2315     * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
2316     * applies to the selection in a list of items.
2317     *
2318     * <p>Supporting this category means that you would like your activity to be
2319     * displayed in the set of alternative things the user can do, usually as
2320     * part of the current activity's options menu.  You will usually want to
2321     * include a specific label in the &lt;intent-filter&gt; of this action
2322     * describing to the user what it does.
2323     *
2324     * <p>The action of IntentFilter with this category is important in that it
2325     * describes the specific action the target will perform.  This generally
2326     * should not be a generic action (such as {@link #ACTION_VIEW}, but rather
2327     * a specific name such as "com.android.camera.action.CROP.  Only one
2328     * alternative of any particular action will be shown to the user, so using
2329     * a specific action like this makes sure that your alternative will be
2330     * displayed while also allowing other applications to provide their own
2331     * overrides of that particular action.
2332     */
2333    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2334    public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
2335    /**
2336     * Set if the activity should be considered as an alternative selection
2337     * action to the data the user has currently selected.  This is like
2338     * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list
2339     * of items from which the user can select, giving them alternatives to the
2340     * default action that will be performed on it.
2341     */
2342    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2343    public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
2344    /**
2345     * Intended to be used as a tab inside of a containing TabActivity.
2346     */
2347    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2348    public static final String CATEGORY_TAB = "android.intent.category.TAB";
2349    /**
2350     * Should be displayed in the top-level launcher.
2351     */
2352    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2353    public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
2354    /**
2355     * Provides information about the package it is in; typically used if
2356     * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
2357     * a front-door to the user without having to be shown in the all apps list.
2358     */
2359    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2360    public static final String CATEGORY_INFO = "android.intent.category.INFO";
2361    /**
2362     * This is the home activity, that is the first activity that is displayed
2363     * when the device boots.
2364     */
2365    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2366    public static final String CATEGORY_HOME = "android.intent.category.HOME";
2367    /**
2368     * This activity is a preference panel.
2369     */
2370    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2371    public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
2372    /**
2373     * This activity is a development preference panel.
2374     */
2375    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2376    public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
2377    /**
2378     * Capable of running inside a parent activity container.
2379     */
2380    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2381    public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
2382    /**
2383     * This activity allows the user to browse and download new applications.
2384     */
2385    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2386    public static final String CATEGORY_APP_MARKET = "android.intent.category.APP_MARKET";
2387    /**
2388     * This activity may be exercised by the monkey or other automated test tools.
2389     */
2390    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2391    public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
2392    /**
2393     * To be used as a test (not part of the normal user experience).
2394     */
2395    public static final String CATEGORY_TEST = "android.intent.category.TEST";
2396    /**
2397     * To be used as a unit test (run through the Test Harness).
2398     */
2399    public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
2400    /**
2401     * To be used as a sample code example (not part of the normal user
2402     * experience).
2403     */
2404    public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
2405    /**
2406     * Used to indicate that a GET_CONTENT intent only wants URIs that can be opened with
2407     * ContentResolver.openInputStream. Openable URIs must support the columns in OpenableColumns
2408     * when queried, though it is allowable for those columns to be blank.
2409     */
2410    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2411    public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
2412
2413    /**
2414     * To be used as code under test for framework instrumentation tests.
2415     */
2416    public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
2417            "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
2418    /**
2419     * An activity to run when device is inserted into a car dock.
2420     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
2421     * information, see {@link android.app.UiModeManager}.
2422     */
2423    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2424    public static final String CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
2425    /**
2426     * An activity to run when device is inserted into a car dock.
2427     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
2428     * information, see {@link android.app.UiModeManager}.
2429     */
2430    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2431    public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
2432    /**
2433     * An activity to run when device is inserted into a analog (low end) dock.
2434     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
2435     * information, see {@link android.app.UiModeManager}.
2436     */
2437    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2438    public static final String CATEGORY_LE_DESK_DOCK = "android.intent.category.LE_DESK_DOCK";
2439
2440    /**
2441     * An activity to run when device is inserted into a digital (high end) dock.
2442     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
2443     * information, see {@link android.app.UiModeManager}.
2444     */
2445    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2446    public static final String CATEGORY_HE_DESK_DOCK = "android.intent.category.HE_DESK_DOCK";
2447
2448    /**
2449     * Used to indicate that the activity can be used in a car environment.
2450     */
2451    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2452    public static final String CATEGORY_CAR_MODE = "android.intent.category.CAR_MODE";
2453
2454    // ---------------------------------------------------------------------
2455    // ---------------------------------------------------------------------
2456    // Application launch intent categories (see addCategory()).
2457
2458    /**
2459     * Used with {@link #ACTION_MAIN} to launch the browser application.
2460     * The activity should be able to browse the Internet.
2461     * <p>NOTE: This should not be used as the primary key of an Intent,
2462     * since it will not result in the app launching with the correct
2463     * action and category.  Instead, use this with
2464     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2465     * Intent with this category in the selector.</p>
2466     */
2467    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2468    public static final String CATEGORY_APP_BROWSER = "android.intent.category.APP_BROWSER";
2469
2470    /**
2471     * Used with {@link #ACTION_MAIN} to launch the calculator application.
2472     * The activity should be able to perform standard arithmetic operations.
2473     * <p>NOTE: This should not be used as the primary key of an Intent,
2474     * since it will not result in the app launching with the correct
2475     * action and category.  Instead, use this with
2476     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2477     * Intent with this category in the selector.</p>
2478     */
2479    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2480    public static final String CATEGORY_APP_CALCULATOR = "android.intent.category.APP_CALCULATOR";
2481
2482    /**
2483     * Used with {@link #ACTION_MAIN} to launch the calendar application.
2484     * The activity should be able to view and manipulate calendar entries.
2485     * <p>NOTE: This should not be used as the primary key of an Intent,
2486     * since it will not result in the app launching with the correct
2487     * action and category.  Instead, use this with
2488     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2489     * Intent with this category in the selector.</p>
2490     */
2491    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2492    public static final String CATEGORY_APP_CALENDAR = "android.intent.category.APP_CALENDAR";
2493
2494    /**
2495     * Used with {@link #ACTION_MAIN} to launch the contacts application.
2496     * The activity should be able to view and manipulate address book entries.
2497     * <p>NOTE: This should not be used as the primary key of an Intent,
2498     * since it will not result in the app launching with the correct
2499     * action and category.  Instead, use this with
2500     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2501     * Intent with this category in the selector.</p>
2502     */
2503    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2504    public static final String CATEGORY_APP_CONTACTS = "android.intent.category.APP_CONTACTS";
2505
2506    /**
2507     * Used with {@link #ACTION_MAIN} to launch the email application.
2508     * The activity should be able to send and receive email.
2509     * <p>NOTE: This should not be used as the primary key of an Intent,
2510     * since it will not result in the app launching with the correct
2511     * action and category.  Instead, use this with
2512     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2513     * Intent with this category in the selector.</p>
2514     */
2515    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2516    public static final String CATEGORY_APP_EMAIL = "android.intent.category.APP_EMAIL";
2517
2518    /**
2519     * Used with {@link #ACTION_MAIN} to launch the gallery application.
2520     * The activity should be able to view and manipulate image and video files
2521     * stored on the device.
2522     * <p>NOTE: This should not be used as the primary key of an Intent,
2523     * since it will not result in the app launching with the correct
2524     * action and category.  Instead, use this with
2525     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2526     * Intent with this category in the selector.</p>
2527     */
2528    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2529    public static final String CATEGORY_APP_GALLERY = "android.intent.category.APP_GALLERY";
2530
2531    /**
2532     * Used with {@link #ACTION_MAIN} to launch the maps application.
2533     * The activity should be able to show the user's current location and surroundings.
2534     * <p>NOTE: This should not be used as the primary key of an Intent,
2535     * since it will not result in the app launching with the correct
2536     * action and category.  Instead, use this with
2537     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2538     * Intent with this category in the selector.</p>
2539     */
2540    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2541    public static final String CATEGORY_APP_MAPS = "android.intent.category.APP_MAPS";
2542
2543    /**
2544     * Used with {@link #ACTION_MAIN} to launch the messaging application.
2545     * The activity should be able to send and receive text messages.
2546     * <p>NOTE: This should not be used as the primary key of an Intent,
2547     * since it will not result in the app launching with the correct
2548     * action and category.  Instead, use this with
2549     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2550     * Intent with this category in the selector.</p>
2551     */
2552    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2553    public static final String CATEGORY_APP_MESSAGING = "android.intent.category.APP_MESSAGING";
2554
2555    /**
2556     * Used with {@link #ACTION_MAIN} to launch the music application.
2557     * The activity should be able to play, browse, or manipulate music files
2558     * stored on the device.
2559     * <p>NOTE: This should not be used as the primary key of an Intent,
2560     * since it will not result in the app launching with the correct
2561     * action and category.  Instead, use this with
2562     * {@link #makeMainSelectorActivity(String, String)} to generate a main
2563     * Intent with this category in the selector.</p>
2564     */
2565    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
2566    public static final String CATEGORY_APP_MUSIC = "android.intent.category.APP_MUSIC";
2567
2568    // ---------------------------------------------------------------------
2569    // ---------------------------------------------------------------------
2570    // Standard extra data keys.
2571
2572    /**
2573     * The initial data to place in a newly created record.  Use with
2574     * {@link #ACTION_INSERT}.  The data here is a Map containing the same
2575     * fields as would be given to the underlying ContentProvider.insert()
2576     * call.
2577     */
2578    public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
2579
2580    /**
2581     * A constant CharSequence that is associated with the Intent, used with
2582     * {@link #ACTION_SEND} to supply the literal data to be sent.  Note that
2583     * this may be a styled CharSequence, so you must use
2584     * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to
2585     * retrieve it.
2586     */
2587    public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
2588
2589    /**
2590     * A constant String that is associated with the Intent, used with
2591     * {@link #ACTION_SEND} to supply an alternative to {@link #EXTRA_TEXT}
2592     * as HTML formatted text.  Note that you <em>must</em> also supply
2593     * {@link #EXTRA_TEXT}.
2594     */
2595    public static final String EXTRA_HTML_TEXT = "android.intent.extra.HTML_TEXT";
2596
2597    /**
2598     * A content: URI holding a stream of data associated with the Intent,
2599     * used with {@link #ACTION_SEND} to supply the data being sent.
2600     */
2601    public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
2602
2603    /**
2604     * A String[] holding e-mail addresses that should be delivered to.
2605     */
2606    public static final String EXTRA_EMAIL       = "android.intent.extra.EMAIL";
2607
2608    /**
2609     * A String[] holding e-mail addresses that should be carbon copied.
2610     */
2611    public static final String EXTRA_CC       = "android.intent.extra.CC";
2612
2613    /**
2614     * A String[] holding e-mail addresses that should be blind carbon copied.
2615     */
2616    public static final String EXTRA_BCC      = "android.intent.extra.BCC";
2617
2618    /**
2619     * A constant string holding the desired subject line of a message.
2620     */
2621    public static final String EXTRA_SUBJECT  = "android.intent.extra.SUBJECT";
2622
2623    /**
2624     * An Intent describing the choices you would like shown with
2625     * {@link #ACTION_PICK_ACTIVITY}.
2626     */
2627    public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
2628
2629    /**
2630     * A CharSequence dialog title to provide to the user when used with a
2631     * {@link #ACTION_CHOOSER}.
2632     */
2633    public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
2634
2635    /**
2636     * A Parcelable[] of {@link Intent} or
2637     * {@link android.content.pm.LabeledIntent} objects as set with
2638     * {@link #putExtra(String, Parcelable[])} of additional activities to place
2639     * a the front of the list of choices, when shown to the user with a
2640     * {@link #ACTION_CHOOSER}.
2641     */
2642    public static final String EXTRA_INITIAL_INTENTS = "android.intent.extra.INITIAL_INTENTS";
2643
2644    /**
2645     * A {@link android.view.KeyEvent} object containing the event that
2646     * triggered the creation of the Intent it is in.
2647     */
2648    public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
2649
2650    /**
2651     * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to request confirmation from the user
2652     * before shutting down.
2653     *
2654     * {@hide}
2655     */
2656    public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";
2657
2658    /**
2659     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
2660     * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
2661     * of restarting the application.
2662     */
2663    public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
2664
2665    /**
2666     * A String holding the phone number originally entered in
2667     * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual
2668     * number to call in a {@link android.content.Intent#ACTION_CALL}.
2669     */
2670    public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
2671
2672    /**
2673     * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED}
2674     * intents to supply the uid the package had been assigned.  Also an optional
2675     * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
2676     * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same
2677     * purpose.
2678     */
2679    public static final String EXTRA_UID = "android.intent.extra.UID";
2680
2681    /**
2682     * @hide String array of package names.
2683     */
2684    public static final String EXTRA_PACKAGES = "android.intent.extra.PACKAGES";
2685
2686    /**
2687     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
2688     * intents to indicate whether this represents a full uninstall (removing
2689     * both the code and its data) or a partial uninstall (leaving its data,
2690     * implying that this is an update).
2691     */
2692    public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
2693
2694    /**
2695     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
2696     * intents to indicate that this is a replacement of the package, so this
2697     * broadcast will immediately be followed by an add broadcast for a
2698     * different version of the same package.
2699     */
2700    public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
2701
2702    /**
2703     * Used as an int extra field in {@link android.app.AlarmManager} intents
2704     * to tell the application being invoked how many pending alarms are being
2705     * delievered with the intent.  For one-shot alarms this will always be 1.
2706     * For recurring alarms, this might be greater than 1 if the device was
2707     * asleep or powered off at the time an earlier alarm would have been
2708     * delivered.
2709     */
2710    public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
2711
2712    /**
2713     * Used as an int extra field in {@link android.content.Intent#ACTION_DOCK_EVENT}
2714     * intents to request the dock state.  Possible values are
2715     * {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
2716     * {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
2717     * {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}, or
2718     * {@link android.content.Intent#EXTRA_DOCK_STATE_LE_DESK}, or
2719     * {@link android.content.Intent#EXTRA_DOCK_STATE_HE_DESK}.
2720     */
2721    public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
2722
2723    /**
2724     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2725     * to represent that the phone is not in any dock.
2726     */
2727    public static final int EXTRA_DOCK_STATE_UNDOCKED = 0;
2728
2729    /**
2730     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2731     * to represent that the phone is in a desk dock.
2732     */
2733    public static final int EXTRA_DOCK_STATE_DESK = 1;
2734
2735    /**
2736     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2737     * to represent that the phone is in a car dock.
2738     */
2739    public static final int EXTRA_DOCK_STATE_CAR = 2;
2740
2741    /**
2742     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2743     * to represent that the phone is in a analog (low end) dock.
2744     */
2745    public static final int EXTRA_DOCK_STATE_LE_DESK = 3;
2746
2747    /**
2748     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2749     * to represent that the phone is in a digital (high end) dock.
2750     */
2751    public static final int EXTRA_DOCK_STATE_HE_DESK = 4;
2752
2753    /**
2754     * Boolean that can be supplied as meta-data with a dock activity, to
2755     * indicate that the dock should take over the home key when it is active.
2756     */
2757    public static final String METADATA_DOCK_HOME = "android.dock_home";
2758
2759    /**
2760     * Used as a parcelable extra field in {@link #ACTION_APP_ERROR}, containing
2761     * the bug report.
2762     */
2763    public static final String EXTRA_BUG_REPORT = "android.intent.extra.BUG_REPORT";
2764
2765    /**
2766     * Used in the extra field in the remote intent. It's astring token passed with the
2767     * remote intent.
2768     */
2769    public static final String EXTRA_REMOTE_INTENT_TOKEN =
2770            "android.intent.extra.remote_intent_token";
2771
2772    /**
2773     * @deprecated See {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST}; this field
2774     * will contain only the first name in the list.
2775     */
2776    @Deprecated public static final String EXTRA_CHANGED_COMPONENT_NAME =
2777            "android.intent.extra.changed_component_name";
2778
2779    /**
2780     * This field is part of {@link android.content.Intent#ACTION_PACKAGE_CHANGED},
2781     * and contains a string array of all of the components that have changed.
2782     */
2783    public static final String EXTRA_CHANGED_COMPONENT_NAME_LIST =
2784            "android.intent.extra.changed_component_name_list";
2785
2786    /**
2787     * This field is part of
2788     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_AVAILABLE},
2789     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE}
2790     * and contains a string array of all of the components that have changed.
2791     */
2792    public static final String EXTRA_CHANGED_PACKAGE_LIST =
2793            "android.intent.extra.changed_package_list";
2794
2795    /**
2796     * This field is part of
2797     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_AVAILABLE},
2798     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE}
2799     * and contains an integer array of uids of all of the components
2800     * that have changed.
2801     */
2802    public static final String EXTRA_CHANGED_UID_LIST =
2803            "android.intent.extra.changed_uid_list";
2804
2805    /**
2806     * @hide
2807     * Magic extra system code can use when binding, to give a label for
2808     * who it is that has bound to a service.  This is an integer giving
2809     * a framework string resource that can be displayed to the user.
2810     */
2811    public static final String EXTRA_CLIENT_LABEL =
2812            "android.intent.extra.client_label";
2813
2814    /**
2815     * @hide
2816     * Magic extra system code can use when binding, to give a PendingIntent object
2817     * that can be launched for the user to disable the system's use of this
2818     * service.
2819     */
2820    public static final String EXTRA_CLIENT_INTENT =
2821            "android.intent.extra.client_intent";
2822
2823    /**
2824     * Used to indicate that a {@link #ACTION_GET_CONTENT} intent should only return
2825     * data that is on the local device.  This is a boolean extra; the default
2826     * is false.  If true, an implementation of ACTION_GET_CONTENT should only allow
2827     * the user to select media that is already on the device, not requiring it
2828     * be downloaded from a remote service when opened.  Another way to look
2829     * at it is that such content should generally have a "_data" column to the
2830     * path of the content on local external storage.
2831     */
2832    public static final String EXTRA_LOCAL_ONLY =
2833        "android.intent.extra.LOCAL_ONLY";
2834
2835    /**
2836     * The userid carried with broadcast intents related to addition, removal and switching of users
2837     * - {@link #ACTION_USER_ADDED}, {@link #ACTION_USER_REMOVED} and {@link #ACTION_USER_SWITCHED}.
2838     * @hide
2839     */
2840    public static final String EXTRA_USERID =
2841            "android.intent.extra.user_id";
2842    // ---------------------------------------------------------------------
2843    // ---------------------------------------------------------------------
2844    // Intent flags (see mFlags variable).
2845
2846    /**
2847     * If set, the recipient of this Intent will be granted permission to
2848     * perform read operations on the Uri in the Intent's data and any URIs
2849     * specified in its ClipData.  When applying to an Intent's ClipData,
2850     * all URIs as well as recursive traversals through data or other ClipData
2851     * in Intent items will be granted; only the grant flags of the top-level
2852     * Intent are used.
2853     */
2854    public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
2855    /**
2856     * If set, the recipient of this Intent will be granted permission to
2857     * perform write operations on the Uri in the Intent's data and any URIs
2858     * specified in its ClipData.  When applying to an Intent's ClipData,
2859     * all URIs as well as recursive traversals through data or other ClipData
2860     * in Intent items will be granted; only the grant flags of the top-level
2861     * Intent are used.
2862     */
2863    public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
2864    /**
2865     * Can be set by the caller to indicate that this Intent is coming from
2866     * a background operation, not from direct user interaction.
2867     */
2868    public static final int FLAG_FROM_BACKGROUND = 0x00000004;
2869    /**
2870     * A flag you can enable for debugging: when set, log messages will be
2871     * printed during the resolution of this intent to show you what has
2872     * been found to create the final resolved list.
2873     */
2874    public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
2875    /**
2876     * If set, this intent will not match any components in packages that
2877     * are currently stopped.  If this is not set, then the default behavior
2878     * is to include such applications in the result.
2879     */
2880    public static final int FLAG_EXCLUDE_STOPPED_PACKAGES = 0x00000010;
2881    /**
2882     * If set, this intent will always match any components in packages that
2883     * are currently stopped.  This is the default behavior when
2884     * {@link #FLAG_EXCLUDE_STOPPED_PACKAGES} is not set.  If both of these
2885     * flags are set, this one wins (it allows overriding of exclude for
2886     * places where the framework may automatically set the exclude flag).
2887     */
2888    public static final int FLAG_INCLUDE_STOPPED_PACKAGES = 0x00000020;
2889
2890    /**
2891     * If set, the new activity is not kept in the history stack.  As soon as
2892     * the user navigates away from it, the activity is finished.  This may also
2893     * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
2894     * noHistory} attribute.
2895     */
2896    public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
2897    /**
2898     * If set, the activity will not be launched if it is already running
2899     * at the top of the history stack.
2900     */
2901    public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
2902    /**
2903     * If set, this activity will become the start of a new task on this
2904     * history stack.  A task (from the activity that started it to the
2905     * next task activity) defines an atomic group of activities that the
2906     * user can move to.  Tasks can be moved to the foreground and background;
2907     * all of the activities inside of a particular task always remain in
2908     * the same order.  See
2909     * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
2910     * Stack</a> for more information about tasks.
2911     *
2912     * <p>This flag is generally used by activities that want
2913     * to present a "launcher" style behavior: they give the user a list of
2914     * separate things that can be done, which otherwise run completely
2915     * independently of the activity launching them.
2916     *
2917     * <p>When using this flag, if a task is already running for the activity
2918     * you are now starting, then a new activity will not be started; instead,
2919     * the current task will simply be brought to the front of the screen with
2920     * the state it was last in.  See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
2921     * to disable this behavior.
2922     *
2923     * <p>This flag can not be used when the caller is requesting a result from
2924     * the activity being launched.
2925     */
2926    public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
2927    /**
2928     * <strong>Do not use this flag unless you are implementing your own
2929     * top-level application launcher.</strong>  Used in conjunction with
2930     * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the
2931     * behavior of bringing an existing task to the foreground.  When set,
2932     * a new task is <em>always</em> started to host the Activity for the
2933     * Intent, regardless of whether there is already an existing task running
2934     * the same thing.
2935     *
2936     * <p><strong>Because the default system does not include graphical task management,
2937     * you should not use this flag unless you provide some way for a user to
2938     * return back to the tasks you have launched.</strong>
2939     *
2940     * <p>This flag is ignored if
2941     * {@link #FLAG_ACTIVITY_NEW_TASK} is not set.
2942     *
2943     * <p>See
2944     * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
2945     * Stack</a> for more information about tasks.
2946     */
2947    public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
2948    /**
2949     * If set, and the activity being launched is already running in the
2950     * current task, then instead of launching a new instance of that activity,
2951     * all of the other activities on top of it will be closed and this Intent
2952     * will be delivered to the (now on top) old activity as a new Intent.
2953     *
2954     * <p>For example, consider a task consisting of the activities: A, B, C, D.
2955     * If D calls startActivity() with an Intent that resolves to the component
2956     * of activity B, then C and D will be finished and B receive the given
2957     * Intent, resulting in the stack now being: A, B.
2958     *
2959     * <p>The currently running instance of activity B in the above example will
2960     * either receive the new intent you are starting here in its
2961     * onNewIntent() method, or be itself finished and restarted with the
2962     * new intent.  If it has declared its launch mode to be "multiple" (the
2963     * default) and you have not set {@link #FLAG_ACTIVITY_SINGLE_TOP} in
2964     * the same intent, then it will be finished and re-created; for all other
2965     * launch modes or if {@link #FLAG_ACTIVITY_SINGLE_TOP} is set then this
2966     * Intent will be delivered to the current instance's onNewIntent().
2967     *
2968     * <p>This launch mode can also be used to good effect in conjunction with
2969     * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity
2970     * of a task, it will bring any currently running instance of that task
2971     * to the foreground, and then clear it to its root state.  This is
2972     * especially useful, for example, when launching an activity from the
2973     * notification manager.
2974     *
2975     * <p>See
2976     * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
2977     * Stack</a> for more information about tasks.
2978     */
2979    public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
2980    /**
2981     * If set and this intent is being used to launch a new activity from an
2982     * existing one, then the reply target of the existing activity will be
2983     * transfered to the new activity.  This way the new activity can call
2984     * {@link android.app.Activity#setResult} and have that result sent back to
2985     * the reply target of the original activity.
2986     */
2987    public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
2988    /**
2989     * If set and this intent is being used to launch a new activity from an
2990     * existing one, the current activity will not be counted as the top
2991     * activity for deciding whether the new intent should be delivered to
2992     * the top instead of starting a new one.  The previous activity will
2993     * be used as the top, with the assumption being that the current activity
2994     * will finish itself immediately.
2995     */
2996    public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
2997    /**
2998     * If set, the new activity is not kept in the list of recently launched
2999     * activities.
3000     */
3001    public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
3002    /**
3003     * This flag is not normally set by application code, but set for you by
3004     * the system as described in the
3005     * {@link android.R.styleable#AndroidManifestActivity_launchMode
3006     * launchMode} documentation for the singleTask mode.
3007     */
3008    public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
3009    /**
3010     * If set, and this activity is either being started in a new task or
3011     * bringing to the top an existing task, then it will be launched as
3012     * the front door of the task.  This will result in the application of
3013     * any affinities needed to have that task in the proper state (either
3014     * moving activities to or from it), or simply resetting that task to
3015     * its initial state if needed.
3016     */
3017    public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
3018    /**
3019     * This flag is not normally set by application code, but set for you by
3020     * the system if this activity is being launched from history
3021     * (longpress home key).
3022     */
3023    public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
3024    /**
3025     * If set, this marks a point in the task's activity stack that should
3026     * be cleared when the task is reset.  That is, the next time the task
3027     * is brought to the foreground with
3028     * {@link #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED} (typically as a result of
3029     * the user re-launching it from home), this activity and all on top of
3030     * it will be finished so that the user does not return to them, but
3031     * instead returns to whatever activity preceeded it.
3032     *
3033     * <p>This is useful for cases where you have a logical break in your
3034     * application.  For example, an e-mail application may have a command
3035     * to view an attachment, which launches an image view activity to
3036     * display it.  This activity should be part of the e-mail application's
3037     * task, since it is a part of the task the user is involved in.  However,
3038     * if the user leaves that task, and later selects the e-mail app from
3039     * home, we may like them to return to the conversation they were
3040     * viewing, not the picture attachment, since that is confusing.  By
3041     * setting this flag when launching the image viewer, that viewer and
3042     * any activities it starts will be removed the next time the user returns
3043     * to mail.
3044     */
3045    public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
3046    /**
3047     * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint}
3048     * callback from occurring on the current frontmost activity before it is
3049     * paused as the newly-started activity is brought to the front.
3050     *
3051     * <p>Typically, an activity can rely on that callback to indicate that an
3052     * explicit user action has caused their activity to be moved out of the
3053     * foreground. The callback marks an appropriate point in the activity's
3054     * lifecycle for it to dismiss any notifications that it intends to display
3055     * "until the user has seen them," such as a blinking LED.
3056     *
3057     * <p>If an activity is ever started via any non-user-driven events such as
3058     * phone-call receipt or an alarm handler, this flag should be passed to {@link
3059     * Context#startActivity Context.startActivity}, ensuring that the pausing
3060     * activity does not think the user has acknowledged its notification.
3061     */
3062    public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
3063    /**
3064     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
3065     * this flag will cause the launched activity to be brought to the front of its
3066     * task's history stack if it is already running.
3067     *
3068     * <p>For example, consider a task consisting of four activities: A, B, C, D.
3069     * If D calls startActivity() with an Intent that resolves to the component
3070     * of activity B, then B will be brought to the front of the history stack,
3071     * with this resulting order:  A, C, D, B.
3072     *
3073     * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also
3074     * specified.
3075     */
3076    public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
3077    /**
3078     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
3079     * this flag will prevent the system from applying an activity transition
3080     * animation to go to the next activity state.  This doesn't mean an
3081     * animation will never run -- if another activity change happens that doesn't
3082     * specify this flag before the activity started here is displayed, then
3083     * that transition will be used.  This flag can be put to good use
3084     * when you are going to do a series of activity operations but the
3085     * animation seen by the user shouldn't be driven by the first activity
3086     * change but rather a later one.
3087     */
3088    public static final int FLAG_ACTIVITY_NO_ANIMATION = 0X00010000;
3089    /**
3090     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
3091     * this flag will cause any existing task that would be associated with the
3092     * activity to be cleared before the activity is started.  That is, the activity
3093     * becomes the new root of an otherwise empty task, and any old activities
3094     * are finished.  This can only be used in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}.
3095     */
3096    public static final int FLAG_ACTIVITY_CLEAR_TASK = 0X00008000;
3097    /**
3098     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
3099     * this flag will cause a newly launching task to be placed on top of the current
3100     * home activity task (if there is one).  That is, pressing back from the task
3101     * will always return the user to home even if that was not the last activity they
3102     * saw.   This can only be used in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}.
3103     */
3104    public static final int FLAG_ACTIVITY_TASK_ON_HOME = 0X00004000;
3105    /**
3106     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
3107     * upon starting the activity the system will also clear any system dialogs that
3108     * are currently shown.  This is intended primarily for any actions that are
3109     * associated with buttons in a notification: tapping on the button to launch
3110     * the activity needs to also dismiss the notification window (which is one
3111     * of the system dialogs); setting this flag on the Intent associated with that
3112     * action will ensure that and other system dialogs are dismissed so that the
3113     * user arrives in the new activity.
3114     */
3115    public static final int FLAG_ACTIVITY_CLOSE_SYSTEM_DIALOGS = 0X00002000;
3116    /**
3117     * If set, when sending a broadcast only registered receivers will be
3118     * called -- no BroadcastReceiver components will be launched.
3119     */
3120    public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
3121    /**
3122     * If set, when sending a broadcast the new broadcast will replace
3123     * any existing pending broadcast that matches it.  Matching is defined
3124     * by {@link Intent#filterEquals(Intent) Intent.filterEquals} returning
3125     * true for the intents of the two broadcasts.  When a match is found,
3126     * the new broadcast (and receivers associated with it) will replace the
3127     * existing one in the pending broadcast list, remaining at the same
3128     * position in the list.
3129     *
3130     * <p>This flag is most typically used with sticky broadcasts, which
3131     * only care about delivering the most recent values of the broadcast
3132     * to their receivers.
3133     */
3134    public static final int FLAG_RECEIVER_REPLACE_PENDING = 0x20000000;
3135    /**
3136     * If set, when sending a broadcast the recipient is allowed to run at
3137     * foreground priority, with a shorter timeout interval.  During normal
3138     * broadcasts the receivers are not automatically hoisted out of the
3139     * background priority class.
3140     */
3141    public static final int FLAG_RECEIVER_FOREGROUND = 0x10000000;
3142    /**
3143     * If set, when sending a broadcast <i>before boot has completed</i> only
3144     * registered receivers will be called -- no BroadcastReceiver components
3145     * will be launched.  Sticky intent state will be recorded properly even
3146     * if no receivers wind up being called.  If {@link #FLAG_RECEIVER_REGISTERED_ONLY}
3147     * is specified in the broadcast intent, this flag is unnecessary.
3148     *
3149     * <p>This flag is only for use by system sevices as a convenience to
3150     * avoid having to implement a more complex mechanism around detection
3151     * of boot completion.
3152     *
3153     * @hide
3154     */
3155    public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x08000000;
3156    /**
3157     * Set when this broadcast is for a boot upgrade, a special mode that
3158     * allows the broadcast to be sent before the system is ready and launches
3159     * the app process with no providers running in it.
3160     * @hide
3161     */
3162    public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x04000000;
3163
3164    /**
3165     * @hide Flags that can't be changed with PendingIntent.
3166     */
3167    public static final int IMMUTABLE_FLAGS =
3168            FLAG_GRANT_READ_URI_PERMISSION
3169            | FLAG_GRANT_WRITE_URI_PERMISSION;
3170
3171    // ---------------------------------------------------------------------
3172    // ---------------------------------------------------------------------
3173    // toUri() and parseUri() options.
3174
3175    /**
3176     * Flag for use with {@link #toUri} and {@link #parseUri}: the URI string
3177     * always has the "intent:" scheme.  This syntax can be used when you want
3178     * to later disambiguate between URIs that are intended to describe an
3179     * Intent vs. all others that should be treated as raw URIs.  When used
3180     * with {@link #parseUri}, any other scheme will result in a generic
3181     * VIEW action for that raw URI.
3182     */
3183    public static final int URI_INTENT_SCHEME = 1<<0;
3184
3185    // ---------------------------------------------------------------------
3186
3187    private String mAction;
3188    private Uri mData;
3189    private String mType;
3190    private String mPackage;
3191    private ComponentName mComponent;
3192    private int mFlags;
3193    private HashSet<String> mCategories;
3194    private Bundle mExtras;
3195    private Rect mSourceBounds;
3196    private Intent mSelector;
3197    private ClipData mClipData;
3198
3199    // ---------------------------------------------------------------------
3200
3201    /**
3202     * Create an empty intent.
3203     */
3204    public Intent() {
3205    }
3206
3207    /**
3208     * Copy constructor.
3209     */
3210    public Intent(Intent o) {
3211        this.mAction = o.mAction;
3212        this.mData = o.mData;
3213        this.mType = o.mType;
3214        this.mPackage = o.mPackage;
3215        this.mComponent = o.mComponent;
3216        this.mFlags = o.mFlags;
3217        if (o.mCategories != null) {
3218            this.mCategories = new HashSet<String>(o.mCategories);
3219        }
3220        if (o.mExtras != null) {
3221            this.mExtras = new Bundle(o.mExtras);
3222        }
3223        if (o.mSourceBounds != null) {
3224            this.mSourceBounds = new Rect(o.mSourceBounds);
3225        }
3226        if (o.mSelector != null) {
3227            this.mSelector = new Intent(o.mSelector);
3228        }
3229        if (o.mClipData != null) {
3230            this.mClipData = new ClipData(o.mClipData);
3231        }
3232    }
3233
3234    @Override
3235    public Object clone() {
3236        return new Intent(this);
3237    }
3238
3239    private Intent(Intent o, boolean all) {
3240        this.mAction = o.mAction;
3241        this.mData = o.mData;
3242        this.mType = o.mType;
3243        this.mPackage = o.mPackage;
3244        this.mComponent = o.mComponent;
3245        if (o.mCategories != null) {
3246            this.mCategories = new HashSet<String>(o.mCategories);
3247        }
3248    }
3249
3250    /**
3251     * Make a clone of only the parts of the Intent that are relevant for
3252     * filter matching: the action, data, type, component, and categories.
3253     */
3254    public Intent cloneFilter() {
3255        return new Intent(this, false);
3256    }
3257
3258    /**
3259     * Create an intent with a given action.  All other fields (data, type,
3260     * class) are null.  Note that the action <em>must</em> be in a
3261     * namespace because Intents are used globally in the system -- for
3262     * example the system VIEW action is android.intent.action.VIEW; an
3263     * application's custom action would be something like
3264     * com.google.app.myapp.CUSTOM_ACTION.
3265     *
3266     * @param action The Intent action, such as ACTION_VIEW.
3267     */
3268    public Intent(String action) {
3269        setAction(action);
3270    }
3271
3272    /**
3273     * Create an intent with a given action and for a given data url.  Note
3274     * that the action <em>must</em> be in a namespace because Intents are
3275     * used globally in the system -- for example the system VIEW action is
3276     * android.intent.action.VIEW; an application's custom action would be
3277     * something like com.google.app.myapp.CUSTOM_ACTION.
3278     *
3279     * <p><em>Note: scheme and host name matching in the Android framework is
3280     * case-sensitive, unlike the formal RFC.  As a result,
3281     * you should always ensure that you write your Uri with these elements
3282     * using lower case letters, and normalize any Uris you receive from
3283     * outside of Android to ensure the scheme and host is lower case.</em></p>
3284     *
3285     * @param action The Intent action, such as ACTION_VIEW.
3286     * @param uri The Intent data URI.
3287     */
3288    public Intent(String action, Uri uri) {
3289        setAction(action);
3290        mData = uri;
3291    }
3292
3293    /**
3294     * Create an intent for a specific component.  All other fields (action, data,
3295     * type, class) are null, though they can be modified later with explicit
3296     * calls.  This provides a convenient way to create an intent that is
3297     * intended to execute a hard-coded class name, rather than relying on the
3298     * system to find an appropriate class for you; see {@link #setComponent}
3299     * for more information on the repercussions of this.
3300     *
3301     * @param packageContext A Context of the application package implementing
3302     * this class.
3303     * @param cls The component class that is to be used for the intent.
3304     *
3305     * @see #setClass
3306     * @see #setComponent
3307     * @see #Intent(String, android.net.Uri , Context, Class)
3308     */
3309    public Intent(Context packageContext, Class<?> cls) {
3310        mComponent = new ComponentName(packageContext, cls);
3311    }
3312
3313    /**
3314     * Create an intent for a specific component with a specified action and data.
3315     * This is equivalent using {@link #Intent(String, android.net.Uri)} to
3316     * construct the Intent and then calling {@link #setClass} to set its
3317     * class.
3318     *
3319     * <p><em>Note: scheme and host name matching in the Android framework is
3320     * case-sensitive, unlike the formal RFC.  As a result,
3321     * you should always ensure that you write your Uri with these elements
3322     * using lower case letters, and normalize any Uris you receive from
3323     * outside of Android to ensure the scheme and host is lower case.</em></p>
3324     *
3325     * @param action The Intent action, such as ACTION_VIEW.
3326     * @param uri The Intent data URI.
3327     * @param packageContext A Context of the application package implementing
3328     * this class.
3329     * @param cls The component class that is to be used for the intent.
3330     *
3331     * @see #Intent(String, android.net.Uri)
3332     * @see #Intent(Context, Class)
3333     * @see #setClass
3334     * @see #setComponent
3335     */
3336    public Intent(String action, Uri uri,
3337            Context packageContext, Class<?> cls) {
3338        setAction(action);
3339        mData = uri;
3340        mComponent = new ComponentName(packageContext, cls);
3341    }
3342
3343    /**
3344     * Create an intent to launch the main (root) activity of a task.  This
3345     * is the Intent that is started when the application's is launched from
3346     * Home.  For anything else that wants to launch an application in the
3347     * same way, it is important that they use an Intent structured the same
3348     * way, and can use this function to ensure this is the case.
3349     *
3350     * <p>The returned Intent has the given Activity component as its explicit
3351     * component, {@link #ACTION_MAIN} as its action, and includes the
3352     * category {@link #CATEGORY_LAUNCHER}.  This does <em>not</em> have
3353     * {@link #FLAG_ACTIVITY_NEW_TASK} set, though typically you will want
3354     * to do that through {@link #addFlags(int)} on the returned Intent.
3355     *
3356     * @param mainActivity The main activity component that this Intent will
3357     * launch.
3358     * @return Returns a newly created Intent that can be used to launch the
3359     * activity as a main application entry.
3360     *
3361     * @see #setClass
3362     * @see #setComponent
3363     */
3364    public static Intent makeMainActivity(ComponentName mainActivity) {
3365        Intent intent = new Intent(ACTION_MAIN);
3366        intent.setComponent(mainActivity);
3367        intent.addCategory(CATEGORY_LAUNCHER);
3368        return intent;
3369    }
3370
3371    /**
3372     * Make an Intent for the main activity of an application, without
3373     * specifying a specific activity to run but giving a selector to find
3374     * the activity.  This results in a final Intent that is structured
3375     * the same as when the application is launched from
3376     * Home.  For anything else that wants to launch an application in the
3377     * same way, it is important that they use an Intent structured the same
3378     * way, and can use this function to ensure this is the case.
3379     *
3380     * <p>The returned Intent has {@link #ACTION_MAIN} as its action, and includes the
3381     * category {@link #CATEGORY_LAUNCHER}.  This does <em>not</em> have
3382     * {@link #FLAG_ACTIVITY_NEW_TASK} set, though typically you will want
3383     * to do that through {@link #addFlags(int)} on the returned Intent.
3384     *
3385     * @param selectorAction The action name of the Intent's selector.
3386     * @param selectorCategory The name of a category to add to the Intent's
3387     * selector.
3388     * @return Returns a newly created Intent that can be used to launch the
3389     * activity as a main application entry.
3390     *
3391     * @see #setSelector(Intent)
3392     */
3393    public static Intent makeMainSelectorActivity(String selectorAction,
3394            String selectorCategory) {
3395        Intent intent = new Intent(ACTION_MAIN);
3396        intent.addCategory(CATEGORY_LAUNCHER);
3397        Intent selector = new Intent();
3398        selector.setAction(selectorAction);
3399        selector.addCategory(selectorCategory);
3400        intent.setSelector(selector);
3401        return intent;
3402    }
3403
3404    /**
3405     * Make an Intent that can be used to re-launch an application's task
3406     * in its base state.  This is like {@link #makeMainActivity(ComponentName)},
3407     * but also sets the flags {@link #FLAG_ACTIVITY_NEW_TASK} and
3408     * {@link #FLAG_ACTIVITY_CLEAR_TASK}.
3409     *
3410     * @param mainActivity The activity component that is the root of the
3411     * task; this is the activity that has been published in the application's
3412     * manifest as the main launcher icon.
3413     *
3414     * @return Returns a newly created Intent that can be used to relaunch the
3415     * activity's task in its root state.
3416     */
3417    public static Intent makeRestartActivityTask(ComponentName mainActivity) {
3418        Intent intent = makeMainActivity(mainActivity);
3419        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3420                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
3421        return intent;
3422    }
3423
3424    /**
3425     * Call {@link #parseUri} with 0 flags.
3426     * @deprecated Use {@link #parseUri} instead.
3427     */
3428    @Deprecated
3429    public static Intent getIntent(String uri) throws URISyntaxException {
3430        return parseUri(uri, 0);
3431    }
3432
3433    /**
3434     * Create an intent from a URI.  This URI may encode the action,
3435     * category, and other intent fields, if it was returned by
3436     * {@link #toUri}.  If the Intent was not generate by toUri(), its data
3437     * will be the entire URI and its action will be ACTION_VIEW.
3438     *
3439     * <p>The URI given here must not be relative -- that is, it must include
3440     * the scheme and full path.
3441     *
3442     * @param uri The URI to turn into an Intent.
3443     * @param flags Additional processing flags.  Either 0 or
3444     * {@link #URI_INTENT_SCHEME}.
3445     *
3446     * @return Intent The newly created Intent object.
3447     *
3448     * @throws URISyntaxException Throws URISyntaxError if the basic URI syntax
3449     * it bad (as parsed by the Uri class) or the Intent data within the
3450     * URI is invalid.
3451     *
3452     * @see #toUri
3453     */
3454    public static Intent parseUri(String uri, int flags) throws URISyntaxException {
3455        int i = 0;
3456        try {
3457            // Validate intent scheme for if requested.
3458            if ((flags&URI_INTENT_SCHEME) != 0) {
3459                if (!uri.startsWith("intent:")) {
3460                    Intent intent = new Intent(ACTION_VIEW);
3461                    try {
3462                        intent.setData(Uri.parse(uri));
3463                    } catch (IllegalArgumentException e) {
3464                        throw new URISyntaxException(uri, e.getMessage());
3465                    }
3466                    return intent;
3467                }
3468            }
3469
3470            // simple case
3471            i = uri.lastIndexOf("#");
3472            if (i == -1) return new Intent(ACTION_VIEW, Uri.parse(uri));
3473
3474            // old format Intent URI
3475            if (!uri.startsWith("#Intent;", i)) return getIntentOld(uri);
3476
3477            // new format
3478            Intent intent = new Intent(ACTION_VIEW);
3479            Intent baseIntent = intent;
3480
3481            // fetch data part, if present
3482            String data = i >= 0 ? uri.substring(0, i) : null;
3483            String scheme = null;
3484            i += "#Intent;".length();
3485
3486            // loop over contents of Intent, all name=value;
3487            while (!uri.startsWith("end", i)) {
3488                int eq = uri.indexOf('=', i);
3489                if (eq < 0) eq = i-1;
3490                int semi = uri.indexOf(';', i);
3491                String value = eq < semi ? Uri.decode(uri.substring(eq + 1, semi)) : "";
3492
3493                // action
3494                if (uri.startsWith("action=", i)) {
3495                    intent.setAction(value);
3496                }
3497
3498                // categories
3499                else if (uri.startsWith("category=", i)) {
3500                    intent.addCategory(value);
3501                }
3502
3503                // type
3504                else if (uri.startsWith("type=", i)) {
3505                    intent.mType = value;
3506                }
3507
3508                // launch flags
3509                else if (uri.startsWith("launchFlags=", i)) {
3510                    intent.mFlags = Integer.decode(value).intValue();
3511                }
3512
3513                // package
3514                else if (uri.startsWith("package=", i)) {
3515                    intent.mPackage = value;
3516                }
3517
3518                // component
3519                else if (uri.startsWith("component=", i)) {
3520                    intent.mComponent = ComponentName.unflattenFromString(value);
3521                }
3522
3523                // scheme
3524                else if (uri.startsWith("scheme=", i)) {
3525                    scheme = value;
3526                }
3527
3528                // source bounds
3529                else if (uri.startsWith("sourceBounds=", i)) {
3530                    intent.mSourceBounds = Rect.unflattenFromString(value);
3531                }
3532
3533                // selector
3534                else if (semi == (i+3) && uri.startsWith("SEL", i)) {
3535                    intent = new Intent();
3536                }
3537
3538                // extra
3539                else {
3540                    String key = Uri.decode(uri.substring(i + 2, eq));
3541                    // create Bundle if it doesn't already exist
3542                    if (intent.mExtras == null) intent.mExtras = new Bundle();
3543                    Bundle b = intent.mExtras;
3544                    // add EXTRA
3545                    if      (uri.startsWith("S.", i)) b.putString(key, value);
3546                    else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
3547                    else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
3548                    else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
3549                    else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
3550                    else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
3551                    else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
3552                    else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
3553                    else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
3554                    else throw new URISyntaxException(uri, "unknown EXTRA type", i);
3555                }
3556
3557                // move to the next item
3558                i = semi + 1;
3559            }
3560
3561            if (intent != baseIntent) {
3562                // The Intent had a selector; fix it up.
3563                baseIntent.setSelector(intent);
3564                intent = baseIntent;
3565            }
3566
3567            if (data != null) {
3568                if (data.startsWith("intent:")) {
3569                    data = data.substring(7);
3570                    if (scheme != null) {
3571                        data = scheme + ':' + data;
3572                    }
3573                }
3574
3575                if (data.length() > 0) {
3576                    try {
3577                        intent.mData = Uri.parse(data);
3578                    } catch (IllegalArgumentException e) {
3579                        throw new URISyntaxException(uri, e.getMessage());
3580                    }
3581                }
3582            }
3583
3584            return intent;
3585
3586        } catch (IndexOutOfBoundsException e) {
3587            throw new URISyntaxException(uri, "illegal Intent URI format", i);
3588        }
3589    }
3590
3591    public static Intent getIntentOld(String uri) throws URISyntaxException {
3592        Intent intent;
3593
3594        int i = uri.lastIndexOf('#');
3595        if (i >= 0) {
3596            String action = null;
3597            final int intentFragmentStart = i;
3598            boolean isIntentFragment = false;
3599
3600            i++;
3601
3602            if (uri.regionMatches(i, "action(", 0, 7)) {
3603                isIntentFragment = true;
3604                i += 7;
3605                int j = uri.indexOf(')', i);
3606                action = uri.substring(i, j);
3607                i = j + 1;
3608            }
3609
3610            intent = new Intent(action);
3611
3612            if (uri.regionMatches(i, "categories(", 0, 11)) {
3613                isIntentFragment = true;
3614                i += 11;
3615                int j = uri.indexOf(')', i);
3616                while (i < j) {
3617                    int sep = uri.indexOf('!', i);
3618                    if (sep < 0) sep = j;
3619                    if (i < sep) {
3620                        intent.addCategory(uri.substring(i, sep));
3621                    }
3622                    i = sep + 1;
3623                }
3624                i = j + 1;
3625            }
3626
3627            if (uri.regionMatches(i, "type(", 0, 5)) {
3628                isIntentFragment = true;
3629                i += 5;
3630                int j = uri.indexOf(')', i);
3631                intent.mType = uri.substring(i, j);
3632                i = j + 1;
3633            }
3634
3635            if (uri.regionMatches(i, "launchFlags(", 0, 12)) {
3636                isIntentFragment = true;
3637                i += 12;
3638                int j = uri.indexOf(')', i);
3639                intent.mFlags = Integer.decode(uri.substring(i, j)).intValue();
3640                i = j + 1;
3641            }
3642
3643            if (uri.regionMatches(i, "component(", 0, 10)) {
3644                isIntentFragment = true;
3645                i += 10;
3646                int j = uri.indexOf(')', i);
3647                int sep = uri.indexOf('!', i);
3648                if (sep >= 0 && sep < j) {
3649                    String pkg = uri.substring(i, sep);
3650                    String cls = uri.substring(sep + 1, j);
3651                    intent.mComponent = new ComponentName(pkg, cls);
3652                }
3653                i = j + 1;
3654            }
3655
3656            if (uri.regionMatches(i, "extras(", 0, 7)) {
3657                isIntentFragment = true;
3658                i += 7;
3659
3660                final int closeParen = uri.indexOf(')', i);
3661                if (closeParen == -1) throw new URISyntaxException(uri,
3662                        "EXTRA missing trailing ')'", i);
3663
3664                while (i < closeParen) {
3665                    // fetch the key value
3666                    int j = uri.indexOf('=', i);
3667                    if (j <= i + 1 || i >= closeParen) {
3668                        throw new URISyntaxException(uri, "EXTRA missing '='", i);
3669                    }
3670                    char type = uri.charAt(i);
3671                    i++;
3672                    String key = uri.substring(i, j);
3673                    i = j + 1;
3674
3675                    // get type-value
3676                    j = uri.indexOf('!', i);
3677                    if (j == -1 || j >= closeParen) j = closeParen;
3678                    if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i);
3679                    String value = uri.substring(i, j);
3680                    i = j;
3681
3682                    // create Bundle if it doesn't already exist
3683                    if (intent.mExtras == null) intent.mExtras = new Bundle();
3684
3685                    // add item to bundle
3686                    try {
3687                        switch (type) {
3688                            case 'S':
3689                                intent.mExtras.putString(key, Uri.decode(value));
3690                                break;
3691                            case 'B':
3692                                intent.mExtras.putBoolean(key, Boolean.parseBoolean(value));
3693                                break;
3694                            case 'b':
3695                                intent.mExtras.putByte(key, Byte.parseByte(value));
3696                                break;
3697                            case 'c':
3698                                intent.mExtras.putChar(key, Uri.decode(value).charAt(0));
3699                                break;
3700                            case 'd':
3701                                intent.mExtras.putDouble(key, Double.parseDouble(value));
3702                                break;
3703                            case 'f':
3704                                intent.mExtras.putFloat(key, Float.parseFloat(value));
3705                                break;
3706                            case 'i':
3707                                intent.mExtras.putInt(key, Integer.parseInt(value));
3708                                break;
3709                            case 'l':
3710                                intent.mExtras.putLong(key, Long.parseLong(value));
3711                                break;
3712                            case 's':
3713                                intent.mExtras.putShort(key, Short.parseShort(value));
3714                                break;
3715                            default:
3716                                throw new URISyntaxException(uri, "EXTRA has unknown type", i);
3717                        }
3718                    } catch (NumberFormatException e) {
3719                        throw new URISyntaxException(uri, "EXTRA value can't be parsed", i);
3720                    }
3721
3722                    char ch = uri.charAt(i);
3723                    if (ch == ')') break;
3724                    if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i);
3725                    i++;
3726                }
3727            }
3728
3729            if (isIntentFragment) {
3730                intent.mData = Uri.parse(uri.substring(0, intentFragmentStart));
3731            } else {
3732                intent.mData = Uri.parse(uri);
3733            }
3734
3735            if (intent.mAction == null) {
3736                // By default, if no action is specified, then use VIEW.
3737                intent.mAction = ACTION_VIEW;
3738            }
3739
3740        } else {
3741            intent = new Intent(ACTION_VIEW, Uri.parse(uri));
3742        }
3743
3744        return intent;
3745    }
3746
3747    /**
3748     * Retrieve the general action to be performed, such as
3749     * {@link #ACTION_VIEW}.  The action describes the general way the rest of
3750     * the information in the intent should be interpreted -- most importantly,
3751     * what to do with the data returned by {@link #getData}.
3752     *
3753     * @return The action of this intent or null if none is specified.
3754     *
3755     * @see #setAction
3756     */
3757    public String getAction() {
3758        return mAction;
3759    }
3760
3761    /**
3762     * Retrieve data this intent is operating on.  This URI specifies the name
3763     * of the data; often it uses the content: scheme, specifying data in a
3764     * content provider.  Other schemes may be handled by specific activities,
3765     * such as http: by the web browser.
3766     *
3767     * @return The URI of the data this intent is targeting or null.
3768     *
3769     * @see #getScheme
3770     * @see #setData
3771     */
3772    public Uri getData() {
3773        return mData;
3774    }
3775
3776    /**
3777     * The same as {@link #getData()}, but returns the URI as an encoded
3778     * String.
3779     */
3780    public String getDataString() {
3781        return mData != null ? mData.toString() : null;
3782    }
3783
3784    /**
3785     * Return the scheme portion of the intent's data.  If the data is null or
3786     * does not include a scheme, null is returned.  Otherwise, the scheme
3787     * prefix without the final ':' is returned, i.e. "http".
3788     *
3789     * <p>This is the same as calling getData().getScheme() (and checking for
3790     * null data).
3791     *
3792     * @return The scheme of this intent.
3793     *
3794     * @see #getData
3795     */
3796    public String getScheme() {
3797        return mData != null ? mData.getScheme() : null;
3798    }
3799
3800    /**
3801     * Retrieve any explicit MIME type included in the intent.  This is usually
3802     * null, as the type is determined by the intent data.
3803     *
3804     * @return If a type was manually set, it is returned; else null is
3805     *         returned.
3806     *
3807     * @see #resolveType(ContentResolver)
3808     * @see #setType
3809     */
3810    public String getType() {
3811        return mType;
3812    }
3813
3814    /**
3815     * Return the MIME data type of this intent.  If the type field is
3816     * explicitly set, that is simply returned.  Otherwise, if the data is set,
3817     * the type of that data is returned.  If neither fields are set, a null is
3818     * returned.
3819     *
3820     * @return The MIME type of this intent.
3821     *
3822     * @see #getType
3823     * @see #resolveType(ContentResolver)
3824     */
3825    public String resolveType(Context context) {
3826        return resolveType(context.getContentResolver());
3827    }
3828
3829    /**
3830     * Return the MIME data type of this intent.  If the type field is
3831     * explicitly set, that is simply returned.  Otherwise, if the data is set,
3832     * the type of that data is returned.  If neither fields are set, a null is
3833     * returned.
3834     *
3835     * @param resolver A ContentResolver that can be used to determine the MIME
3836     *                 type of the intent's data.
3837     *
3838     * @return The MIME type of this intent.
3839     *
3840     * @see #getType
3841     * @see #resolveType(Context)
3842     */
3843    public String resolveType(ContentResolver resolver) {
3844        if (mType != null) {
3845            return mType;
3846        }
3847        if (mData != null) {
3848            if ("content".equals(mData.getScheme())) {
3849                return resolver.getType(mData);
3850            }
3851        }
3852        return null;
3853    }
3854
3855    /**
3856     * Return the MIME data type of this intent, only if it will be needed for
3857     * intent resolution.  This is not generally useful for application code;
3858     * it is used by the frameworks for communicating with back-end system
3859     * services.
3860     *
3861     * @param resolver A ContentResolver that can be used to determine the MIME
3862     *                 type of the intent's data.
3863     *
3864     * @return The MIME type of this intent, or null if it is unknown or not
3865     *         needed.
3866     */
3867    public String resolveTypeIfNeeded(ContentResolver resolver) {
3868        if (mComponent != null) {
3869            return mType;
3870        }
3871        return resolveType(resolver);
3872    }
3873
3874    /**
3875     * Check if a category exists in the intent.
3876     *
3877     * @param category The category to check.
3878     *
3879     * @return boolean True if the intent contains the category, else false.
3880     *
3881     * @see #getCategories
3882     * @see #addCategory
3883     */
3884    public boolean hasCategory(String category) {
3885        return mCategories != null && mCategories.contains(category);
3886    }
3887
3888    /**
3889     * Return the set of all categories in the intent.  If there are no categories,
3890     * returns NULL.
3891     *
3892     * @return The set of categories you can examine.  Do not modify!
3893     *
3894     * @see #hasCategory
3895     * @see #addCategory
3896     */
3897    public Set<String> getCategories() {
3898        return mCategories;
3899    }
3900
3901    /**
3902     * Return the specific selector associated with this Intent.  If there is
3903     * none, returns null.  See {@link #setSelector} for more information.
3904     *
3905     * @see #setSelector
3906     */
3907    public Intent getSelector() {
3908        return mSelector;
3909    }
3910
3911    /**
3912     * Return the {@link ClipData} associated with this Intent.  If there is
3913     * none, returns null.  See {@link #setClipData} for more information.
3914     *
3915     * @see #setClipData;
3916     */
3917    public ClipData getClipData() {
3918        return mClipData;
3919    }
3920
3921    /**
3922     * Sets the ClassLoader that will be used when unmarshalling
3923     * any Parcelable values from the extras of this Intent.
3924     *
3925     * @param loader a ClassLoader, or null to use the default loader
3926     * at the time of unmarshalling.
3927     */
3928    public void setExtrasClassLoader(ClassLoader loader) {
3929        if (mExtras != null) {
3930            mExtras.setClassLoader(loader);
3931        }
3932    }
3933
3934    /**
3935     * Returns true if an extra value is associated with the given name.
3936     * @param name the extra's name
3937     * @return true if the given extra is present.
3938     */
3939    public boolean hasExtra(String name) {
3940        return mExtras != null && mExtras.containsKey(name);
3941    }
3942
3943    /**
3944     * Returns true if the Intent's extras contain a parcelled file descriptor.
3945     * @return true if the Intent contains a parcelled file descriptor.
3946     */
3947    public boolean hasFileDescriptors() {
3948        return mExtras != null && mExtras.hasFileDescriptors();
3949    }
3950
3951    /** @hide */
3952    public void setAllowFds(boolean allowFds) {
3953        if (mExtras != null) {
3954            mExtras.setAllowFds(allowFds);
3955        }
3956    }
3957
3958    /**
3959     * Retrieve extended data from the intent.
3960     *
3961     * @param name The name of the desired item.
3962     *
3963     * @return the value of an item that previously added with putExtra()
3964     * or null if none was found.
3965     *
3966     * @deprecated
3967     * @hide
3968     */
3969    @Deprecated
3970    public Object getExtra(String name) {
3971        return getExtra(name, null);
3972    }
3973
3974    /**
3975     * Retrieve extended data from the intent.
3976     *
3977     * @param name The name of the desired item.
3978     * @param defaultValue the value to be returned if no value of the desired
3979     * type is stored with the given name.
3980     *
3981     * @return the value of an item that previously added with putExtra()
3982     * or the default value if none was found.
3983     *
3984     * @see #putExtra(String, boolean)
3985     */
3986    public boolean getBooleanExtra(String name, boolean defaultValue) {
3987        return mExtras == null ? defaultValue :
3988            mExtras.getBoolean(name, defaultValue);
3989    }
3990
3991    /**
3992     * Retrieve extended data from the intent.
3993     *
3994     * @param name The name of the desired item.
3995     * @param defaultValue the value to be returned if no value of the desired
3996     * type is stored with the given name.
3997     *
3998     * @return the value of an item that previously added with putExtra()
3999     * or the default value if none was found.
4000     *
4001     * @see #putExtra(String, byte)
4002     */
4003    public byte getByteExtra(String name, byte defaultValue) {
4004        return mExtras == null ? defaultValue :
4005            mExtras.getByte(name, defaultValue);
4006    }
4007
4008    /**
4009     * Retrieve extended data from the intent.
4010     *
4011     * @param name The name of the desired item.
4012     * @param defaultValue the value to be returned if no value of the desired
4013     * type is stored with the given name.
4014     *
4015     * @return the value of an item that previously added with putExtra()
4016     * or the default value if none was found.
4017     *
4018     * @see #putExtra(String, short)
4019     */
4020    public short getShortExtra(String name, short defaultValue) {
4021        return mExtras == null ? defaultValue :
4022            mExtras.getShort(name, defaultValue);
4023    }
4024
4025    /**
4026     * Retrieve extended data from the intent.
4027     *
4028     * @param name The name of the desired item.
4029     * @param defaultValue the value to be returned if no value of the desired
4030     * type is stored with the given name.
4031     *
4032     * @return the value of an item that previously added with putExtra()
4033     * or the default value if none was found.
4034     *
4035     * @see #putExtra(String, char)
4036     */
4037    public char getCharExtra(String name, char defaultValue) {
4038        return mExtras == null ? defaultValue :
4039            mExtras.getChar(name, defaultValue);
4040    }
4041
4042    /**
4043     * Retrieve extended data from the intent.
4044     *
4045     * @param name The name of the desired item.
4046     * @param defaultValue the value to be returned if no value of the desired
4047     * type is stored with the given name.
4048     *
4049     * @return the value of an item that previously added with putExtra()
4050     * or the default value if none was found.
4051     *
4052     * @see #putExtra(String, int)
4053     */
4054    public int getIntExtra(String name, int defaultValue) {
4055        return mExtras == null ? defaultValue :
4056            mExtras.getInt(name, defaultValue);
4057    }
4058
4059    /**
4060     * Retrieve extended data from the intent.
4061     *
4062     * @param name The name of the desired item.
4063     * @param defaultValue the value to be returned if no value of the desired
4064     * type is stored with the given name.
4065     *
4066     * @return the value of an item that previously added with putExtra()
4067     * or the default value if none was found.
4068     *
4069     * @see #putExtra(String, long)
4070     */
4071    public long getLongExtra(String name, long defaultValue) {
4072        return mExtras == null ? defaultValue :
4073            mExtras.getLong(name, defaultValue);
4074    }
4075
4076    /**
4077     * Retrieve extended data from the intent.
4078     *
4079     * @param name The name of the desired item.
4080     * @param defaultValue the value to be returned if no value of the desired
4081     * type is stored with the given name.
4082     *
4083     * @return the value of an item that previously added with putExtra(),
4084     * or the default value if no such item is present
4085     *
4086     * @see #putExtra(String, float)
4087     */
4088    public float getFloatExtra(String name, float defaultValue) {
4089        return mExtras == null ? defaultValue :
4090            mExtras.getFloat(name, defaultValue);
4091    }
4092
4093    /**
4094     * Retrieve extended data from the intent.
4095     *
4096     * @param name The name of the desired item.
4097     * @param defaultValue the value to be returned if no value of the desired
4098     * type is stored with the given name.
4099     *
4100     * @return the value of an item that previously added with putExtra()
4101     * or the default value if none was found.
4102     *
4103     * @see #putExtra(String, double)
4104     */
4105    public double getDoubleExtra(String name, double defaultValue) {
4106        return mExtras == null ? defaultValue :
4107            mExtras.getDouble(name, defaultValue);
4108    }
4109
4110    /**
4111     * Retrieve extended data from the intent.
4112     *
4113     * @param name The name of the desired item.
4114     *
4115     * @return the value of an item that previously added with putExtra()
4116     * or null if no String value was found.
4117     *
4118     * @see #putExtra(String, String)
4119     */
4120    public String getStringExtra(String name) {
4121        return mExtras == null ? null : mExtras.getString(name);
4122    }
4123
4124    /**
4125     * Retrieve extended data from the intent.
4126     *
4127     * @param name The name of the desired item.
4128     *
4129     * @return the value of an item that previously added with putExtra()
4130     * or null if no CharSequence value was found.
4131     *
4132     * @see #putExtra(String, CharSequence)
4133     */
4134    public CharSequence getCharSequenceExtra(String name) {
4135        return mExtras == null ? null : mExtras.getCharSequence(name);
4136    }
4137
4138    /**
4139     * Retrieve extended data from the intent.
4140     *
4141     * @param name The name of the desired item.
4142     *
4143     * @return the value of an item that previously added with putExtra()
4144     * or null if no Parcelable value was found.
4145     *
4146     * @see #putExtra(String, Parcelable)
4147     */
4148    public <T extends Parcelable> T getParcelableExtra(String name) {
4149        return mExtras == null ? null : mExtras.<T>getParcelable(name);
4150    }
4151
4152    /**
4153     * Retrieve extended data from the intent.
4154     *
4155     * @param name The name of the desired item.
4156     *
4157     * @return the value of an item that previously added with putExtra()
4158     * or null if no Parcelable[] value was found.
4159     *
4160     * @see #putExtra(String, Parcelable[])
4161     */
4162    public Parcelable[] getParcelableArrayExtra(String name) {
4163        return mExtras == null ? null : mExtras.getParcelableArray(name);
4164    }
4165
4166    /**
4167     * Retrieve extended data from the intent.
4168     *
4169     * @param name The name of the desired item.
4170     *
4171     * @return the value of an item that previously added with putExtra()
4172     * or null if no ArrayList<Parcelable> value was found.
4173     *
4174     * @see #putParcelableArrayListExtra(String, ArrayList)
4175     */
4176    public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
4177        return mExtras == null ? null : mExtras.<T>getParcelableArrayList(name);
4178    }
4179
4180    /**
4181     * Retrieve extended data from the intent.
4182     *
4183     * @param name The name of the desired item.
4184     *
4185     * @return the value of an item that previously added with putExtra()
4186     * or null if no Serializable value was found.
4187     *
4188     * @see #putExtra(String, Serializable)
4189     */
4190    public Serializable getSerializableExtra(String name) {
4191        return mExtras == null ? null : mExtras.getSerializable(name);
4192    }
4193
4194    /**
4195     * Retrieve extended data from the intent.
4196     *
4197     * @param name The name of the desired item.
4198     *
4199     * @return the value of an item that previously added with putExtra()
4200     * or null if no ArrayList<Integer> value was found.
4201     *
4202     * @see #putIntegerArrayListExtra(String, ArrayList)
4203     */
4204    public ArrayList<Integer> getIntegerArrayListExtra(String name) {
4205        return mExtras == null ? null : mExtras.getIntegerArrayList(name);
4206    }
4207
4208    /**
4209     * Retrieve extended data from the intent.
4210     *
4211     * @param name The name of the desired item.
4212     *
4213     * @return the value of an item that previously added with putExtra()
4214     * or null if no ArrayList<String> value was found.
4215     *
4216     * @see #putStringArrayListExtra(String, ArrayList)
4217     */
4218    public ArrayList<String> getStringArrayListExtra(String name) {
4219        return mExtras == null ? null : mExtras.getStringArrayList(name);
4220    }
4221
4222    /**
4223     * Retrieve extended data from the intent.
4224     *
4225     * @param name The name of the desired item.
4226     *
4227     * @return the value of an item that previously added with putExtra()
4228     * or null if no ArrayList<CharSequence> value was found.
4229     *
4230     * @see #putCharSequenceArrayListExtra(String, ArrayList)
4231     */
4232    public ArrayList<CharSequence> getCharSequenceArrayListExtra(String name) {
4233        return mExtras == null ? null : mExtras.getCharSequenceArrayList(name);
4234    }
4235
4236    /**
4237     * Retrieve extended data from the intent.
4238     *
4239     * @param name The name of the desired item.
4240     *
4241     * @return the value of an item that previously added with putExtra()
4242     * or null if no boolean array value was found.
4243     *
4244     * @see #putExtra(String, boolean[])
4245     */
4246    public boolean[] getBooleanArrayExtra(String name) {
4247        return mExtras == null ? null : mExtras.getBooleanArray(name);
4248    }
4249
4250    /**
4251     * Retrieve extended data from the intent.
4252     *
4253     * @param name The name of the desired item.
4254     *
4255     * @return the value of an item that previously added with putExtra()
4256     * or null if no byte array value was found.
4257     *
4258     * @see #putExtra(String, byte[])
4259     */
4260    public byte[] getByteArrayExtra(String name) {
4261        return mExtras == null ? null : mExtras.getByteArray(name);
4262    }
4263
4264    /**
4265     * Retrieve extended data from the intent.
4266     *
4267     * @param name The name of the desired item.
4268     *
4269     * @return the value of an item that previously added with putExtra()
4270     * or null if no short array value was found.
4271     *
4272     * @see #putExtra(String, short[])
4273     */
4274    public short[] getShortArrayExtra(String name) {
4275        return mExtras == null ? null : mExtras.getShortArray(name);
4276    }
4277
4278    /**
4279     * Retrieve extended data from the intent.
4280     *
4281     * @param name The name of the desired item.
4282     *
4283     * @return the value of an item that previously added with putExtra()
4284     * or null if no char array value was found.
4285     *
4286     * @see #putExtra(String, char[])
4287     */
4288    public char[] getCharArrayExtra(String name) {
4289        return mExtras == null ? null : mExtras.getCharArray(name);
4290    }
4291
4292    /**
4293     * Retrieve extended data from the intent.
4294     *
4295     * @param name The name of the desired item.
4296     *
4297     * @return the value of an item that previously added with putExtra()
4298     * or null if no int array value was found.
4299     *
4300     * @see #putExtra(String, int[])
4301     */
4302    public int[] getIntArrayExtra(String name) {
4303        return mExtras == null ? null : mExtras.getIntArray(name);
4304    }
4305
4306    /**
4307     * Retrieve extended data from the intent.
4308     *
4309     * @param name The name of the desired item.
4310     *
4311     * @return the value of an item that previously added with putExtra()
4312     * or null if no long array value was found.
4313     *
4314     * @see #putExtra(String, long[])
4315     */
4316    public long[] getLongArrayExtra(String name) {
4317        return mExtras == null ? null : mExtras.getLongArray(name);
4318    }
4319
4320    /**
4321     * Retrieve extended data from the intent.
4322     *
4323     * @param name The name of the desired item.
4324     *
4325     * @return the value of an item that previously added with putExtra()
4326     * or null if no float array value was found.
4327     *
4328     * @see #putExtra(String, float[])
4329     */
4330    public float[] getFloatArrayExtra(String name) {
4331        return mExtras == null ? null : mExtras.getFloatArray(name);
4332    }
4333
4334    /**
4335     * Retrieve extended data from the intent.
4336     *
4337     * @param name The name of the desired item.
4338     *
4339     * @return the value of an item that previously added with putExtra()
4340     * or null if no double array value was found.
4341     *
4342     * @see #putExtra(String, double[])
4343     */
4344    public double[] getDoubleArrayExtra(String name) {
4345        return mExtras == null ? null : mExtras.getDoubleArray(name);
4346    }
4347
4348    /**
4349     * Retrieve extended data from the intent.
4350     *
4351     * @param name The name of the desired item.
4352     *
4353     * @return the value of an item that previously added with putExtra()
4354     * or null if no String array value was found.
4355     *
4356     * @see #putExtra(String, String[])
4357     */
4358    public String[] getStringArrayExtra(String name) {
4359        return mExtras == null ? null : mExtras.getStringArray(name);
4360    }
4361
4362    /**
4363     * Retrieve extended data from the intent.
4364     *
4365     * @param name The name of the desired item.
4366     *
4367     * @return the value of an item that previously added with putExtra()
4368     * or null if no CharSequence array value was found.
4369     *
4370     * @see #putExtra(String, CharSequence[])
4371     */
4372    public CharSequence[] getCharSequenceArrayExtra(String name) {
4373        return mExtras == null ? null : mExtras.getCharSequenceArray(name);
4374    }
4375
4376    /**
4377     * Retrieve extended data from the intent.
4378     *
4379     * @param name The name of the desired item.
4380     *
4381     * @return the value of an item that previously added with putExtra()
4382     * or null if no Bundle value was found.
4383     *
4384     * @see #putExtra(String, Bundle)
4385     */
4386    public Bundle getBundleExtra(String name) {
4387        return mExtras == null ? null : mExtras.getBundle(name);
4388    }
4389
4390    /**
4391     * Retrieve extended data from the intent.
4392     *
4393     * @param name The name of the desired item.
4394     *
4395     * @return the value of an item that previously added with putExtra()
4396     * or null if no IBinder value was found.
4397     *
4398     * @see #putExtra(String, IBinder)
4399     *
4400     * @deprecated
4401     * @hide
4402     */
4403    @Deprecated
4404    public IBinder getIBinderExtra(String name) {
4405        return mExtras == null ? null : mExtras.getIBinder(name);
4406    }
4407
4408    /**
4409     * Retrieve extended data from the intent.
4410     *
4411     * @param name The name of the desired item.
4412     * @param defaultValue The default value to return in case no item is
4413     * associated with the key 'name'
4414     *
4415     * @return the value of an item that previously added with putExtra()
4416     * or defaultValue if none was found.
4417     *
4418     * @see #putExtra
4419     *
4420     * @deprecated
4421     * @hide
4422     */
4423    @Deprecated
4424    public Object getExtra(String name, Object defaultValue) {
4425        Object result = defaultValue;
4426        if (mExtras != null) {
4427            Object result2 = mExtras.get(name);
4428            if (result2 != null) {
4429                result = result2;
4430            }
4431        }
4432
4433        return result;
4434    }
4435
4436    /**
4437     * Retrieves a map of extended data from the intent.
4438     *
4439     * @return the map of all extras previously added with putExtra(),
4440     * or null if none have been added.
4441     */
4442    public Bundle getExtras() {
4443        return (mExtras != null)
4444                ? new Bundle(mExtras)
4445                : null;
4446    }
4447
4448    /**
4449     * Retrieve any special flags associated with this intent.  You will
4450     * normally just set them with {@link #setFlags} and let the system
4451     * take the appropriate action with them.
4452     *
4453     * @return int The currently set flags.
4454     *
4455     * @see #setFlags
4456     */
4457    public int getFlags() {
4458        return mFlags;
4459    }
4460
4461    /** @hide */
4462    public boolean isExcludingStopped() {
4463        return (mFlags&(FLAG_EXCLUDE_STOPPED_PACKAGES|FLAG_INCLUDE_STOPPED_PACKAGES))
4464                == FLAG_EXCLUDE_STOPPED_PACKAGES;
4465    }
4466
4467    /**
4468     * Retrieve the application package name this Intent is limited to.  When
4469     * resolving an Intent, if non-null this limits the resolution to only
4470     * components in the given application package.
4471     *
4472     * @return The name of the application package for the Intent.
4473     *
4474     * @see #resolveActivity
4475     * @see #setPackage
4476     */
4477    public String getPackage() {
4478        return mPackage;
4479    }
4480
4481    /**
4482     * Retrieve the concrete component associated with the intent.  When receiving
4483     * an intent, this is the component that was found to best handle it (that is,
4484     * yourself) and will always be non-null; in all other cases it will be
4485     * null unless explicitly set.
4486     *
4487     * @return The name of the application component to handle the intent.
4488     *
4489     * @see #resolveActivity
4490     * @see #setComponent
4491     */
4492    public ComponentName getComponent() {
4493        return mComponent;
4494    }
4495
4496    /**
4497     * Get the bounds of the sender of this intent, in screen coordinates.  This can be
4498     * used as a hint to the receiver for animations and the like.  Null means that there
4499     * is no source bounds.
4500     */
4501    public Rect getSourceBounds() {
4502        return mSourceBounds;
4503    }
4504
4505    /**
4506     * Return the Activity component that should be used to handle this intent.
4507     * The appropriate component is determined based on the information in the
4508     * intent, evaluated as follows:
4509     *
4510     * <p>If {@link #getComponent} returns an explicit class, that is returned
4511     * without any further consideration.
4512     *
4513     * <p>The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent
4514     * category to be considered.
4515     *
4516     * <p>If {@link #getAction} is non-NULL, the activity must handle this
4517     * action.
4518     *
4519     * <p>If {@link #resolveType} returns non-NULL, the activity must handle
4520     * this type.
4521     *
4522     * <p>If {@link #addCategory} has added any categories, the activity must
4523     * handle ALL of the categories specified.
4524     *
4525     * <p>If {@link #getPackage} is non-NULL, only activity components in
4526     * that application package will be considered.
4527     *
4528     * <p>If there are no activities that satisfy all of these conditions, a
4529     * null string is returned.
4530     *
4531     * <p>If multiple activities are found to satisfy the intent, the one with
4532     * the highest priority will be used.  If there are multiple activities
4533     * with the same priority, the system will either pick the best activity
4534     * based on user preference, or resolve to a system class that will allow
4535     * the user to pick an activity and forward from there.
4536     *
4537     * <p>This method is implemented simply by calling
4538     * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter
4539     * true.</p>
4540     * <p> This API is called for you as part of starting an activity from an
4541     * intent.  You do not normally need to call it yourself.</p>
4542     *
4543     * @param pm The package manager with which to resolve the Intent.
4544     *
4545     * @return Name of the component implementing an activity that can
4546     *         display the intent.
4547     *
4548     * @see #setComponent
4549     * @see #getComponent
4550     * @see #resolveActivityInfo
4551     */
4552    public ComponentName resolveActivity(PackageManager pm) {
4553        if (mComponent != null) {
4554            return mComponent;
4555        }
4556
4557        ResolveInfo info = pm.resolveActivity(
4558            this, PackageManager.MATCH_DEFAULT_ONLY);
4559        if (info != null) {
4560            return new ComponentName(
4561                    info.activityInfo.applicationInfo.packageName,
4562                    info.activityInfo.name);
4563        }
4564
4565        return null;
4566    }
4567
4568    /**
4569     * Resolve the Intent into an {@link ActivityInfo}
4570     * describing the activity that should execute the intent.  Resolution
4571     * follows the same rules as described for {@link #resolveActivity}, but
4572     * you get back the completely information about the resolved activity
4573     * instead of just its class name.
4574     *
4575     * @param pm The package manager with which to resolve the Intent.
4576     * @param flags Addition information to retrieve as per
4577     * {@link PackageManager#getActivityInfo(ComponentName, int)
4578     * PackageManager.getActivityInfo()}.
4579     *
4580     * @return PackageManager.ActivityInfo
4581     *
4582     * @see #resolveActivity
4583     */
4584    public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) {
4585        ActivityInfo ai = null;
4586        if (mComponent != null) {
4587            try {
4588                ai = pm.getActivityInfo(mComponent, flags);
4589            } catch (PackageManager.NameNotFoundException e) {
4590                // ignore
4591            }
4592        } else {
4593            ResolveInfo info = pm.resolveActivity(
4594                this, PackageManager.MATCH_DEFAULT_ONLY | flags);
4595            if (info != null) {
4596                ai = info.activityInfo;
4597            }
4598        }
4599
4600        return ai;
4601    }
4602
4603    /**
4604     * Set the general action to be performed.
4605     *
4606     * @param action An action name, such as ACTION_VIEW.  Application-specific
4607     *               actions should be prefixed with the vendor's package name.
4608     *
4609     * @return Returns the same Intent object, for chaining multiple calls
4610     * into a single statement.
4611     *
4612     * @see #getAction
4613     */
4614    public Intent setAction(String action) {
4615        mAction = action != null ? action.intern() : null;
4616        return this;
4617    }
4618
4619    /**
4620     * Set the data this intent is operating on.  This method automatically
4621     * clears any type that was previously set by {@link #setType} or
4622     * {@link #setTypeAndNormalize}.
4623     *
4624     * <p><em>Note: scheme matching in the Android framework is
4625     * case-sensitive, unlike the formal RFC. As a result,
4626     * you should always write your Uri with a lower case scheme,
4627     * or use {@link Uri#normalizeScheme} or
4628     * {@link #setDataAndNormalize}
4629     * to ensure that the scheme is converted to lower case.</em>
4630     *
4631     * @param data The Uri of the data this intent is now targeting.
4632     *
4633     * @return Returns the same Intent object, for chaining multiple calls
4634     * into a single statement.
4635     *
4636     * @see #getData
4637     * @see #setDataAndNormalize
4638     * @see android.net.Intent#normalize
4639     */
4640    public Intent setData(Uri data) {
4641        mData = data;
4642        mType = null;
4643        return this;
4644    }
4645
4646    /**
4647     * Normalize and set the data this intent is operating on.
4648     *
4649     * <p>This method automatically clears any type that was
4650     * previously set (for example, by {@link #setType}).
4651     *
4652     * <p>The data Uri is normalized using
4653     * {@link android.net.Uri#normalizeScheme} before it is set,
4654     * so really this is just a convenience method for
4655     * <pre>
4656     * setData(data.normalize())
4657     * </pre>
4658     *
4659     * @param data The Uri of the data this intent is now targeting.
4660     *
4661     * @return Returns the same Intent object, for chaining multiple calls
4662     * into a single statement.
4663     *
4664     * @see #getData
4665     * @see #setType
4666     * @see android.net.Uri#normalizeScheme
4667     */
4668    public Intent setDataAndNormalize(Uri data) {
4669        return setData(data.normalizeScheme());
4670    }
4671
4672    /**
4673     * Set an explicit MIME data type.
4674     *
4675     * <p>This is used to create intents that only specify a type and not data,
4676     * for example to indicate the type of data to return.
4677     *
4678     * <p>This method automatically clears any data that was
4679     * previously set (for example by {@link #setData}).
4680     *
4681     * <p><em>Note: MIME type matching in the Android framework is
4682     * case-sensitive, unlike formal RFC MIME types.  As a result,
4683     * you should always write your MIME types with lower case letters,
4684     * or use {@link #normalizeMimeType} or {@link #setTypeAndNormalize}
4685     * to ensure that it is converted to lower case.</em>
4686     *
4687     * @param type The MIME type of the data being handled by this intent.
4688     *
4689     * @return Returns the same Intent object, for chaining multiple calls
4690     * into a single statement.
4691     *
4692     * @see #getType
4693     * @see #setTypeAndNormalize
4694     * @see #setDataAndType
4695     * @see #normalizeMimeType
4696     */
4697    public Intent setType(String type) {
4698        mData = null;
4699        mType = type;
4700        return this;
4701    }
4702
4703    /**
4704     * Normalize and set an explicit MIME data type.
4705     *
4706     * <p>This is used to create intents that only specify a type and not data,
4707     * for example to indicate the type of data to return.
4708     *
4709     * <p>This method automatically clears any data that was
4710     * previously set (for example by {@link #setData}).
4711     *
4712     * <p>The MIME type is normalized using
4713     * {@link #normalizeMimeType} before it is set,
4714     * so really this is just a convenience method for
4715     * <pre>
4716     * setType(Intent.normalizeMimeType(type))
4717     * </pre>
4718     *
4719     * @param type The MIME type of the data being handled by this intent.
4720     *
4721     * @return Returns the same Intent object, for chaining multiple calls
4722     * into a single statement.
4723     *
4724     * @see #getType
4725     * @see #setData
4726     * @see #normalizeMimeType
4727     */
4728    public Intent setTypeAndNormalize(String type) {
4729        return setType(normalizeMimeType(type));
4730    }
4731
4732    /**
4733     * (Usually optional) Set the data for the intent along with an explicit
4734     * MIME data type.  This method should very rarely be used -- it allows you
4735     * to override the MIME type that would ordinarily be inferred from the
4736     * data with your own type given here.
4737     *
4738     * <p><em>Note: MIME type and Uri scheme matching in the
4739     * Android framework is case-sensitive, unlike the formal RFC definitions.
4740     * As a result, you should always write these elements with lower case letters,
4741     * or use {@link #normalizeMimeType} or {@link android.net.Uri#normalizeScheme} or
4742     * {@link #setDataAndTypeAndNormalize}
4743     * to ensure that they are converted to lower case.</em>
4744     *
4745     * @param data The Uri of the data this intent is now targeting.
4746     * @param type The MIME type of the data being handled by this intent.
4747     *
4748     * @return Returns the same Intent object, for chaining multiple calls
4749     * into a single statement.
4750     *
4751     * @see #setType
4752     * @see #setData
4753     * @see #normalizeMimeType
4754     * @see android.net.Uri#normalizeScheme
4755     * @see #setDataAndTypeAndNormalize
4756     */
4757    public Intent setDataAndType(Uri data, String type) {
4758        mData = data;
4759        mType = type;
4760        return this;
4761    }
4762
4763    /**
4764     * (Usually optional) Normalize and set both the data Uri and an explicit
4765     * MIME data type.  This method should very rarely be used -- it allows you
4766     * to override the MIME type that would ordinarily be inferred from the
4767     * data with your own type given here.
4768     *
4769     * <p>The data Uri and the MIME type are normalize using
4770     * {@link android.net.Uri#normalizeScheme} and {@link #normalizeMimeType}
4771     * before they are set, so really this is just a convenience method for
4772     * <pre>
4773     * setDataAndType(data.normalize(), Intent.normalizeMimeType(type))
4774     * </pre>
4775     *
4776     * @param data The Uri of the data this intent is now targeting.
4777     * @param type The MIME type of the data being handled by this intent.
4778     *
4779     * @return Returns the same Intent object, for chaining multiple calls
4780     * into a single statement.
4781     *
4782     * @see #setType
4783     * @see #setData
4784     * @see #setDataAndType
4785     * @see #normalizeMimeType
4786     * @see android.net.Uri#normalizeScheme
4787     */
4788    public Intent setDataAndTypeAndNormalize(Uri data, String type) {
4789        return setDataAndType(data.normalizeScheme(), normalizeMimeType(type));
4790    }
4791
4792    /**
4793     * Add a new category to the intent.  Categories provide additional detail
4794     * about the action the intent performs.  When resolving an intent, only
4795     * activities that provide <em>all</em> of the requested categories will be
4796     * used.
4797     *
4798     * @param category The desired category.  This can be either one of the
4799     *               predefined Intent categories, or a custom category in your own
4800     *               namespace.
4801     *
4802     * @return Returns the same Intent object, for chaining multiple calls
4803     * into a single statement.
4804     *
4805     * @see #hasCategory
4806     * @see #removeCategory
4807     */
4808    public Intent addCategory(String category) {
4809        if (mCategories == null) {
4810            mCategories = new HashSet<String>();
4811        }
4812        mCategories.add(category.intern());
4813        return this;
4814    }
4815
4816    /**
4817     * Remove a category from an intent.
4818     *
4819     * @param category The category to remove.
4820     *
4821     * @see #addCategory
4822     */
4823    public void removeCategory(String category) {
4824        if (mCategories != null) {
4825            mCategories.remove(category);
4826            if (mCategories.size() == 0) {
4827                mCategories = null;
4828            }
4829        }
4830    }
4831
4832    /**
4833     * Set a selector for this Intent.  This is a modification to the kinds of
4834     * things the Intent will match.  If the selector is set, it will be used
4835     * when trying to find entities that can handle the Intent, instead of the
4836     * main contents of the Intent.  This allows you build an Intent containing
4837     * a generic protocol while targeting it more specifically.
4838     *
4839     * <p>An example of where this may be used is with things like
4840     * {@link #CATEGORY_APP_BROWSER}.  This category allows you to build an
4841     * Intent that will launch the Browser application.  However, the correct
4842     * main entry point of an application is actually {@link #ACTION_MAIN}
4843     * {@link #CATEGORY_LAUNCHER} with {@link #setComponent(ComponentName)}
4844     * used to specify the actual Activity to launch.  If you launch the browser
4845     * with something different, undesired behavior may happen if the user has
4846     * previously or later launches it the normal way, since they do not match.
4847     * Instead, you can build an Intent with the MAIN action (but no ComponentName
4848     * yet specified) and set a selector with {@link #ACTION_MAIN} and
4849     * {@link #CATEGORY_APP_BROWSER} to point it specifically to the browser activity.
4850     *
4851     * <p>Setting a selector does not impact the behavior of
4852     * {@link #filterEquals(Intent)} and {@link #filterHashCode()}.  This is part of the
4853     * desired behavior of a selector -- it does not impact the base meaning
4854     * of the Intent, just what kinds of things will be matched against it
4855     * when determining who can handle it.</p>
4856     *
4857     * <p>You can not use both a selector and {@link #setPackage(String)} on
4858     * the same base Intent.</p>
4859     *
4860     * @param selector The desired selector Intent; set to null to not use
4861     * a special selector.
4862     */
4863    public void setSelector(Intent selector) {
4864        if (selector == this) {
4865            throw new IllegalArgumentException(
4866                    "Intent being set as a selector of itself");
4867        }
4868        if (selector != null && mPackage != null) {
4869            throw new IllegalArgumentException(
4870                    "Can't set selector when package name is already set");
4871        }
4872        mSelector = selector;
4873    }
4874
4875    /**
4876     * Set a {@link ClipData} associated with this Intent.  This replaces any
4877     * previously set ClipData.
4878     *
4879     * <p>The ClipData in an intent is not used for Intent matching or other
4880     * such operations.  Semantically it is like extras, used to transmit
4881     * additional data with the Intent.  The main feature of using this over
4882     * the extras for data is that {@link #FLAG_GRANT_READ_URI_PERMISSION}
4883     * and {@link #FLAG_GRANT_WRITE_URI_PERMISSION} will operate on any URI
4884     * items included in the clip data.  This is useful, in particular, if
4885     * you want to transmit an Intent containing multiple <code>content:</code>
4886     * URIs for which the recipient may not have global permission to access the
4887     * content provider.
4888     *
4889     * <p>If the ClipData contains items that are themselves Intents, any
4890     * grant flags in those Intents will be ignored.  Only the top-level flags
4891     * of the main Intent are respected, and will be applied to all Uri or
4892     * Intent items in the clip (or sub-items of the clip).
4893     *
4894     * <p>The MIME type, label, and icon in the ClipData object are not
4895     * directly used by Intent.  Applications should generally rely on the
4896     * MIME type of the Intent itself, not what it may find in the ClipData.
4897     * A common practice is to construct a ClipData for use with an Intent
4898     * with a MIME type of "*\/*".
4899     *
4900     * @param clip The new clip to set.  May be null to clear the current clip.
4901     */
4902    public void setClipData(ClipData clip) {
4903        mClipData = clip;
4904    }
4905
4906    /**
4907     * Add extended data to the intent.  The name must include a package
4908     * prefix, for example the app com.android.contacts would use names
4909     * like "com.android.contacts.ShowAll".
4910     *
4911     * @param name The name of the extra data, with package prefix.
4912     * @param value The boolean data value.
4913     *
4914     * @return Returns the same Intent object, for chaining multiple calls
4915     * into a single statement.
4916     *
4917     * @see #putExtras
4918     * @see #removeExtra
4919     * @see #getBooleanExtra(String, boolean)
4920     */
4921    public Intent putExtra(String name, boolean value) {
4922        if (mExtras == null) {
4923            mExtras = new Bundle();
4924        }
4925        mExtras.putBoolean(name, value);
4926        return this;
4927    }
4928
4929    /**
4930     * Add extended data to the intent.  The name must include a package
4931     * prefix, for example the app com.android.contacts would use names
4932     * like "com.android.contacts.ShowAll".
4933     *
4934     * @param name The name of the extra data, with package prefix.
4935     * @param value The byte data value.
4936     *
4937     * @return Returns the same Intent object, for chaining multiple calls
4938     * into a single statement.
4939     *
4940     * @see #putExtras
4941     * @see #removeExtra
4942     * @see #getByteExtra(String, byte)
4943     */
4944    public Intent putExtra(String name, byte value) {
4945        if (mExtras == null) {
4946            mExtras = new Bundle();
4947        }
4948        mExtras.putByte(name, value);
4949        return this;
4950    }
4951
4952    /**
4953     * Add extended data to the intent.  The name must include a package
4954     * prefix, for example the app com.android.contacts would use names
4955     * like "com.android.contacts.ShowAll".
4956     *
4957     * @param name The name of the extra data, with package prefix.
4958     * @param value The char data value.
4959     *
4960     * @return Returns the same Intent object, for chaining multiple calls
4961     * into a single statement.
4962     *
4963     * @see #putExtras
4964     * @see #removeExtra
4965     * @see #getCharExtra(String, char)
4966     */
4967    public Intent putExtra(String name, char value) {
4968        if (mExtras == null) {
4969            mExtras = new Bundle();
4970        }
4971        mExtras.putChar(name, value);
4972        return this;
4973    }
4974
4975    /**
4976     * Add extended data to the intent.  The name must include a package
4977     * prefix, for example the app com.android.contacts would use names
4978     * like "com.android.contacts.ShowAll".
4979     *
4980     * @param name The name of the extra data, with package prefix.
4981     * @param value The short data value.
4982     *
4983     * @return Returns the same Intent object, for chaining multiple calls
4984     * into a single statement.
4985     *
4986     * @see #putExtras
4987     * @see #removeExtra
4988     * @see #getShortExtra(String, short)
4989     */
4990    public Intent putExtra(String name, short value) {
4991        if (mExtras == null) {
4992            mExtras = new Bundle();
4993        }
4994        mExtras.putShort(name, value);
4995        return this;
4996    }
4997
4998    /**
4999     * Add extended data to the intent.  The name must include a package
5000     * prefix, for example the app com.android.contacts would use names
5001     * like "com.android.contacts.ShowAll".
5002     *
5003     * @param name The name of the extra data, with package prefix.
5004     * @param value The integer data value.
5005     *
5006     * @return Returns the same Intent object, for chaining multiple calls
5007     * into a single statement.
5008     *
5009     * @see #putExtras
5010     * @see #removeExtra
5011     * @see #getIntExtra(String, int)
5012     */
5013    public Intent putExtra(String name, int value) {
5014        if (mExtras == null) {
5015            mExtras = new Bundle();
5016        }
5017        mExtras.putInt(name, value);
5018        return this;
5019    }
5020
5021    /**
5022     * Add extended data to the intent.  The name must include a package
5023     * prefix, for example the app com.android.contacts would use names
5024     * like "com.android.contacts.ShowAll".
5025     *
5026     * @param name The name of the extra data, with package prefix.
5027     * @param value The long data value.
5028     *
5029     * @return Returns the same Intent object, for chaining multiple calls
5030     * into a single statement.
5031     *
5032     * @see #putExtras
5033     * @see #removeExtra
5034     * @see #getLongExtra(String, long)
5035     */
5036    public Intent putExtra(String name, long value) {
5037        if (mExtras == null) {
5038            mExtras = new Bundle();
5039        }
5040        mExtras.putLong(name, value);
5041        return this;
5042    }
5043
5044    /**
5045     * Add extended data to the intent.  The name must include a package
5046     * prefix, for example the app com.android.contacts would use names
5047     * like "com.android.contacts.ShowAll".
5048     *
5049     * @param name The name of the extra data, with package prefix.
5050     * @param value The float data value.
5051     *
5052     * @return Returns the same Intent object, for chaining multiple calls
5053     * into a single statement.
5054     *
5055     * @see #putExtras
5056     * @see #removeExtra
5057     * @see #getFloatExtra(String, float)
5058     */
5059    public Intent putExtra(String name, float value) {
5060        if (mExtras == null) {
5061            mExtras = new Bundle();
5062        }
5063        mExtras.putFloat(name, value);
5064        return this;
5065    }
5066
5067    /**
5068     * Add extended data to the intent.  The name must include a package
5069     * prefix, for example the app com.android.contacts would use names
5070     * like "com.android.contacts.ShowAll".
5071     *
5072     * @param name The name of the extra data, with package prefix.
5073     * @param value The double data value.
5074     *
5075     * @return Returns the same Intent object, for chaining multiple calls
5076     * into a single statement.
5077     *
5078     * @see #putExtras
5079     * @see #removeExtra
5080     * @see #getDoubleExtra(String, double)
5081     */
5082    public Intent putExtra(String name, double value) {
5083        if (mExtras == null) {
5084            mExtras = new Bundle();
5085        }
5086        mExtras.putDouble(name, value);
5087        return this;
5088    }
5089
5090    /**
5091     * Add extended data to the intent.  The name must include a package
5092     * prefix, for example the app com.android.contacts would use names
5093     * like "com.android.contacts.ShowAll".
5094     *
5095     * @param name The name of the extra data, with package prefix.
5096     * @param value The String data value.
5097     *
5098     * @return Returns the same Intent object, for chaining multiple calls
5099     * into a single statement.
5100     *
5101     * @see #putExtras
5102     * @see #removeExtra
5103     * @see #getStringExtra(String)
5104     */
5105    public Intent putExtra(String name, String value) {
5106        if (mExtras == null) {
5107            mExtras = new Bundle();
5108        }
5109        mExtras.putString(name, value);
5110        return this;
5111    }
5112
5113    /**
5114     * Add extended data to the intent.  The name must include a package
5115     * prefix, for example the app com.android.contacts would use names
5116     * like "com.android.contacts.ShowAll".
5117     *
5118     * @param name The name of the extra data, with package prefix.
5119     * @param value The CharSequence data value.
5120     *
5121     * @return Returns the same Intent object, for chaining multiple calls
5122     * into a single statement.
5123     *
5124     * @see #putExtras
5125     * @see #removeExtra
5126     * @see #getCharSequenceExtra(String)
5127     */
5128    public Intent putExtra(String name, CharSequence value) {
5129        if (mExtras == null) {
5130            mExtras = new Bundle();
5131        }
5132        mExtras.putCharSequence(name, value);
5133        return this;
5134    }
5135
5136    /**
5137     * Add extended data to the intent.  The name must include a package
5138     * prefix, for example the app com.android.contacts would use names
5139     * like "com.android.contacts.ShowAll".
5140     *
5141     * @param name The name of the extra data, with package prefix.
5142     * @param value The Parcelable data value.
5143     *
5144     * @return Returns the same Intent object, for chaining multiple calls
5145     * into a single statement.
5146     *
5147     * @see #putExtras
5148     * @see #removeExtra
5149     * @see #getParcelableExtra(String)
5150     */
5151    public Intent putExtra(String name, Parcelable value) {
5152        if (mExtras == null) {
5153            mExtras = new Bundle();
5154        }
5155        mExtras.putParcelable(name, value);
5156        return this;
5157    }
5158
5159    /**
5160     * Add extended data to the intent.  The name must include a package
5161     * prefix, for example the app com.android.contacts would use names
5162     * like "com.android.contacts.ShowAll".
5163     *
5164     * @param name The name of the extra data, with package prefix.
5165     * @param value The Parcelable[] data value.
5166     *
5167     * @return Returns the same Intent object, for chaining multiple calls
5168     * into a single statement.
5169     *
5170     * @see #putExtras
5171     * @see #removeExtra
5172     * @see #getParcelableArrayExtra(String)
5173     */
5174    public Intent putExtra(String name, Parcelable[] value) {
5175        if (mExtras == null) {
5176            mExtras = new Bundle();
5177        }
5178        mExtras.putParcelableArray(name, value);
5179        return this;
5180    }
5181
5182    /**
5183     * Add extended data to the intent.  The name must include a package
5184     * prefix, for example the app com.android.contacts would use names
5185     * like "com.android.contacts.ShowAll".
5186     *
5187     * @param name The name of the extra data, with package prefix.
5188     * @param value The ArrayList<Parcelable> data value.
5189     *
5190     * @return Returns the same Intent object, for chaining multiple calls
5191     * into a single statement.
5192     *
5193     * @see #putExtras
5194     * @see #removeExtra
5195     * @see #getParcelableArrayListExtra(String)
5196     */
5197    public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
5198        if (mExtras == null) {
5199            mExtras = new Bundle();
5200        }
5201        mExtras.putParcelableArrayList(name, value);
5202        return this;
5203    }
5204
5205    /**
5206     * Add extended data to the intent.  The name must include a package
5207     * prefix, for example the app com.android.contacts would use names
5208     * like "com.android.contacts.ShowAll".
5209     *
5210     * @param name The name of the extra data, with package prefix.
5211     * @param value The ArrayList<Integer> data value.
5212     *
5213     * @return Returns the same Intent object, for chaining multiple calls
5214     * into a single statement.
5215     *
5216     * @see #putExtras
5217     * @see #removeExtra
5218     * @see #getIntegerArrayListExtra(String)
5219     */
5220    public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
5221        if (mExtras == null) {
5222            mExtras = new Bundle();
5223        }
5224        mExtras.putIntegerArrayList(name, value);
5225        return this;
5226    }
5227
5228    /**
5229     * Add extended data to the intent.  The name must include a package
5230     * prefix, for example the app com.android.contacts would use names
5231     * like "com.android.contacts.ShowAll".
5232     *
5233     * @param name The name of the extra data, with package prefix.
5234     * @param value The ArrayList<String> data value.
5235     *
5236     * @return Returns the same Intent object, for chaining multiple calls
5237     * into a single statement.
5238     *
5239     * @see #putExtras
5240     * @see #removeExtra
5241     * @see #getStringArrayListExtra(String)
5242     */
5243    public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
5244        if (mExtras == null) {
5245            mExtras = new Bundle();
5246        }
5247        mExtras.putStringArrayList(name, value);
5248        return this;
5249    }
5250
5251    /**
5252     * Add extended data to the intent.  The name must include a package
5253     * prefix, for example the app com.android.contacts would use names
5254     * like "com.android.contacts.ShowAll".
5255     *
5256     * @param name The name of the extra data, with package prefix.
5257     * @param value The ArrayList<CharSequence> data value.
5258     *
5259     * @return Returns the same Intent object, for chaining multiple calls
5260     * into a single statement.
5261     *
5262     * @see #putExtras
5263     * @see #removeExtra
5264     * @see #getCharSequenceArrayListExtra(String)
5265     */
5266    public Intent putCharSequenceArrayListExtra(String name, ArrayList<CharSequence> value) {
5267        if (mExtras == null) {
5268            mExtras = new Bundle();
5269        }
5270        mExtras.putCharSequenceArrayList(name, value);
5271        return this;
5272    }
5273
5274    /**
5275     * Add extended data to the intent.  The name must include a package
5276     * prefix, for example the app com.android.contacts would use names
5277     * like "com.android.contacts.ShowAll".
5278     *
5279     * @param name The name of the extra data, with package prefix.
5280     * @param value The Serializable data value.
5281     *
5282     * @return Returns the same Intent object, for chaining multiple calls
5283     * into a single statement.
5284     *
5285     * @see #putExtras
5286     * @see #removeExtra
5287     * @see #getSerializableExtra(String)
5288     */
5289    public Intent putExtra(String name, Serializable value) {
5290        if (mExtras == null) {
5291            mExtras = new Bundle();
5292        }
5293        mExtras.putSerializable(name, value);
5294        return this;
5295    }
5296
5297    /**
5298     * Add extended data to the intent.  The name must include a package
5299     * prefix, for example the app com.android.contacts would use names
5300     * like "com.android.contacts.ShowAll".
5301     *
5302     * @param name The name of the extra data, with package prefix.
5303     * @param value The boolean array data value.
5304     *
5305     * @return Returns the same Intent object, for chaining multiple calls
5306     * into a single statement.
5307     *
5308     * @see #putExtras
5309     * @see #removeExtra
5310     * @see #getBooleanArrayExtra(String)
5311     */
5312    public Intent putExtra(String name, boolean[] value) {
5313        if (mExtras == null) {
5314            mExtras = new Bundle();
5315        }
5316        mExtras.putBooleanArray(name, value);
5317        return this;
5318    }
5319
5320    /**
5321     * Add extended data to the intent.  The name must include a package
5322     * prefix, for example the app com.android.contacts would use names
5323     * like "com.android.contacts.ShowAll".
5324     *
5325     * @param name The name of the extra data, with package prefix.
5326     * @param value The byte array data value.
5327     *
5328     * @return Returns the same Intent object, for chaining multiple calls
5329     * into a single statement.
5330     *
5331     * @see #putExtras
5332     * @see #removeExtra
5333     * @see #getByteArrayExtra(String)
5334     */
5335    public Intent putExtra(String name, byte[] value) {
5336        if (mExtras == null) {
5337            mExtras = new Bundle();
5338        }
5339        mExtras.putByteArray(name, value);
5340        return this;
5341    }
5342
5343    /**
5344     * Add extended data to the intent.  The name must include a package
5345     * prefix, for example the app com.android.contacts would use names
5346     * like "com.android.contacts.ShowAll".
5347     *
5348     * @param name The name of the extra data, with package prefix.
5349     * @param value The short array data value.
5350     *
5351     * @return Returns the same Intent object, for chaining multiple calls
5352     * into a single statement.
5353     *
5354     * @see #putExtras
5355     * @see #removeExtra
5356     * @see #getShortArrayExtra(String)
5357     */
5358    public Intent putExtra(String name, short[] value) {
5359        if (mExtras == null) {
5360            mExtras = new Bundle();
5361        }
5362        mExtras.putShortArray(name, value);
5363        return this;
5364    }
5365
5366    /**
5367     * Add extended data to the intent.  The name must include a package
5368     * prefix, for example the app com.android.contacts would use names
5369     * like "com.android.contacts.ShowAll".
5370     *
5371     * @param name The name of the extra data, with package prefix.
5372     * @param value The char array data value.
5373     *
5374     * @return Returns the same Intent object, for chaining multiple calls
5375     * into a single statement.
5376     *
5377     * @see #putExtras
5378     * @see #removeExtra
5379     * @see #getCharArrayExtra(String)
5380     */
5381    public Intent putExtra(String name, char[] value) {
5382        if (mExtras == null) {
5383            mExtras = new Bundle();
5384        }
5385        mExtras.putCharArray(name, value);
5386        return this;
5387    }
5388
5389    /**
5390     * Add extended data to the intent.  The name must include a package
5391     * prefix, for example the app com.android.contacts would use names
5392     * like "com.android.contacts.ShowAll".
5393     *
5394     * @param name The name of the extra data, with package prefix.
5395     * @param value The int array data value.
5396     *
5397     * @return Returns the same Intent object, for chaining multiple calls
5398     * into a single statement.
5399     *
5400     * @see #putExtras
5401     * @see #removeExtra
5402     * @see #getIntArrayExtra(String)
5403     */
5404    public Intent putExtra(String name, int[] value) {
5405        if (mExtras == null) {
5406            mExtras = new Bundle();
5407        }
5408        mExtras.putIntArray(name, value);
5409        return this;
5410    }
5411
5412    /**
5413     * Add extended data to the intent.  The name must include a package
5414     * prefix, for example the app com.android.contacts would use names
5415     * like "com.android.contacts.ShowAll".
5416     *
5417     * @param name The name of the extra data, with package prefix.
5418     * @param value The byte array data value.
5419     *
5420     * @return Returns the same Intent object, for chaining multiple calls
5421     * into a single statement.
5422     *
5423     * @see #putExtras
5424     * @see #removeExtra
5425     * @see #getLongArrayExtra(String)
5426     */
5427    public Intent putExtra(String name, long[] value) {
5428        if (mExtras == null) {
5429            mExtras = new Bundle();
5430        }
5431        mExtras.putLongArray(name, value);
5432        return this;
5433    }
5434
5435    /**
5436     * Add extended data to the intent.  The name must include a package
5437     * prefix, for example the app com.android.contacts would use names
5438     * like "com.android.contacts.ShowAll".
5439     *
5440     * @param name The name of the extra data, with package prefix.
5441     * @param value The float array data value.
5442     *
5443     * @return Returns the same Intent object, for chaining multiple calls
5444     * into a single statement.
5445     *
5446     * @see #putExtras
5447     * @see #removeExtra
5448     * @see #getFloatArrayExtra(String)
5449     */
5450    public Intent putExtra(String name, float[] value) {
5451        if (mExtras == null) {
5452            mExtras = new Bundle();
5453        }
5454        mExtras.putFloatArray(name, value);
5455        return this;
5456    }
5457
5458    /**
5459     * Add extended data to the intent.  The name must include a package
5460     * prefix, for example the app com.android.contacts would use names
5461     * like "com.android.contacts.ShowAll".
5462     *
5463     * @param name The name of the extra data, with package prefix.
5464     * @param value The double array data value.
5465     *
5466     * @return Returns the same Intent object, for chaining multiple calls
5467     * into a single statement.
5468     *
5469     * @see #putExtras
5470     * @see #removeExtra
5471     * @see #getDoubleArrayExtra(String)
5472     */
5473    public Intent putExtra(String name, double[] value) {
5474        if (mExtras == null) {
5475            mExtras = new Bundle();
5476        }
5477        mExtras.putDoubleArray(name, value);
5478        return this;
5479    }
5480
5481    /**
5482     * Add extended data to the intent.  The name must include a package
5483     * prefix, for example the app com.android.contacts would use names
5484     * like "com.android.contacts.ShowAll".
5485     *
5486     * @param name The name of the extra data, with package prefix.
5487     * @param value The String array data value.
5488     *
5489     * @return Returns the same Intent object, for chaining multiple calls
5490     * into a single statement.
5491     *
5492     * @see #putExtras
5493     * @see #removeExtra
5494     * @see #getStringArrayExtra(String)
5495     */
5496    public Intent putExtra(String name, String[] value) {
5497        if (mExtras == null) {
5498            mExtras = new Bundle();
5499        }
5500        mExtras.putStringArray(name, value);
5501        return this;
5502    }
5503
5504    /**
5505     * Add extended data to the intent.  The name must include a package
5506     * prefix, for example the app com.android.contacts would use names
5507     * like "com.android.contacts.ShowAll".
5508     *
5509     * @param name The name of the extra data, with package prefix.
5510     * @param value The CharSequence array data value.
5511     *
5512     * @return Returns the same Intent object, for chaining multiple calls
5513     * into a single statement.
5514     *
5515     * @see #putExtras
5516     * @see #removeExtra
5517     * @see #getCharSequenceArrayExtra(String)
5518     */
5519    public Intent putExtra(String name, CharSequence[] value) {
5520        if (mExtras == null) {
5521            mExtras = new Bundle();
5522        }
5523        mExtras.putCharSequenceArray(name, value);
5524        return this;
5525    }
5526
5527    /**
5528     * Add extended data to the intent.  The name must include a package
5529     * prefix, for example the app com.android.contacts would use names
5530     * like "com.android.contacts.ShowAll".
5531     *
5532     * @param name The name of the extra data, with package prefix.
5533     * @param value The Bundle data value.
5534     *
5535     * @return Returns the same Intent object, for chaining multiple calls
5536     * into a single statement.
5537     *
5538     * @see #putExtras
5539     * @see #removeExtra
5540     * @see #getBundleExtra(String)
5541     */
5542    public Intent putExtra(String name, Bundle value) {
5543        if (mExtras == null) {
5544            mExtras = new Bundle();
5545        }
5546        mExtras.putBundle(name, value);
5547        return this;
5548    }
5549
5550    /**
5551     * Add extended data to the intent.  The name must include a package
5552     * prefix, for example the app com.android.contacts would use names
5553     * like "com.android.contacts.ShowAll".
5554     *
5555     * @param name The name of the extra data, with package prefix.
5556     * @param value The IBinder data value.
5557     *
5558     * @return Returns the same Intent object, for chaining multiple calls
5559     * into a single statement.
5560     *
5561     * @see #putExtras
5562     * @see #removeExtra
5563     * @see #getIBinderExtra(String)
5564     *
5565     * @deprecated
5566     * @hide
5567     */
5568    @Deprecated
5569    public Intent putExtra(String name, IBinder value) {
5570        if (mExtras == null) {
5571            mExtras = new Bundle();
5572        }
5573        mExtras.putIBinder(name, value);
5574        return this;
5575    }
5576
5577    /**
5578     * Copy all extras in 'src' in to this intent.
5579     *
5580     * @param src Contains the extras to copy.
5581     *
5582     * @see #putExtra
5583     */
5584    public Intent putExtras(Intent src) {
5585        if (src.mExtras != null) {
5586            if (mExtras == null) {
5587                mExtras = new Bundle(src.mExtras);
5588            } else {
5589                mExtras.putAll(src.mExtras);
5590            }
5591        }
5592        return this;
5593    }
5594
5595    /**
5596     * Add a set of extended data to the intent.  The keys must include a package
5597     * prefix, for example the app com.android.contacts would use names
5598     * like "com.android.contacts.ShowAll".
5599     *
5600     * @param extras The Bundle of extras to add to this intent.
5601     *
5602     * @see #putExtra
5603     * @see #removeExtra
5604     */
5605    public Intent putExtras(Bundle extras) {
5606        if (mExtras == null) {
5607            mExtras = new Bundle();
5608        }
5609        mExtras.putAll(extras);
5610        return this;
5611    }
5612
5613    /**
5614     * Completely replace the extras in the Intent with the extras in the
5615     * given Intent.
5616     *
5617     * @param src The exact extras contained in this Intent are copied
5618     * into the target intent, replacing any that were previously there.
5619     */
5620    public Intent replaceExtras(Intent src) {
5621        mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null;
5622        return this;
5623    }
5624
5625    /**
5626     * Completely replace the extras in the Intent with the given Bundle of
5627     * extras.
5628     *
5629     * @param extras The new set of extras in the Intent, or null to erase
5630     * all extras.
5631     */
5632    public Intent replaceExtras(Bundle extras) {
5633        mExtras = extras != null ? new Bundle(extras) : null;
5634        return this;
5635    }
5636
5637    /**
5638     * Remove extended data from the intent.
5639     *
5640     * @see #putExtra
5641     */
5642    public void removeExtra(String name) {
5643        if (mExtras != null) {
5644            mExtras.remove(name);
5645            if (mExtras.size() == 0) {
5646                mExtras = null;
5647            }
5648        }
5649    }
5650
5651    /**
5652     * Set special flags controlling how this intent is handled.  Most values
5653     * here depend on the type of component being executed by the Intent,
5654     * specifically the FLAG_ACTIVITY_* flags are all for use with
5655     * {@link Context#startActivity Context.startActivity()} and the
5656     * FLAG_RECEIVER_* flags are all for use with
5657     * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
5658     *
5659     * <p>See the
5660     * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
5661     * Stack</a> documentation for important information on how some of these options impact
5662     * the behavior of your application.
5663     *
5664     * @param flags The desired flags.
5665     *
5666     * @return Returns the same Intent object, for chaining multiple calls
5667     * into a single statement.
5668     *
5669     * @see #getFlags
5670     * @see #addFlags
5671     *
5672     * @see #FLAG_GRANT_READ_URI_PERMISSION
5673     * @see #FLAG_GRANT_WRITE_URI_PERMISSION
5674     * @see #FLAG_DEBUG_LOG_RESOLUTION
5675     * @see #FLAG_FROM_BACKGROUND
5676     * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT
5677     * @see #FLAG_ACTIVITY_CLEAR_TASK
5678     * @see #FLAG_ACTIVITY_CLEAR_TOP
5679     * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
5680     * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
5681     * @see #FLAG_ACTIVITY_FORWARD_RESULT
5682     * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
5683     * @see #FLAG_ACTIVITY_MULTIPLE_TASK
5684     * @see #FLAG_ACTIVITY_NEW_TASK
5685     * @see #FLAG_ACTIVITY_NO_ANIMATION
5686     * @see #FLAG_ACTIVITY_NO_HISTORY
5687     * @see #FLAG_ACTIVITY_NO_USER_ACTION
5688     * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP
5689     * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
5690     * @see #FLAG_ACTIVITY_REORDER_TO_FRONT
5691     * @see #FLAG_ACTIVITY_SINGLE_TOP
5692     * @see #FLAG_ACTIVITY_TASK_ON_HOME
5693     * @see #FLAG_RECEIVER_REGISTERED_ONLY
5694     */
5695    public Intent setFlags(int flags) {
5696        mFlags = flags;
5697        return this;
5698    }
5699
5700    /**
5701     * Add additional flags to the intent (or with existing flags
5702     * value).
5703     *
5704     * @param flags The new flags to set.
5705     *
5706     * @return Returns the same Intent object, for chaining multiple calls
5707     * into a single statement.
5708     *
5709     * @see #setFlags
5710     */
5711    public Intent addFlags(int flags) {
5712        mFlags |= flags;
5713        return this;
5714    }
5715
5716    /**
5717     * (Usually optional) Set an explicit application package name that limits
5718     * the components this Intent will resolve to.  If left to the default
5719     * value of null, all components in all applications will considered.
5720     * If non-null, the Intent can only match the components in the given
5721     * application package.
5722     *
5723     * @param packageName The name of the application package to handle the
5724     * intent, or null to allow any application package.
5725     *
5726     * @return Returns the same Intent object, for chaining multiple calls
5727     * into a single statement.
5728     *
5729     * @see #getPackage
5730     * @see #resolveActivity
5731     */
5732    public Intent setPackage(String packageName) {
5733        if (packageName != null && mSelector != null) {
5734            throw new IllegalArgumentException(
5735                    "Can't set package name when selector is already set");
5736        }
5737        mPackage = packageName;
5738        return this;
5739    }
5740
5741    /**
5742     * (Usually optional) Explicitly set the component to handle the intent.
5743     * If left with the default value of null, the system will determine the
5744     * appropriate class to use based on the other fields (action, data,
5745     * type, categories) in the Intent.  If this class is defined, the
5746     * specified class will always be used regardless of the other fields.  You
5747     * should only set this value when you know you absolutely want a specific
5748     * class to be used; otherwise it is better to let the system find the
5749     * appropriate class so that you will respect the installed applications
5750     * and user preferences.
5751     *
5752     * @param component The name of the application component to handle the
5753     * intent, or null to let the system find one for you.
5754     *
5755     * @return Returns the same Intent object, for chaining multiple calls
5756     * into a single statement.
5757     *
5758     * @see #setClass
5759     * @see #setClassName(Context, String)
5760     * @see #setClassName(String, String)
5761     * @see #getComponent
5762     * @see #resolveActivity
5763     */
5764    public Intent setComponent(ComponentName component) {
5765        mComponent = component;
5766        return this;
5767    }
5768
5769    /**
5770     * Convenience for calling {@link #setComponent} with an
5771     * explicit class name.
5772     *
5773     * @param packageContext A Context of the application package implementing
5774     * this class.
5775     * @param className The name of a class inside of the application package
5776     * that will be used as the component for this Intent.
5777     *
5778     * @return Returns the same Intent object, for chaining multiple calls
5779     * into a single statement.
5780     *
5781     * @see #setComponent
5782     * @see #setClass
5783     */
5784    public Intent setClassName(Context packageContext, String className) {
5785        mComponent = new ComponentName(packageContext, className);
5786        return this;
5787    }
5788
5789    /**
5790     * Convenience for calling {@link #setComponent} with an
5791     * explicit application package name and class name.
5792     *
5793     * @param packageName The name of the package implementing the desired
5794     * component.
5795     * @param className The name of a class inside of the application package
5796     * that will be used as the component for this Intent.
5797     *
5798     * @return Returns the same Intent object, for chaining multiple calls
5799     * into a single statement.
5800     *
5801     * @see #setComponent
5802     * @see #setClass
5803     */
5804    public Intent setClassName(String packageName, String className) {
5805        mComponent = new ComponentName(packageName, className);
5806        return this;
5807    }
5808
5809    /**
5810     * Convenience for calling {@link #setComponent(ComponentName)} with the
5811     * name returned by a {@link Class} object.
5812     *
5813     * @param packageContext A Context of the application package implementing
5814     * this class.
5815     * @param cls The class name to set, equivalent to
5816     *            <code>setClassName(context, cls.getName())</code>.
5817     *
5818     * @return Returns the same Intent object, for chaining multiple calls
5819     * into a single statement.
5820     *
5821     * @see #setComponent
5822     */
5823    public Intent setClass(Context packageContext, Class<?> cls) {
5824        mComponent = new ComponentName(packageContext, cls);
5825        return this;
5826    }
5827
5828    /**
5829     * Set the bounds of the sender of this intent, in screen coordinates.  This can be
5830     * used as a hint to the receiver for animations and the like.  Null means that there
5831     * is no source bounds.
5832     */
5833    public void setSourceBounds(Rect r) {
5834        if (r != null) {
5835            mSourceBounds = new Rect(r);
5836        } else {
5837            mSourceBounds = null;
5838        }
5839    }
5840
5841    /**
5842     * Use with {@link #fillIn} to allow the current action value to be
5843     * overwritten, even if it is already set.
5844     */
5845    public static final int FILL_IN_ACTION = 1<<0;
5846
5847    /**
5848     * Use with {@link #fillIn} to allow the current data or type value
5849     * overwritten, even if it is already set.
5850     */
5851    public static final int FILL_IN_DATA = 1<<1;
5852
5853    /**
5854     * Use with {@link #fillIn} to allow the current categories to be
5855     * overwritten, even if they are already set.
5856     */
5857    public static final int FILL_IN_CATEGORIES = 1<<2;
5858
5859    /**
5860     * Use with {@link #fillIn} to allow the current component value to be
5861     * overwritten, even if it is already set.
5862     */
5863    public static final int FILL_IN_COMPONENT = 1<<3;
5864
5865    /**
5866     * Use with {@link #fillIn} to allow the current package value to be
5867     * overwritten, even if it is already set.
5868     */
5869    public static final int FILL_IN_PACKAGE = 1<<4;
5870
5871    /**
5872     * Use with {@link #fillIn} to allow the current bounds rectangle to be
5873     * overwritten, even if it is already set.
5874     */
5875    public static final int FILL_IN_SOURCE_BOUNDS = 1<<5;
5876
5877    /**
5878     * Use with {@link #fillIn} to allow the current selector to be
5879     * overwritten, even if it is already set.
5880     */
5881    public static final int FILL_IN_SELECTOR = 1<<6;
5882
5883    /**
5884     * Use with {@link #fillIn} to allow the current ClipData to be
5885     * overwritten, even if it is already set.
5886     */
5887    public static final int FILL_IN_CLIP_DATA = 1<<7;
5888
5889    /**
5890     * Copy the contents of <var>other</var> in to this object, but only
5891     * where fields are not defined by this object.  For purposes of a field
5892     * being defined, the following pieces of data in the Intent are
5893     * considered to be separate fields:
5894     *
5895     * <ul>
5896     * <li> action, as set by {@link #setAction}.
5897     * <li> data Uri and MIME type, as set by {@link #setData(Uri)},
5898     * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}.
5899     * <li> categories, as set by {@link #addCategory}.
5900     * <li> package, as set by {@link #setPackage}.
5901     * <li> component, as set by {@link #setComponent(ComponentName)} or
5902     * related methods.
5903     * <li> source bounds, as set by {@link #setSourceBounds}.
5904     * <li> selector, as set by {@link #setSelector(Intent)}.
5905     * <li> clip data, as set by {@link #setClipData(ClipData)}.
5906     * <li> each top-level name in the associated extras.
5907     * </ul>
5908     *
5909     * <p>In addition, you can use the {@link #FILL_IN_ACTION},
5910     * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
5911     * {@link #FILL_IN_COMPONENT}, {@link #FILL_IN_SOURCE_BOUNDS},
5912     * {@link #FILL_IN_SELECTOR}, and {@link #FILL_IN_CLIP_DATA} to override
5913     * the restriction where the corresponding field will not be replaced if
5914     * it is already set.
5915     *
5916     * <p>Note: The component field will only be copied if {@link #FILL_IN_COMPONENT}
5917     * is explicitly specified.  The selector will only be copied if
5918     * {@link #FILL_IN_SELECTOR} is explicitly specified.
5919     *
5920     * <p>For example, consider Intent A with {data="foo", categories="bar"}
5921     * and Intent B with {action="gotit", data-type="some/thing",
5922     * categories="one","two"}.
5923     *
5924     * <p>Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now
5925     * containing: {action="gotit", data-type="some/thing",
5926     * categories="bar"}.
5927     *
5928     * @param other Another Intent whose values are to be used to fill in
5929     * the current one.
5930     * @param flags Options to control which fields can be filled in.
5931     *
5932     * @return Returns a bit mask of {@link #FILL_IN_ACTION},
5933     * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
5934     * {@link #FILL_IN_COMPONENT}, {@link #FILL_IN_SOURCE_BOUNDS}, and
5935     * {@link #FILL_IN_SELECTOR} indicating which fields were changed.
5936     */
5937    public int fillIn(Intent other, int flags) {
5938        int changes = 0;
5939        if (other.mAction != null
5940                && (mAction == null || (flags&FILL_IN_ACTION) != 0)) {
5941            mAction = other.mAction;
5942            changes |= FILL_IN_ACTION;
5943        }
5944        if ((other.mData != null || other.mType != null)
5945                && ((mData == null && mType == null)
5946                        || (flags&FILL_IN_DATA) != 0)) {
5947            mData = other.mData;
5948            mType = other.mType;
5949            changes |= FILL_IN_DATA;
5950        }
5951        if (other.mCategories != null
5952                && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) {
5953            if (other.mCategories != null) {
5954                mCategories = new HashSet<String>(other.mCategories);
5955            }
5956            changes |= FILL_IN_CATEGORIES;
5957        }
5958        if (other.mPackage != null
5959                && (mPackage == null || (flags&FILL_IN_PACKAGE) != 0)) {
5960            // Only do this if mSelector is not set.
5961            if (mSelector == null) {
5962                mPackage = other.mPackage;
5963                changes |= FILL_IN_PACKAGE;
5964            }
5965        }
5966        // Selector is special: it can only be set if explicitly allowed,
5967        // for the same reason as the component name.
5968        if (other.mSelector != null && (flags&FILL_IN_SELECTOR) != 0) {
5969            if (mPackage == null) {
5970                mSelector = new Intent(other.mSelector);
5971                mPackage = null;
5972                changes |= FILL_IN_SELECTOR;
5973            }
5974        }
5975        if (other.mClipData != null
5976                && (mClipData == null || (flags&FILL_IN_CLIP_DATA) != 0)) {
5977            mClipData = other.mClipData;
5978            changes |= FILL_IN_CLIP_DATA;
5979        }
5980        // Component is special: it can -only- be set if explicitly allowed,
5981        // since otherwise the sender could force the intent somewhere the
5982        // originator didn't intend.
5983        if (other.mComponent != null && (flags&FILL_IN_COMPONENT) != 0) {
5984            mComponent = other.mComponent;
5985            changes |= FILL_IN_COMPONENT;
5986        }
5987        mFlags |= other.mFlags;
5988        if (other.mSourceBounds != null
5989                && (mSourceBounds == null || (flags&FILL_IN_SOURCE_BOUNDS) != 0)) {
5990            mSourceBounds = new Rect(other.mSourceBounds);
5991            changes |= FILL_IN_SOURCE_BOUNDS;
5992        }
5993        if (mExtras == null) {
5994            if (other.mExtras != null) {
5995                mExtras = new Bundle(other.mExtras);
5996            }
5997        } else if (other.mExtras != null) {
5998            try {
5999                Bundle newb = new Bundle(other.mExtras);
6000                newb.putAll(mExtras);
6001                mExtras = newb;
6002            } catch (RuntimeException e) {
6003                // Modifying the extras can cause us to unparcel the contents
6004                // of the bundle, and if we do this in the system process that
6005                // may fail.  We really should handle this (i.e., the Bundle
6006                // impl shouldn't be on top of a plain map), but for now just
6007                // ignore it and keep the original contents. :(
6008                Log.w("Intent", "Failure filling in extras", e);
6009            }
6010        }
6011        return changes;
6012    }
6013
6014    /**
6015     * Wrapper class holding an Intent and implementing comparisons on it for
6016     * the purpose of filtering.  The class implements its
6017     * {@link #equals equals()} and {@link #hashCode hashCode()} methods as
6018     * simple calls to {@link Intent#filterEquals(Intent)}  filterEquals()} and
6019     * {@link android.content.Intent#filterHashCode()}  filterHashCode()}
6020     * on the wrapped Intent.
6021     */
6022    public static final class FilterComparison {
6023        private final Intent mIntent;
6024        private final int mHashCode;
6025
6026        public FilterComparison(Intent intent) {
6027            mIntent = intent;
6028            mHashCode = intent.filterHashCode();
6029        }
6030
6031        /**
6032         * Return the Intent that this FilterComparison represents.
6033         * @return Returns the Intent held by the FilterComparison.  Do
6034         * not modify!
6035         */
6036        public Intent getIntent() {
6037            return mIntent;
6038        }
6039
6040        @Override
6041        public boolean equals(Object obj) {
6042            if (obj instanceof FilterComparison) {
6043                Intent other = ((FilterComparison)obj).mIntent;
6044                return mIntent.filterEquals(other);
6045            }
6046            return false;
6047        }
6048
6049        @Override
6050        public int hashCode() {
6051            return mHashCode;
6052        }
6053    }
6054
6055    /**
6056     * Determine if two intents are the same for the purposes of intent
6057     * resolution (filtering). That is, if their action, data, type,
6058     * class, and categories are the same.  This does <em>not</em> compare
6059     * any extra data included in the intents.
6060     *
6061     * @param other The other Intent to compare against.
6062     *
6063     * @return Returns true if action, data, type, class, and categories
6064     *         are the same.
6065     */
6066    public boolean filterEquals(Intent other) {
6067        if (other == null) {
6068            return false;
6069        }
6070        if (mAction != other.mAction) {
6071            if (mAction != null) {
6072                if (!mAction.equals(other.mAction)) {
6073                    return false;
6074                }
6075            } else {
6076                if (!other.mAction.equals(mAction)) {
6077                    return false;
6078                }
6079            }
6080        }
6081        if (mData != other.mData) {
6082            if (mData != null) {
6083                if (!mData.equals(other.mData)) {
6084                    return false;
6085                }
6086            } else {
6087                if (!other.mData.equals(mData)) {
6088                    return false;
6089                }
6090            }
6091        }
6092        if (mType != other.mType) {
6093            if (mType != null) {
6094                if (!mType.equals(other.mType)) {
6095                    return false;
6096                }
6097            } else {
6098                if (!other.mType.equals(mType)) {
6099                    return false;
6100                }
6101            }
6102        }
6103        if (mPackage != other.mPackage) {
6104            if (mPackage != null) {
6105                if (!mPackage.equals(other.mPackage)) {
6106                    return false;
6107                }
6108            } else {
6109                if (!other.mPackage.equals(mPackage)) {
6110                    return false;
6111                }
6112            }
6113        }
6114        if (mComponent != other.mComponent) {
6115            if (mComponent != null) {
6116                if (!mComponent.equals(other.mComponent)) {
6117                    return false;
6118                }
6119            } else {
6120                if (!other.mComponent.equals(mComponent)) {
6121                    return false;
6122                }
6123            }
6124        }
6125        if (mCategories != other.mCategories) {
6126            if (mCategories != null) {
6127                if (!mCategories.equals(other.mCategories)) {
6128                    return false;
6129                }
6130            } else {
6131                if (!other.mCategories.equals(mCategories)) {
6132                    return false;
6133                }
6134            }
6135        }
6136
6137        return true;
6138    }
6139
6140    /**
6141     * Generate hash code that matches semantics of filterEquals().
6142     *
6143     * @return Returns the hash value of the action, data, type, class, and
6144     *         categories.
6145     *
6146     * @see #filterEquals
6147     */
6148    public int filterHashCode() {
6149        int code = 0;
6150        if (mAction != null) {
6151            code += mAction.hashCode();
6152        }
6153        if (mData != null) {
6154            code += mData.hashCode();
6155        }
6156        if (mType != null) {
6157            code += mType.hashCode();
6158        }
6159        if (mPackage != null) {
6160            code += mPackage.hashCode();
6161        }
6162        if (mComponent != null) {
6163            code += mComponent.hashCode();
6164        }
6165        if (mCategories != null) {
6166            code += mCategories.hashCode();
6167        }
6168        return code;
6169    }
6170
6171    @Override
6172    public String toString() {
6173        StringBuilder b = new StringBuilder(128);
6174
6175        b.append("Intent { ");
6176        toShortString(b, true, true, true, false);
6177        b.append(" }");
6178
6179        return b.toString();
6180    }
6181
6182    /** @hide */
6183    public String toInsecureString() {
6184        StringBuilder b = new StringBuilder(128);
6185
6186        b.append("Intent { ");
6187        toShortString(b, false, true, true, false);
6188        b.append(" }");
6189
6190        return b.toString();
6191    }
6192
6193    /** @hide */
6194    public String toInsecureStringWithClip() {
6195        StringBuilder b = new StringBuilder(128);
6196
6197        b.append("Intent { ");
6198        toShortString(b, false, true, true, true);
6199        b.append(" }");
6200
6201        return b.toString();
6202    }
6203
6204    /** @hide */
6205    public String toShortString(boolean secure, boolean comp, boolean extras, boolean clip) {
6206        StringBuilder b = new StringBuilder(128);
6207        toShortString(b, secure, comp, extras, clip);
6208        return b.toString();
6209    }
6210
6211    /** @hide */
6212    public void toShortString(StringBuilder b, boolean secure, boolean comp, boolean extras,
6213            boolean clip) {
6214        boolean first = true;
6215        if (mAction != null) {
6216            b.append("act=").append(mAction);
6217            first = false;
6218        }
6219        if (mCategories != null) {
6220            if (!first) {
6221                b.append(' ');
6222            }
6223            first = false;
6224            b.append("cat=[");
6225            Iterator<String> i = mCategories.iterator();
6226            boolean didone = false;
6227            while (i.hasNext()) {
6228                if (didone) b.append(",");
6229                didone = true;
6230                b.append(i.next());
6231            }
6232            b.append("]");
6233        }
6234        if (mData != null) {
6235            if (!first) {
6236                b.append(' ');
6237            }
6238            first = false;
6239            b.append("dat=");
6240            if (secure) {
6241                b.append(mData.toSafeString());
6242            } else {
6243                b.append(mData);
6244            }
6245        }
6246        if (mType != null) {
6247            if (!first) {
6248                b.append(' ');
6249            }
6250            first = false;
6251            b.append("typ=").append(mType);
6252        }
6253        if (mFlags != 0) {
6254            if (!first) {
6255                b.append(' ');
6256            }
6257            first = false;
6258            b.append("flg=0x").append(Integer.toHexString(mFlags));
6259        }
6260        if (mPackage != null) {
6261            if (!first) {
6262                b.append(' ');
6263            }
6264            first = false;
6265            b.append("pkg=").append(mPackage);
6266        }
6267        if (comp && mComponent != null) {
6268            if (!first) {
6269                b.append(' ');
6270            }
6271            first = false;
6272            b.append("cmp=").append(mComponent.flattenToShortString());
6273        }
6274        if (mSourceBounds != null) {
6275            if (!first) {
6276                b.append(' ');
6277            }
6278            first = false;
6279            b.append("bnds=").append(mSourceBounds.toShortString());
6280        }
6281        if (mClipData != null) {
6282            if (!first) {
6283                b.append(' ');
6284            }
6285            first = false;
6286            if (clip) {
6287                b.append("clip={");
6288                mClipData.toShortString(b);
6289                b.append('}');
6290            } else {
6291                b.append("(has clip)");
6292            }
6293        }
6294        if (extras && mExtras != null) {
6295            if (!first) {
6296                b.append(' ');
6297            }
6298            first = false;
6299            b.append("(has extras)");
6300        }
6301        if (mSelector != null) {
6302            b.append(" sel={");
6303            mSelector.toShortString(b, secure, comp, extras, clip);
6304            b.append("}");
6305        }
6306    }
6307
6308    /**
6309     * Call {@link #toUri} with 0 flags.
6310     * @deprecated Use {@link #toUri} instead.
6311     */
6312    @Deprecated
6313    public String toURI() {
6314        return toUri(0);
6315    }
6316
6317    /**
6318     * Convert this Intent into a String holding a URI representation of it.
6319     * The returned URI string has been properly URI encoded, so it can be
6320     * used with {@link Uri#parse Uri.parse(String)}.  The URI contains the
6321     * Intent's data as the base URI, with an additional fragment describing
6322     * the action, categories, type, flags, package, component, and extras.
6323     *
6324     * <p>You can convert the returned string back to an Intent with
6325     * {@link #getIntent}.
6326     *
6327     * @param flags Additional operating flags.  Either 0 or
6328     * {@link #URI_INTENT_SCHEME}.
6329     *
6330     * @return Returns a URI encoding URI string describing the entire contents
6331     * of the Intent.
6332     */
6333    public String toUri(int flags) {
6334        StringBuilder uri = new StringBuilder(128);
6335        String scheme = null;
6336        if (mData != null) {
6337            String data = mData.toString();
6338            if ((flags&URI_INTENT_SCHEME) != 0) {
6339                final int N = data.length();
6340                for (int i=0; i<N; i++) {
6341                    char c = data.charAt(i);
6342                    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
6343                            || c == '.' || c == '-') {
6344                        continue;
6345                    }
6346                    if (c == ':' && i > 0) {
6347                        // Valid scheme.
6348                        scheme = data.substring(0, i);
6349                        uri.append("intent:");
6350                        data = data.substring(i+1);
6351                        break;
6352                    }
6353
6354                    // No scheme.
6355                    break;
6356                }
6357            }
6358            uri.append(data);
6359
6360        } else if ((flags&URI_INTENT_SCHEME) != 0) {
6361            uri.append("intent:");
6362        }
6363
6364        uri.append("#Intent;");
6365
6366        toUriInner(uri, scheme, flags);
6367        if (mSelector != null) {
6368            uri.append("SEL;");
6369            // Note that for now we are not going to try to handle the
6370            // data part; not clear how to represent this as a URI, and
6371            // not much utility in it.
6372            mSelector.toUriInner(uri, null, flags);
6373        }
6374
6375        uri.append("end");
6376
6377        return uri.toString();
6378    }
6379
6380    private void toUriInner(StringBuilder uri, String scheme, int flags) {
6381        if (scheme != null) {
6382            uri.append("scheme=").append(scheme).append(';');
6383        }
6384        if (mAction != null) {
6385            uri.append("action=").append(Uri.encode(mAction)).append(';');
6386        }
6387        if (mCategories != null) {
6388            for (String category : mCategories) {
6389                uri.append("category=").append(Uri.encode(category)).append(';');
6390            }
6391        }
6392        if (mType != null) {
6393            uri.append("type=").append(Uri.encode(mType, "/")).append(';');
6394        }
6395        if (mFlags != 0) {
6396            uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
6397        }
6398        if (mPackage != null) {
6399            uri.append("package=").append(Uri.encode(mPackage)).append(';');
6400        }
6401        if (mComponent != null) {
6402            uri.append("component=").append(Uri.encode(
6403                    mComponent.flattenToShortString(), "/")).append(';');
6404        }
6405        if (mSourceBounds != null) {
6406            uri.append("sourceBounds=")
6407                    .append(Uri.encode(mSourceBounds.flattenToString()))
6408                    .append(';');
6409        }
6410        if (mExtras != null) {
6411            for (String key : mExtras.keySet()) {
6412                final Object value = mExtras.get(key);
6413                char entryType =
6414                        value instanceof String    ? 'S' :
6415                        value instanceof Boolean   ? 'B' :
6416                        value instanceof Byte      ? 'b' :
6417                        value instanceof Character ? 'c' :
6418                        value instanceof Double    ? 'd' :
6419                        value instanceof Float     ? 'f' :
6420                        value instanceof Integer   ? 'i' :
6421                        value instanceof Long      ? 'l' :
6422                        value instanceof Short     ? 's' :
6423                        '\0';
6424
6425                if (entryType != '\0') {
6426                    uri.append(entryType);
6427                    uri.append('.');
6428                    uri.append(Uri.encode(key));
6429                    uri.append('=');
6430                    uri.append(Uri.encode(value.toString()));
6431                    uri.append(';');
6432                }
6433            }
6434        }
6435    }
6436
6437    public int describeContents() {
6438        return (mExtras != null) ? mExtras.describeContents() : 0;
6439    }
6440
6441    public void writeToParcel(Parcel out, int flags) {
6442        out.writeString(mAction);
6443        Uri.writeToParcel(out, mData);
6444        out.writeString(mType);
6445        out.writeInt(mFlags);
6446        out.writeString(mPackage);
6447        ComponentName.writeToParcel(mComponent, out);
6448
6449        if (mSourceBounds != null) {
6450            out.writeInt(1);
6451            mSourceBounds.writeToParcel(out, flags);
6452        } else {
6453            out.writeInt(0);
6454        }
6455
6456        if (mCategories != null) {
6457            out.writeInt(mCategories.size());
6458            for (String category : mCategories) {
6459                out.writeString(category);
6460            }
6461        } else {
6462            out.writeInt(0);
6463        }
6464
6465        if (mSelector != null) {
6466            out.writeInt(1);
6467            mSelector.writeToParcel(out, flags);
6468        } else {
6469            out.writeInt(0);
6470        }
6471
6472        if (mClipData != null) {
6473            out.writeInt(1);
6474            mClipData.writeToParcel(out, flags);
6475        } else {
6476            out.writeInt(0);
6477        }
6478
6479        out.writeBundle(mExtras);
6480    }
6481
6482    public static final Parcelable.Creator<Intent> CREATOR
6483            = new Parcelable.Creator<Intent>() {
6484        public Intent createFromParcel(Parcel in) {
6485            return new Intent(in);
6486        }
6487        public Intent[] newArray(int size) {
6488            return new Intent[size];
6489        }
6490    };
6491
6492    /** @hide */
6493    protected Intent(Parcel in) {
6494        readFromParcel(in);
6495    }
6496
6497    public void readFromParcel(Parcel in) {
6498        setAction(in.readString());
6499        mData = Uri.CREATOR.createFromParcel(in);
6500        mType = in.readString();
6501        mFlags = in.readInt();
6502        mPackage = in.readString();
6503        mComponent = ComponentName.readFromParcel(in);
6504
6505        if (in.readInt() != 0) {
6506            mSourceBounds = Rect.CREATOR.createFromParcel(in);
6507        }
6508
6509        int N = in.readInt();
6510        if (N > 0) {
6511            mCategories = new HashSet<String>();
6512            int i;
6513            for (i=0; i<N; i++) {
6514                mCategories.add(in.readString().intern());
6515            }
6516        } else {
6517            mCategories = null;
6518        }
6519
6520        if (in.readInt() != 0) {
6521            mSelector = new Intent(in);
6522        }
6523
6524        if (in.readInt() != 0) {
6525            mClipData = new ClipData(in);
6526        }
6527
6528        mExtras = in.readBundle();
6529    }
6530
6531    /**
6532     * Parses the "intent" element (and its children) from XML and instantiates
6533     * an Intent object.  The given XML parser should be located at the tag
6534     * where parsing should start (often named "intent"), from which the
6535     * basic action, data, type, and package and class name will be
6536     * retrieved.  The function will then parse in to any child elements,
6537     * looking for <category android:name="xxx"> tags to add categories and
6538     * <extra android:name="xxx" android:value="yyy"> to attach extra data
6539     * to the intent.
6540     *
6541     * @param resources The Resources to use when inflating resources.
6542     * @param parser The XML parser pointing at an "intent" tag.
6543     * @param attrs The AttributeSet interface for retrieving extended
6544     * attribute data at the current <var>parser</var> location.
6545     * @return An Intent object matching the XML data.
6546     * @throws XmlPullParserException If there was an XML parsing error.
6547     * @throws IOException If there was an I/O error.
6548     */
6549    public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
6550            throws XmlPullParserException, IOException {
6551        Intent intent = new Intent();
6552
6553        TypedArray sa = resources.obtainAttributes(attrs,
6554                com.android.internal.R.styleable.Intent);
6555
6556        intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action));
6557
6558        String data = sa.getString(com.android.internal.R.styleable.Intent_data);
6559        String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType);
6560        intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType);
6561
6562        String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage);
6563        String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass);
6564        if (packageName != null && className != null) {
6565            intent.setComponent(new ComponentName(packageName, className));
6566        }
6567
6568        sa.recycle();
6569
6570        int outerDepth = parser.getDepth();
6571        int type;
6572        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
6573               && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
6574            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
6575                continue;
6576            }
6577
6578            String nodeName = parser.getName();
6579            if (nodeName.equals("category")) {
6580                sa = resources.obtainAttributes(attrs,
6581                        com.android.internal.R.styleable.IntentCategory);
6582                String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name);
6583                sa.recycle();
6584
6585                if (cat != null) {
6586                    intent.addCategory(cat);
6587                }
6588                XmlUtils.skipCurrentTag(parser);
6589
6590            } else if (nodeName.equals("extra")) {
6591                if (intent.mExtras == null) {
6592                    intent.mExtras = new Bundle();
6593                }
6594                resources.parseBundleExtra("extra", attrs, intent.mExtras);
6595                XmlUtils.skipCurrentTag(parser);
6596
6597            } else {
6598                XmlUtils.skipCurrentTag(parser);
6599            }
6600        }
6601
6602        return intent;
6603    }
6604
6605    /**
6606     * Normalize a MIME data type.
6607     *
6608     * <p>A normalized MIME type has white-space trimmed,
6609     * content-type parameters removed, and is lower-case.
6610     * This aligns the type with Android best practices for
6611     * intent filtering.
6612     *
6613     * <p>For example, "text/plain; charset=utf-8" becomes "text/plain".
6614     * "text/x-vCard" becomes "text/x-vcard".
6615     *
6616     * <p>All MIME types received from outside Android (such as user input,
6617     * or external sources like Bluetooth, NFC, or the Internet) should
6618     * be normalized before they are used to create an Intent.
6619     *
6620     * @param type MIME data type to normalize
6621     * @return normalized MIME data type, or null if the input was null
6622     * @see {@link #setType}
6623     * @see {@link #setTypeAndNormalize}
6624     */
6625    public static String normalizeMimeType(String type) {
6626        if (type == null) {
6627            return null;
6628        }
6629
6630        type = type.trim().toLowerCase(Locale.US);
6631
6632        final int semicolonIndex = type.indexOf(';');
6633        if (semicolonIndex != -1) {
6634            type = type.substring(0, semicolonIndex);
6635        }
6636        return type;
6637    }
6638
6639    /**
6640     * Migrate any {@link #EXTRA_STREAM} in {@link #ACTION_SEND} and
6641     * {@link #ACTION_SEND_MULTIPLE} to {@link ClipData}. Also inspects nested
6642     * intents in {@link #ACTION_CHOOSER}.
6643     *
6644     * @return Whether any contents were migrated.
6645     * @hide
6646     */
6647    public boolean migrateExtraStreamToClipData() {
6648        // Refuse to touch if extras already parcelled
6649        if (mExtras != null && mExtras.isParcelled()) return false;
6650
6651        // Bail when someone already gave us ClipData
6652        if (getClipData() != null) return false;
6653
6654        final String action = getAction();
6655        if (ACTION_CHOOSER.equals(action)) {
6656            try {
6657                // Inspect target intent to see if we need to migrate
6658                final Intent target = getParcelableExtra(EXTRA_INTENT);
6659                if (target != null && target.migrateExtraStreamToClipData()) {
6660                    // Since we migrated in child, we need to promote ClipData
6661                    // and flags to ourselves to grant.
6662                    setClipData(target.getClipData());
6663                    addFlags(target.getFlags()
6664                            & (FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION));
6665                    return true;
6666                } else {
6667                    return false;
6668                }
6669            } catch (ClassCastException e) {
6670            }
6671
6672        } else if (ACTION_SEND.equals(action)) {
6673            try {
6674                final Uri stream = getParcelableExtra(EXTRA_STREAM);
6675                final CharSequence text = getCharSequenceExtra(EXTRA_TEXT);
6676                final String htmlText = getStringExtra(EXTRA_HTML_TEXT);
6677                if (stream != null || text != null || htmlText != null) {
6678                    final ClipData clipData = new ClipData(
6679                            null, new String[] { getType() },
6680                            new ClipData.Item(text, htmlText, null, stream));
6681                    setClipData(clipData);
6682                    addFlags(FLAG_GRANT_READ_URI_PERMISSION);
6683                    return true;
6684                }
6685            } catch (ClassCastException e) {
6686            }
6687
6688        } else if (ACTION_SEND_MULTIPLE.equals(action)) {
6689            try {
6690                final ArrayList<Uri> streams = getParcelableArrayListExtra(EXTRA_STREAM);
6691                final ArrayList<CharSequence> texts = getCharSequenceArrayListExtra(EXTRA_TEXT);
6692                final ArrayList<String> htmlTexts = getStringArrayListExtra(EXTRA_HTML_TEXT);
6693                int num = -1;
6694                if (streams != null) {
6695                    num = streams.size();
6696                }
6697                if (texts != null) {
6698                    if (num >= 0 && num != texts.size()) {
6699                        // Wha...!  F- you.
6700                        return false;
6701                    }
6702                    num = texts.size();
6703                }
6704                if (htmlTexts != null) {
6705                    if (num >= 0 && num != htmlTexts.size()) {
6706                        // Wha...!  F- you.
6707                        return false;
6708                    }
6709                    num = htmlTexts.size();
6710                }
6711                if (num > 0) {
6712                    final ClipData clipData = new ClipData(
6713                            null, new String[] { getType() },
6714                            makeClipItem(streams, texts, htmlTexts, 0));
6715
6716                    for (int i = 1; i < num; i++) {
6717                        clipData.addItem(makeClipItem(streams, texts, htmlTexts, i));
6718                    }
6719
6720                    setClipData(clipData);
6721                    addFlags(FLAG_GRANT_READ_URI_PERMISSION);
6722                    return true;
6723                }
6724            } catch (ClassCastException e) {
6725            }
6726        }
6727
6728        return false;
6729    }
6730
6731    private static ClipData.Item makeClipItem(ArrayList<Uri> streams, ArrayList<CharSequence> texts,
6732            ArrayList<String> htmlTexts, int which) {
6733        Uri uri = streams != null ? streams.get(which) : null;
6734        CharSequence text = texts != null ? texts.get(which) : null;
6735        String htmlText = htmlTexts != null ? htmlTexts.get(which) : null;
6736        return new ClipData.Item(text, htmlText, null, uri);
6737    }
6738}
6739