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