Intent.java revision a8057a9dcef71f9b3e0f31e830d750337a4349ba
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 android.content.pm.ApplicationInfo;
20import android.os.ResultReceiver;
21import android.os.ShellCommand;
22import android.provider.MediaStore;
23import android.util.ArraySet;
24
25import org.xmlpull.v1.XmlPullParser;
26import org.xmlpull.v1.XmlPullParserException;
27
28import android.annotation.AnyRes;
29import android.annotation.IntDef;
30import android.annotation.SdkConstant;
31import android.annotation.SystemApi;
32import android.annotation.SdkConstant.SdkConstantType;
33import android.content.pm.ActivityInfo;
34
35import static android.content.ContentProvider.maybeAddUserId;
36
37import android.content.pm.PackageManager;
38import android.content.pm.ResolveInfo;
39import android.content.res.Resources;
40import android.content.res.TypedArray;
41import android.graphics.Rect;
42import android.net.Uri;
43import android.os.Bundle;
44import android.os.IBinder;
45import android.os.Parcel;
46import android.os.Parcelable;
47import android.os.Process;
48import android.os.StrictMode;
49import android.os.UserHandle;
50import android.provider.DocumentsContract;
51import android.provider.DocumentsProvider;
52import android.provider.OpenableColumns;
53import android.util.AttributeSet;
54import android.util.Log;
55
56import com.android.internal.util.XmlUtils;
57
58import org.xmlpull.v1.XmlSerializer;
59
60import java.io.IOException;
61import java.io.PrintWriter;
62import java.io.Serializable;
63import java.lang.annotation.Retention;
64import java.lang.annotation.RetentionPolicy;
65import java.net.URISyntaxException;
66import java.util.ArrayList;
67import java.util.HashSet;
68import java.util.List;
69import java.util.Locale;
70import java.util.Objects;
71import java.util.Set;
72
73/**
74 * An intent is an abstract description of an operation to be performed.  It
75 * can be used with {@link Context#startActivity(Intent) startActivity} to
76 * launch an {@link android.app.Activity},
77 * {@link android.content.Context#sendBroadcast(Intent) broadcastIntent} to
78 * send it to any interested {@link BroadcastReceiver BroadcastReceiver} components,
79 * and {@link android.content.Context#startService} or
80 * {@link android.content.Context#bindService} to communicate with a
81 * background {@link android.app.Service}.
82 *
83 * <p>An Intent provides a facility for performing late runtime binding between the code in
84 * different applications. Its most significant use is in the launching of activities, where it
85 * can be thought of as the glue between activities. It is basically a passive data structure
86 * holding an abstract description of an action to be performed.</p>
87 *
88 * <div class="special reference">
89 * <h3>Developer Guides</h3>
90 * <p>For information about how to create and resolve intents, read the
91 * <a href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and Intent Filters</a>
92 * developer guide.</p>
93 * </div>
94 *
95 * <a name="IntentStructure"></a>
96 * <h3>Intent Structure</h3>
97 * <p>The primary pieces of information in an intent are:</p>
98 *
99 * <ul>
100 *   <li> <p><b>action</b> -- The general action to be performed, such as
101 *     {@link #ACTION_VIEW}, {@link #ACTION_EDIT}, {@link #ACTION_MAIN},
102 *     etc.</p>
103 *   </li>
104 *   <li> <p><b>data</b> -- The data to operate on, such as a person record
105 *     in the contacts database, expressed as a {@link android.net.Uri}.</p>
106 *   </li>
107 * </ul>
108 *
109 *
110 * <p>Some examples of action/data pairs are:</p>
111 *
112 * <ul>
113 *   <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/1</i></b> -- Display
114 *     information about the person whose identifier is "1".</p>
115 *   </li>
116 *   <li> <p><b>{@link #ACTION_DIAL} <i>content://contacts/people/1</i></b> -- Display
117 *     the phone dialer with the person filled in.</p>
118 *   </li>
119 *   <li> <p><b>{@link #ACTION_VIEW} <i>tel:123</i></b> -- Display
120 *     the phone dialer with the given number filled in.  Note how the
121 *     VIEW action does what what is considered the most reasonable thing for
122 *     a particular URI.</p>
123 *   </li>
124 *   <li> <p><b>{@link #ACTION_DIAL} <i>tel:123</i></b> -- Display
125 *     the phone dialer with the given number filled in.</p>
126 *   </li>
127 *   <li> <p><b>{@link #ACTION_EDIT} <i>content://contacts/people/1</i></b> -- Edit
128 *     information about the person whose identifier is "1".</p>
129 *   </li>
130 *   <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/</i></b> -- Display
131 *     a list of people, which the user can browse through.  This example is a
132 *     typical top-level entry into the Contacts application, showing you the
133 *     list of people. Selecting a particular person to view would result in a
134 *     new intent { <b>{@link #ACTION_VIEW} <i>content://contacts/N</i></b> }
135 *     being used to start an activity to display that person.</p>
136 *   </li>
137 * </ul>
138 *
139 * <p>In addition to these primary attributes, there are a number of secondary
140 * attributes that you can also include with an intent:</p>
141 *
142 * <ul>
143 *     <li> <p><b>category</b> -- Gives additional information about the action
144 *         to execute.  For example, {@link #CATEGORY_LAUNCHER} means it should
145 *         appear in the Launcher as a top-level application, while
146 *         {@link #CATEGORY_ALTERNATIVE} means it should be included in a list
147 *         of alternative actions the user can perform on a piece of data.</p>
148 *     <li> <p><b>type</b> -- Specifies an explicit type (a MIME type) of the
149 *         intent data.  Normally the type is inferred from the data itself.
150 *         By setting this attribute, you disable that evaluation and force
151 *         an explicit type.</p>
152 *     <li> <p><b>component</b> -- Specifies an explicit name of a component
153 *         class to use for the intent.  Normally this is determined by looking
154 *         at the other information in the intent (the action, data/type, and
155 *         categories) and matching that with a component that can handle it.
156 *         If this attribute is set then none of the evaluation is performed,
157 *         and this component is used exactly as is.  By specifying this attribute,
158 *         all of the other Intent attributes become optional.</p>
159 *     <li> <p><b>extras</b> -- This is a {@link Bundle} of any additional information.
160 *         This can be used to provide extended information to the component.
161 *         For example, if we have a action to send an e-mail message, we could
162 *         also include extra pieces of data here to supply a subject, body,
163 *         etc.</p>
164 * </ul>
165 *
166 * <p>Here are some examples of other operations you can specify as intents
167 * using these additional parameters:</p>
168 *
169 * <ul>
170 *   <li> <p><b>{@link #ACTION_MAIN} with category {@link #CATEGORY_HOME}</b> --
171 *     Launch the home screen.</p>
172 *   </li>
173 *   <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
174 *     <i>{@link android.provider.Contacts.Phones#CONTENT_URI
175 *     vnd.android.cursor.item/phone}</i></b>
176 *     -- Display the list of people's phone numbers, allowing the user to
177 *     browse through them and pick one and return it to the parent activity.</p>
178 *   </li>
179 *   <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
180 *     <i>*{@literal /}*</i> and category {@link #CATEGORY_OPENABLE}</b>
181 *     -- Display all pickers for data that can be opened with
182 *     {@link ContentResolver#openInputStream(Uri) ContentResolver.openInputStream()},
183 *     allowing the user to pick one of them and then some data inside of it
184 *     and returning the resulting URI to the caller.  This can be used,
185 *     for example, in an e-mail application to allow the user to pick some
186 *     data to include as an attachment.</p>
187 *   </li>
188 * </ul>
189 *
190 * <p>There are a variety of standard Intent action and category constants
191 * defined in the Intent class, but applications can also define their own.
192 * These strings use java style scoping, to ensure they are unique -- for
193 * example, the standard {@link #ACTION_VIEW} is called
194 * "android.intent.action.VIEW".</p>
195 *
196 * <p>Put together, the set of actions, data types, categories, and extra data
197 * defines a language for the system allowing for the expression of phrases
198 * such as "call john smith's cell".  As applications are added to the system,
199 * they can extend this language by adding new actions, types, and categories, or
200 * they can modify the behavior of existing phrases by supplying their own
201 * activities that handle them.</p>
202 *
203 * <a name="IntentResolution"></a>
204 * <h3>Intent Resolution</h3>
205 *
206 * <p>There are two primary forms of intents you will use.
207 *
208 * <ul>
209 *     <li> <p><b>Explicit Intents</b> have specified a component (via
210 *     {@link #setComponent} or {@link #setClass}), which provides the exact
211 *     class to be run.  Often these will not include any other information,
212 *     simply being a way for an application to launch various internal
213 *     activities it has as the user interacts with the application.
214 *
215 *     <li> <p><b>Implicit Intents</b> have not specified a component;
216 *     instead, they must include enough information for the system to
217 *     determine which of the available components is best to run for that
218 *     intent.
219 * </ul>
220 *
221 * <p>When using implicit intents, given such an arbitrary intent we need to
222 * know what to do with it. This is handled by the process of <em>Intent
223 * resolution</em>, which maps an Intent to an {@link android.app.Activity},
224 * {@link BroadcastReceiver}, or {@link android.app.Service} (or sometimes two or
225 * more activities/receivers) that can handle it.</p>
226 *
227 * <p>The intent resolution mechanism basically revolves around matching an
228 * Intent against all of the &lt;intent-filter&gt; descriptions in the
229 * installed application packages.  (Plus, in the case of broadcasts, any {@link BroadcastReceiver}
230 * objects explicitly registered with {@link Context#registerReceiver}.)  More
231 * details on this can be found in the documentation on the {@link
232 * IntentFilter} class.</p>
233 *
234 * <p>There are three pieces of information in the Intent that are used for
235 * resolution: the action, type, and category.  Using this information, a query
236 * is done on the {@link PackageManager} for a component that can handle the
237 * intent. The appropriate component is determined based on the intent
238 * information supplied in the <code>AndroidManifest.xml</code> file as
239 * follows:</p>
240 *
241 * <ul>
242 *     <li> <p>The <b>action</b>, if given, must be listed by the component as
243 *         one it handles.</p>
244 *     <li> <p>The <b>type</b> is retrieved from the Intent's data, if not
245 *         already supplied in the Intent.  Like the action, if a type is
246 *         included in the intent (either explicitly or implicitly in its
247 *         data), then this must be listed by the component as one it handles.</p>
248 *     <li> For data that is not a <code>content:</code> URI and where no explicit
249 *         type is included in the Intent, instead the <b>scheme</b> of the
250 *         intent data (such as <code>http:</code> or <code>mailto:</code>) is
251 *         considered. Again like the action, if we are matching a scheme it
252 *         must be listed by the component as one it can handle.
253 *     <li> <p>The <b>categories</b>, if supplied, must <em>all</em> be listed
254 *         by the activity as categories it handles.  That is, if you include
255 *         the categories {@link #CATEGORY_LAUNCHER} and
256 *         {@link #CATEGORY_ALTERNATIVE}, then you will only resolve to components
257 *         with an intent that lists <em>both</em> of those categories.
258 *         Activities will very often need to support the
259 *         {@link #CATEGORY_DEFAULT} so that they can be found by
260 *         {@link Context#startActivity Context.startActivity()}.</p>
261 * </ul>
262 *
263 * <p>For example, consider the Note Pad sample application that
264 * allows user to browse through a list of notes data and view details about
265 * individual items.  Text in italics indicate places were you would replace a
266 * name with one specific to your own package.</p>
267 *
268 * <pre> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
269 *       package="<i>com.android.notepad</i>"&gt;
270 *     &lt;application android:icon="@drawable/app_notes"
271 *             android:label="@string/app_name"&gt;
272 *
273 *         &lt;provider class=".NotePadProvider"
274 *                 android:authorities="<i>com.google.provider.NotePad</i>" /&gt;
275 *
276 *         &lt;activity class=".NotesList" android:label="@string/title_notes_list"&gt;
277 *             &lt;intent-filter&gt;
278 *                 &lt;action android:name="android.intent.action.MAIN" /&gt;
279 *                 &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
280 *             &lt;/intent-filter&gt;
281 *             &lt;intent-filter&gt;
282 *                 &lt;action android:name="android.intent.action.VIEW" /&gt;
283 *                 &lt;action android:name="android.intent.action.EDIT" /&gt;
284 *                 &lt;action android:name="android.intent.action.PICK" /&gt;
285 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
286 *                 &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
287 *             &lt;/intent-filter&gt;
288 *             &lt;intent-filter&gt;
289 *                 &lt;action android:name="android.intent.action.GET_CONTENT" /&gt;
290 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
291 *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
292 *             &lt;/intent-filter&gt;
293 *         &lt;/activity&gt;
294 *
295 *         &lt;activity class=".NoteEditor" android:label="@string/title_note"&gt;
296 *             &lt;intent-filter android:label="@string/resolve_edit"&gt;
297 *                 &lt;action android:name="android.intent.action.VIEW" /&gt;
298 *                 &lt;action android:name="android.intent.action.EDIT" /&gt;
299 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
300 *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
301 *             &lt;/intent-filter&gt;
302 *
303 *             &lt;intent-filter&gt;
304 *                 &lt;action android:name="android.intent.action.INSERT" /&gt;
305 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
306 *                 &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
307 *             &lt;/intent-filter&gt;
308 *
309 *         &lt;/activity&gt;
310 *
311 *         &lt;activity class=".TitleEditor" android:label="@string/title_edit_title"
312 *                 android:theme="@android:style/Theme.Dialog"&gt;
313 *             &lt;intent-filter android:label="@string/resolve_title"&gt;
314 *                 &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
315 *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
316 *                 &lt;category android:name="android.intent.category.ALTERNATIVE" /&gt;
317 *                 &lt;category android:name="android.intent.category.SELECTED_ALTERNATIVE" /&gt;
318 *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
319 *             &lt;/intent-filter&gt;
320 *         &lt;/activity&gt;
321 *
322 *     &lt;/application&gt;
323 * &lt;/manifest&gt;</pre>
324 *
325 * <p>The first activity,
326 * <code>com.android.notepad.NotesList</code>, serves as our main
327 * entry into the app.  It can do three things as described by its three intent
328 * templates:
329 * <ol>
330 * <li><pre>
331 * &lt;intent-filter&gt;
332 *     &lt;action android:name="{@link #ACTION_MAIN android.intent.action.MAIN}" /&gt;
333 *     &lt;category android:name="{@link #CATEGORY_LAUNCHER android.intent.category.LAUNCHER}" /&gt;
334 * &lt;/intent-filter&gt;</pre>
335 * <p>This provides a top-level entry into the NotePad application: the standard
336 * MAIN action is a main entry point (not requiring any other information in
337 * the Intent), and the LAUNCHER category says that this entry point should be
338 * listed in the application launcher.</p>
339 * <li><pre>
340 * &lt;intent-filter&gt;
341 *     &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
342 *     &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
343 *     &lt;action android:name="{@link #ACTION_PICK android.intent.action.PICK}" /&gt;
344 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
345 *     &lt;data mimeType:name="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
346 * &lt;/intent-filter&gt;</pre>
347 * <p>This declares the things that the activity can do on a directory of
348 * notes.  The type being supported is given with the &lt;type&gt; tag, where
349 * <code>vnd.android.cursor.dir/vnd.google.note</code> is a URI from which
350 * a Cursor of zero or more items (<code>vnd.android.cursor.dir</code>) can
351 * be retrieved which holds our note pad data (<code>vnd.google.note</code>).
352 * The activity allows the user to view or edit the directory of data (via
353 * the VIEW and EDIT actions), or to pick a particular note and return it
354 * to the caller (via the PICK action).  Note also the DEFAULT category
355 * supplied here: this is <em>required</em> for the
356 * {@link Context#startActivity Context.startActivity} method to resolve your
357 * activity when its component name is not explicitly specified.</p>
358 * <li><pre>
359 * &lt;intent-filter&gt;
360 *     &lt;action android:name="{@link #ACTION_GET_CONTENT android.intent.action.GET_CONTENT}" /&gt;
361 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
362 *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
363 * &lt;/intent-filter&gt;</pre>
364 * <p>This filter describes the ability return to the caller a note selected by
365 * the user without needing to know where it came from.  The data type
366 * <code>vnd.android.cursor.item/vnd.google.note</code> is a URI from which
367 * a Cursor of exactly one (<code>vnd.android.cursor.item</code>) item can
368 * be retrieved which contains our note pad data (<code>vnd.google.note</code>).
369 * The GET_CONTENT action is similar to the PICK action, where the activity
370 * will return to its caller a piece of data selected by the user.  Here,
371 * however, the caller specifies the type of data they desire instead of
372 * the type of data the user will be picking from.</p>
373 * </ol>
374 *
375 * <p>Given these capabilities, the following intents will resolve to the
376 * NotesList activity:</p>
377 *
378 * <ul>
379 *     <li> <p><b>{ action=android.app.action.MAIN }</b> matches all of the
380 *         activities that can be used as top-level entry points into an
381 *         application.</p>
382 *     <li> <p><b>{ action=android.app.action.MAIN,
383 *         category=android.app.category.LAUNCHER }</b> is the actual intent
384 *         used by the Launcher to populate its top-level list.</p>
385 *     <li> <p><b>{ action=android.intent.action.VIEW
386 *          data=content://com.google.provider.NotePad/notes }</b>
387 *         displays a list of all the notes under
388 *         "content://com.google.provider.NotePad/notes", which
389 *         the user can browse through and see the details on.</p>
390 *     <li> <p><b>{ action=android.app.action.PICK
391 *          data=content://com.google.provider.NotePad/notes }</b>
392 *         provides a list of the notes under
393 *         "content://com.google.provider.NotePad/notes", from which
394 *         the user can pick a note whose data URL is returned back to the caller.</p>
395 *     <li> <p><b>{ action=android.app.action.GET_CONTENT
396 *          type=vnd.android.cursor.item/vnd.google.note }</b>
397 *         is similar to the pick action, but allows the caller to specify the
398 *         kind of data they want back so that the system can find the appropriate
399 *         activity to pick something of that data type.</p>
400 * </ul>
401 *
402 * <p>The second activity,
403 * <code>com.android.notepad.NoteEditor</code>, shows the user a single
404 * note entry and allows them to edit it.  It can do two things as described
405 * by its two intent templates:
406 * <ol>
407 * <li><pre>
408 * &lt;intent-filter android:label="@string/resolve_edit"&gt;
409 *     &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
410 *     &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
411 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
412 *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
413 * &lt;/intent-filter&gt;</pre>
414 * <p>The first, primary, purpose of this activity is to let the user interact
415 * with a single note, as decribed by the MIME type
416 * <code>vnd.android.cursor.item/vnd.google.note</code>.  The activity can
417 * either VIEW a note or allow the user to EDIT it.  Again we support the
418 * DEFAULT category to allow the activity to be launched without explicitly
419 * specifying its component.</p>
420 * <li><pre>
421 * &lt;intent-filter&gt;
422 *     &lt;action android:name="{@link #ACTION_INSERT android.intent.action.INSERT}" /&gt;
423 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
424 *     &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
425 * &lt;/intent-filter&gt;</pre>
426 * <p>The secondary use of this activity is to insert a new note entry into
427 * an existing directory of notes.  This is used when the user creates a new
428 * note: the INSERT action is executed on the directory of notes, causing
429 * this activity to run and have the user create the new note data which
430 * it then adds to the content provider.</p>
431 * </ol>
432 *
433 * <p>Given these capabilities, the following intents will resolve to the
434 * NoteEditor activity:</p>
435 *
436 * <ul>
437 *     <li> <p><b>{ action=android.intent.action.VIEW
438 *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
439 *         shows the user the content of note <var>{ID}</var>.</p>
440 *     <li> <p><b>{ action=android.app.action.EDIT
441 *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
442 *         allows the user to edit the content of note <var>{ID}</var>.</p>
443 *     <li> <p><b>{ action=android.app.action.INSERT
444 *          data=content://com.google.provider.NotePad/notes }</b>
445 *         creates a new, empty note in the notes list at
446 *         "content://com.google.provider.NotePad/notes"
447 *         and allows the user to edit it.  If they keep their changes, the URI
448 *         of the newly created note is returned to the caller.</p>
449 * </ul>
450 *
451 * <p>The last activity,
452 * <code>com.android.notepad.TitleEditor</code>, allows the user to
453 * edit the title of a note.  This could be implemented as a class that the
454 * application directly invokes (by explicitly setting its component in
455 * the Intent), but here we show a way you can publish alternative
456 * operations on existing data:</p>
457 *
458 * <pre>
459 * &lt;intent-filter android:label="@string/resolve_title"&gt;
460 *     &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
461 *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
462 *     &lt;category android:name="{@link #CATEGORY_ALTERNATIVE android.intent.category.ALTERNATIVE}" /&gt;
463 *     &lt;category android:name="{@link #CATEGORY_SELECTED_ALTERNATIVE android.intent.category.SELECTED_ALTERNATIVE}" /&gt;
464 *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
465 * &lt;/intent-filter&gt;</pre>
466 *
467 * <p>In the single intent template here, we
468 * have created our own private action called
469 * <code>com.android.notepad.action.EDIT_TITLE</code> which means to
470 * edit the title of a note.  It must be invoked on a specific note
471 * (data type <code>vnd.android.cursor.item/vnd.google.note</code>) like the previous
472 * view and edit actions, but here displays and edits the title contained
473 * in the note data.
474 *
475 * <p>In addition to supporting the default category as usual, our title editor
476 * also supports two other standard categories: ALTERNATIVE and
477 * SELECTED_ALTERNATIVE.  Implementing
478 * these categories allows others to find the special action it provides
479 * without directly knowing about it, through the
480 * {@link android.content.pm.PackageManager#queryIntentActivityOptions} method, or
481 * more often to build dynamic menu items with
482 * {@link android.view.Menu#addIntentOptions}.  Note that in the intent
483 * template here was also supply an explicit name for the template
484 * (via <code>android:label="@string/resolve_title"</code>) to better control
485 * what the user sees when presented with this activity as an alternative
486 * action to the data they are viewing.
487 *
488 * <p>Given these capabilities, the following intent will resolve to the
489 * TitleEditor activity:</p>
490 *
491 * <ul>
492 *     <li> <p><b>{ action=com.android.notepad.action.EDIT_TITLE
493 *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
494 *         displays and allows the user to edit the title associated
495 *         with note <var>{ID}</var>.</p>
496 * </ul>
497 *
498 * <h3>Standard Activity Actions</h3>
499 *
500 * <p>These are the current standard actions that Intent defines for launching
501 * activities (usually through {@link Context#startActivity}.  The most
502 * important, and by far most frequently used, are {@link #ACTION_MAIN} and
503 * {@link #ACTION_EDIT}.
504 *
505 * <ul>
506 *     <li> {@link #ACTION_MAIN}
507 *     <li> {@link #ACTION_VIEW}
508 *     <li> {@link #ACTION_ATTACH_DATA}
509 *     <li> {@link #ACTION_EDIT}
510 *     <li> {@link #ACTION_PICK}
511 *     <li> {@link #ACTION_CHOOSER}
512 *     <li> {@link #ACTION_GET_CONTENT}
513 *     <li> {@link #ACTION_DIAL}
514 *     <li> {@link #ACTION_CALL}
515 *     <li> {@link #ACTION_SEND}
516 *     <li> {@link #ACTION_SENDTO}
517 *     <li> {@link #ACTION_ANSWER}
518 *     <li> {@link #ACTION_INSERT}
519 *     <li> {@link #ACTION_DELETE}
520 *     <li> {@link #ACTION_RUN}
521 *     <li> {@link #ACTION_SYNC}
522 *     <li> {@link #ACTION_PICK_ACTIVITY}
523 *     <li> {@link #ACTION_SEARCH}
524 *     <li> {@link #ACTION_WEB_SEARCH}
525 *     <li> {@link #ACTION_FACTORY_TEST}
526 * </ul>
527 *
528 * <h3>Standard Broadcast Actions</h3>
529 *
530 * <p>These are the current standard actions that Intent defines for receiving
531 * broadcasts (usually through {@link Context#registerReceiver} or a
532 * &lt;receiver&gt; tag in a manifest).
533 *
534 * <ul>
535 *     <li> {@link #ACTION_TIME_TICK}
536 *     <li> {@link #ACTION_TIME_CHANGED}
537 *     <li> {@link #ACTION_TIMEZONE_CHANGED}
538 *     <li> {@link #ACTION_BOOT_COMPLETED}
539 *     <li> {@link #ACTION_PACKAGE_ADDED}
540 *     <li> {@link #ACTION_PACKAGE_CHANGED}
541 *     <li> {@link #ACTION_PACKAGE_REMOVED}
542 *     <li> {@link #ACTION_PACKAGE_RESTARTED}
543 *     <li> {@link #ACTION_PACKAGE_DATA_CLEARED}
544 *     <li> {@link #ACTION_UID_REMOVED}
545 *     <li> {@link #ACTION_BATTERY_CHANGED}
546 *     <li> {@link #ACTION_POWER_CONNECTED}
547 *     <li> {@link #ACTION_POWER_DISCONNECTED}
548 *     <li> {@link #ACTION_SHUTDOWN}
549 * </ul>
550 *
551 * <h3>Standard Categories</h3>
552 *
553 * <p>These are the current standard categories that can be used to further
554 * clarify an Intent via {@link #addCategory}.
555 *
556 * <ul>
557 *     <li> {@link #CATEGORY_DEFAULT}
558 *     <li> {@link #CATEGORY_BROWSABLE}
559 *     <li> {@link #CATEGORY_TAB}
560 *     <li> {@link #CATEGORY_ALTERNATIVE}
561 *     <li> {@link #CATEGORY_SELECTED_ALTERNATIVE}
562 *     <li> {@link #CATEGORY_LAUNCHER}
563 *     <li> {@link #CATEGORY_INFO}
564 *     <li> {@link #CATEGORY_HOME}
565 *     <li> {@link #CATEGORY_PREFERENCE}
566 *     <li> {@link #CATEGORY_TEST}
567 *     <li> {@link #CATEGORY_CAR_DOCK}
568 *     <li> {@link #CATEGORY_DESK_DOCK}
569 *     <li> {@link #CATEGORY_LE_DESK_DOCK}
570 *     <li> {@link #CATEGORY_HE_DESK_DOCK}
571 *     <li> {@link #CATEGORY_CAR_MODE}
572 *     <li> {@link #CATEGORY_APP_MARKET}
573 * </ul>
574 *
575 * <h3>Standard Extra Data</h3>
576 *
577 * <p>These are the current standard fields that can be used as extra data via
578 * {@link #putExtra}.
579 *
580 * <ul>
581 *     <li> {@link #EXTRA_ALARM_COUNT}
582 *     <li> {@link #EXTRA_BCC}
583 *     <li> {@link #EXTRA_CC}
584 *     <li> {@link #EXTRA_CHANGED_COMPONENT_NAME}
585 *     <li> {@link #EXTRA_DATA_REMOVED}
586 *     <li> {@link #EXTRA_DOCK_STATE}
587 *     <li> {@link #EXTRA_DOCK_STATE_HE_DESK}
588 *     <li> {@link #EXTRA_DOCK_STATE_LE_DESK}
589 *     <li> {@link #EXTRA_DOCK_STATE_CAR}
590 *     <li> {@link #EXTRA_DOCK_STATE_DESK}
591 *     <li> {@link #EXTRA_DOCK_STATE_UNDOCKED}
592 *     <li> {@link #EXTRA_DONT_KILL_APP}
593 *     <li> {@link #EXTRA_EMAIL}
594 *     <li> {@link #EXTRA_INITIAL_INTENTS}
595 *     <li> {@link #EXTRA_INTENT}
596 *     <li> {@link #EXTRA_KEY_EVENT}
597 *     <li> {@link #EXTRA_ORIGINATING_URI}
598 *     <li> {@link #EXTRA_PHONE_NUMBER}
599 *     <li> {@link #EXTRA_REFERRER}
600 *     <li> {@link #EXTRA_REMOTE_INTENT_TOKEN}
601 *     <li> {@link #EXTRA_REPLACING}
602 *     <li> {@link #EXTRA_SHORTCUT_ICON}
603 *     <li> {@link #EXTRA_SHORTCUT_ICON_RESOURCE}
604 *     <li> {@link #EXTRA_SHORTCUT_INTENT}
605 *     <li> {@link #EXTRA_STREAM}
606 *     <li> {@link #EXTRA_SHORTCUT_NAME}
607 *     <li> {@link #EXTRA_SUBJECT}
608 *     <li> {@link #EXTRA_TEMPLATE}
609 *     <li> {@link #EXTRA_TEXT}
610 *     <li> {@link #EXTRA_TITLE}
611 *     <li> {@link #EXTRA_UID}
612 * </ul>
613 *
614 * <h3>Flags</h3>
615 *
616 * <p>These are the possible flags that can be used in the Intent via
617 * {@link #setFlags} and {@link #addFlags}.  See {@link #setFlags} for a list
618 * of all possible flags.
619 */
620public class Intent implements Parcelable, Cloneable {
621    private static final String ATTR_ACTION = "action";
622    private static final String TAG_CATEGORIES = "categories";
623    private static final String ATTR_CATEGORY = "category";
624    private static final String TAG_EXTRA = "extra";
625    private static final String ATTR_TYPE = "type";
626    private static final String ATTR_COMPONENT = "component";
627    private static final String ATTR_DATA = "data";
628    private static final String ATTR_FLAGS = "flags";
629
630    // ---------------------------------------------------------------------
631    // ---------------------------------------------------------------------
632    // Standard intent activity actions (see action variable).
633
634    /**
635     *  Activity Action: Start as a main entry point, does not expect to
636     *  receive data.
637     *  <p>Input: nothing
638     *  <p>Output: nothing
639     */
640    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
641    public static final String ACTION_MAIN = "android.intent.action.MAIN";
642
643    /**
644     * Activity Action: Display the data to the user.  This is the most common
645     * action performed on data -- it is the generic action you can use on
646     * a piece of data to get the most reasonable thing to occur.  For example,
647     * when used on a contacts entry it will view the entry; when used on a
648     * mailto: URI it will bring up a compose window filled with the information
649     * supplied by the URI; when used with a tel: URI it will invoke the
650     * dialer.
651     * <p>Input: {@link #getData} is URI from which to retrieve data.
652     * <p>Output: nothing.
653     */
654    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
655    public static final String ACTION_VIEW = "android.intent.action.VIEW";
656
657    /**
658     * A synonym for {@link #ACTION_VIEW}, the "standard" action that is
659     * performed on a piece of data.
660     */
661    public static final String ACTION_DEFAULT = ACTION_VIEW;
662
663    /**
664     * Activity Action: Quick view the data.
665     * <p>Input: {@link #getData} is URI from which to retrieve data.
666     * <p>Output: nothing.
667     * @hide
668     */
669    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
670    public static final String ACTION_QUICK_VIEW = "android.intent.action.QUICK_VIEW";
671
672    /**
673     * Used to indicate that some piece of data should be attached to some other
674     * place.  For example, image data could be attached to a contact.  It is up
675     * to the recipient to decide where the data should be attached; the intent
676     * does not specify the ultimate destination.
677     * <p>Input: {@link #getData} is URI of data to be attached.
678     * <p>Output: nothing.
679     */
680    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
681    public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
682
683    /**
684     * Activity Action: Provide explicit editable access to the given data.
685     * <p>Input: {@link #getData} is URI of data to be edited.
686     * <p>Output: nothing.
687     */
688    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
689    public static final String ACTION_EDIT = "android.intent.action.EDIT";
690
691    /**
692     * Activity Action: Pick an existing item, or insert a new item, and then edit it.
693     * <p>Input: {@link #getType} is the desired MIME type of the item to create or edit.
694     * The extras can contain type specific data to pass through to the editing/creating
695     * activity.
696     * <p>Output: The URI of the item that was picked.  This must be a content:
697     * URI so that any receiver can access it.
698     */
699    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
700    public static final String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
701
702    /**
703     * Activity Action: Pick an item from the data, returning what was selected.
704     * <p>Input: {@link #getData} is URI containing a directory of data
705     * (vnd.android.cursor.dir/*) from which to pick an item.
706     * <p>Output: The URI of the item that was picked.
707     */
708    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
709    public static final String ACTION_PICK = "android.intent.action.PICK";
710
711    /**
712     * Activity Action: Creates a shortcut.
713     * <p>Input: Nothing.</p>
714     * <p>Output: An Intent representing the shortcut. The intent must contain three
715     * extras: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String),
716     * and SHORTCUT_ICON (value: Bitmap) or SHORTCUT_ICON_RESOURCE
717     * (value: ShortcutIconResource).</p>
718     *
719     * @see #EXTRA_SHORTCUT_INTENT
720     * @see #EXTRA_SHORTCUT_NAME
721     * @see #EXTRA_SHORTCUT_ICON
722     * @see #EXTRA_SHORTCUT_ICON_RESOURCE
723     * @see android.content.Intent.ShortcutIconResource
724     */
725    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
726    public static final String ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
727
728    /**
729     * The name of the extra used to define the Intent of a shortcut.
730     *
731     * @see #ACTION_CREATE_SHORTCUT
732     */
733    public static final String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
734    /**
735     * The name of the extra used to define the name of a shortcut.
736     *
737     * @see #ACTION_CREATE_SHORTCUT
738     */
739    public static final String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
740    /**
741     * The name of the extra used to define the icon, as a Bitmap, of a shortcut.
742     *
743     * @see #ACTION_CREATE_SHORTCUT
744     */
745    public static final String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
746    /**
747     * The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.
748     *
749     * @see #ACTION_CREATE_SHORTCUT
750     * @see android.content.Intent.ShortcutIconResource
751     */
752    public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
753            "android.intent.extra.shortcut.ICON_RESOURCE";
754
755    /**
756     * Represents a shortcut/live folder icon resource.
757     *
758     * @see Intent#ACTION_CREATE_SHORTCUT
759     * @see Intent#EXTRA_SHORTCUT_ICON_RESOURCE
760     * @see android.provider.LiveFolders#ACTION_CREATE_LIVE_FOLDER
761     * @see android.provider.LiveFolders#EXTRA_LIVE_FOLDER_ICON
762     */
763    public static class ShortcutIconResource implements Parcelable {
764        /**
765         * The package name of the application containing the icon.
766         */
767        public String packageName;
768
769        /**
770         * The resource name of the icon, including package, name and type.
771         */
772        public String resourceName;
773
774        /**
775         * Creates a new ShortcutIconResource for the specified context and resource
776         * identifier.
777         *
778         * @param context The context of the application.
779         * @param resourceId The resource identifier for the icon.
780         * @return A new ShortcutIconResource with the specified's context package name
781         *         and icon resource identifier.``
782         */
783        public static ShortcutIconResource fromContext(Context context, @AnyRes int resourceId) {
784            ShortcutIconResource icon = new ShortcutIconResource();
785            icon.packageName = context.getPackageName();
786            icon.resourceName = context.getResources().getResourceName(resourceId);
787            return icon;
788        }
789
790        /**
791         * Used to read a ShortcutIconResource from a Parcel.
792         */
793        public static final Parcelable.Creator<ShortcutIconResource> CREATOR =
794            new Parcelable.Creator<ShortcutIconResource>() {
795
796                public ShortcutIconResource createFromParcel(Parcel source) {
797                    ShortcutIconResource icon = new ShortcutIconResource();
798                    icon.packageName = source.readString();
799                    icon.resourceName = source.readString();
800                    return icon;
801                }
802
803                public ShortcutIconResource[] newArray(int size) {
804                    return new ShortcutIconResource[size];
805                }
806            };
807
808        /**
809         * No special parcel contents.
810         */
811        public int describeContents() {
812            return 0;
813        }
814
815        public void writeToParcel(Parcel dest, int flags) {
816            dest.writeString(packageName);
817            dest.writeString(resourceName);
818        }
819
820        @Override
821        public String toString() {
822            return resourceName;
823        }
824    }
825
826    /**
827     * Activity Action: Display an activity chooser, allowing the user to pick
828     * what they want to before proceeding.  This can be used as an alternative
829     * to the standard activity picker that is displayed by the system when
830     * you try to start an activity with multiple possible matches, with these
831     * differences in behavior:
832     * <ul>
833     * <li>You can specify the title that will appear in the activity chooser.
834     * <li>The user does not have the option to make one of the matching
835     * activities a preferred activity, and all possible activities will
836     * always be shown even if one of them is currently marked as the
837     * preferred activity.
838     * </ul>
839     * <p>
840     * This action should be used when the user will naturally expect to
841     * select an activity in order to proceed.  An example if when not to use
842     * it is when the user clicks on a "mailto:" link.  They would naturally
843     * expect to go directly to their mail app, so startActivity() should be
844     * called directly: it will
845     * either launch the current preferred app, or put up a dialog allowing the
846     * user to pick an app to use and optionally marking that as preferred.
847     * <p>
848     * In contrast, if the user is selecting a menu item to send a picture
849     * they are viewing to someone else, there are many different things they
850     * may want to do at this point: send it through e-mail, upload it to a
851     * web service, etc.  In this case the CHOOSER action should be used, to
852     * always present to the user a list of the things they can do, with a
853     * nice title given by the caller such as "Send this photo with:".
854     * <p>
855     * If you need to grant URI permissions through a chooser, you must specify
856     * the permissions to be granted on the ACTION_CHOOSER Intent
857     * <em>in addition</em> to the EXTRA_INTENT inside.  This means using
858     * {@link #setClipData} to specify the URIs to be granted as well as
859     * {@link #FLAG_GRANT_READ_URI_PERMISSION} and/or
860     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION} as appropriate.
861     * <p>
862     * As a convenience, an Intent of this form can be created with the
863     * {@link #createChooser} function.
864     * <p>
865     * Input: No data should be specified.  get*Extra must have
866     * a {@link #EXTRA_INTENT} field containing the Intent being executed,
867     * and can optionally have a {@link #EXTRA_TITLE} field containing the
868     * title text to display in the chooser.
869     * <p>
870     * Output: Depends on the protocol of {@link #EXTRA_INTENT}.
871     */
872    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
873    public static final String ACTION_CHOOSER = "android.intent.action.CHOOSER";
874
875    /**
876     * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
877     *
878     * <p>Builds a new {@link #ACTION_CHOOSER} Intent that wraps the given
879     * target intent, also optionally supplying a title.  If the target
880     * intent has specified {@link #FLAG_GRANT_READ_URI_PERMISSION} or
881     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION}, then these flags will also be
882     * set in the returned chooser intent, with its ClipData set appropriately:
883     * either a direct reflection of {@link #getClipData()} if that is non-null,
884     * or a new ClipData built from {@link #getData()}.
885     *
886     * @param target The Intent that the user will be selecting an activity
887     * to perform.
888     * @param title Optional title that will be displayed in the chooser.
889     * @return Return a new Intent object that you can hand to
890     * {@link Context#startActivity(Intent) Context.startActivity()} and
891     * related methods.
892     */
893    public static Intent createChooser(Intent target, CharSequence title) {
894        return createChooser(target, title, null);
895    }
896
897    /**
898     * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
899     *
900     * <p>Builds a new {@link #ACTION_CHOOSER} Intent that wraps the given
901     * target intent, also optionally supplying a title.  If the target
902     * intent has specified {@link #FLAG_GRANT_READ_URI_PERMISSION} or
903     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION}, then these flags will also be
904     * set in the returned chooser intent, with its ClipData set appropriately:
905     * either a direct reflection of {@link #getClipData()} if that is non-null,
906     * or a new ClipData built from {@link #getData()}.</p>
907     *
908     * <p>The caller may optionally supply an {@link IntentSender} to receive a callback
909     * when the user makes a choice. This can be useful if the calling application wants
910     * to remember the last chosen target and surface it as a more prominent or one-touch
911     * affordance elsewhere in the UI for next time.</p>
912     *
913     * @param target The Intent that the user will be selecting an activity
914     * to perform.
915     * @param title Optional title that will be displayed in the chooser.
916     * @param sender Optional IntentSender to be called when a choice is made.
917     * @return Return a new Intent object that you can hand to
918     * {@link Context#startActivity(Intent) Context.startActivity()} and
919     * related methods.
920     */
921    public static Intent createChooser(Intent target, CharSequence title, IntentSender sender) {
922        Intent intent = new Intent(ACTION_CHOOSER);
923        intent.putExtra(EXTRA_INTENT, target);
924        if (title != null) {
925            intent.putExtra(EXTRA_TITLE, title);
926        }
927
928        if (sender != null) {
929            intent.putExtra(EXTRA_CHOSEN_COMPONENT_INTENT_SENDER, sender);
930        }
931
932        // Migrate any clip data and flags from target.
933        int permFlags = target.getFlags() & (FLAG_GRANT_READ_URI_PERMISSION
934                | FLAG_GRANT_WRITE_URI_PERMISSION | FLAG_GRANT_PERSISTABLE_URI_PERMISSION
935                | FLAG_GRANT_PREFIX_URI_PERMISSION);
936        if (permFlags != 0) {
937            ClipData targetClipData = target.getClipData();
938            if (targetClipData == null && target.getData() != null) {
939                ClipData.Item item = new ClipData.Item(target.getData());
940                String[] mimeTypes;
941                if (target.getType() != null) {
942                    mimeTypes = new String[] { target.getType() };
943                } else {
944                    mimeTypes = new String[] { };
945                }
946                targetClipData = new ClipData(null, mimeTypes, item);
947            }
948            if (targetClipData != null) {
949                intent.setClipData(targetClipData);
950                intent.addFlags(permFlags);
951            }
952        }
953
954        return intent;
955    }
956
957    /**
958     * Activity Action: Allow the user to select a particular kind of data and
959     * return it.  This is different than {@link #ACTION_PICK} in that here we
960     * just say what kind of data is desired, not a URI of existing data from
961     * which the user can pick.  An ACTION_GET_CONTENT could allow the user to
962     * create the data as it runs (for example taking a picture or recording a
963     * sound), let them browse over the web and download the desired data,
964     * etc.
965     * <p>
966     * There are two main ways to use this action: if you want a specific kind
967     * of data, such as a person contact, you set the MIME type to the kind of
968     * data you want and launch it with {@link Context#startActivity(Intent)}.
969     * The system will then launch the best application to select that kind
970     * of data for you.
971     * <p>
972     * You may also be interested in any of a set of types of content the user
973     * can pick.  For example, an e-mail application that wants to allow the
974     * user to add an attachment to an e-mail message can use this action to
975     * bring up a list of all of the types of content the user can attach.
976     * <p>
977     * In this case, you should wrap the GET_CONTENT intent with a chooser
978     * (through {@link #createChooser}), which will give the proper interface
979     * for the user to pick how to send your data and allow you to specify
980     * a prompt indicating what they are doing.  You will usually specify a
981     * broad MIME type (such as image/* or {@literal *}/*), resulting in a
982     * broad range of content types the user can select from.
983     * <p>
984     * When using such a broad GET_CONTENT action, it is often desirable to
985     * only pick from data that can be represented as a stream.  This is
986     * accomplished by requiring the {@link #CATEGORY_OPENABLE} in the Intent.
987     * <p>
988     * Callers can optionally specify {@link #EXTRA_LOCAL_ONLY} to request that
989     * the launched content chooser only returns results representing data that
990     * is locally available on the device.  For example, if this extra is set
991     * to true then an image picker should not show any pictures that are available
992     * from a remote server but not already on the local device (thus requiring
993     * they be downloaded when opened).
994     * <p>
995     * If the caller can handle multiple returned items (the user performing
996     * multiple selection), then it can specify {@link #EXTRA_ALLOW_MULTIPLE}
997     * to indicate this.
998     * <p>
999     * Input: {@link #getType} is the desired MIME type to retrieve.  Note
1000     * that no URI is supplied in the intent, as there are no constraints on
1001     * where the returned data originally comes from.  You may also include the
1002     * {@link #CATEGORY_OPENABLE} if you can only accept data that can be
1003     * opened as a stream.  You may use {@link #EXTRA_LOCAL_ONLY} to limit content
1004     * selection to local data.  You may use {@link #EXTRA_ALLOW_MULTIPLE} to
1005     * allow the user to select multiple items.
1006     * <p>
1007     * Output: The URI of the item that was picked.  This must be a content:
1008     * URI so that any receiver can access it.
1009     */
1010    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1011    public static final String ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
1012    /**
1013     * Activity Action: Dial a number as specified by the data.  This shows a
1014     * UI with the number being dialed, allowing the user to explicitly
1015     * initiate the call.
1016     * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
1017     * is URI of a phone number to be dialed or a tel: URI of an explicit phone
1018     * number.
1019     * <p>Output: nothing.
1020     */
1021    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1022    public static final String ACTION_DIAL = "android.intent.action.DIAL";
1023    /**
1024     * Activity Action: Perform a call to someone specified by the data.
1025     * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
1026     * is URI of a phone number to be dialed or a tel: URI of an explicit phone
1027     * number.
1028     * <p>Output: nothing.
1029     *
1030     * <p>Note: there will be restrictions on which applications can initiate a
1031     * call; most applications should use the {@link #ACTION_DIAL}.
1032     * <p>Note: this Intent <strong>cannot</strong> be used to call emergency
1033     * numbers.  Applications can <strong>dial</strong> emergency numbers using
1034     * {@link #ACTION_DIAL}, however.
1035     *
1036     * <p>Note: if you app targets {@link android.os.Build.VERSION_CODES#M M}
1037     * and above and declares as using the {@link android.Manifest.permission#CALL_PHONE}
1038     * permission which is not granted, then attempting to use this action will
1039     * result in a {@link java.lang.SecurityException}.
1040     */
1041    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1042    public static final String ACTION_CALL = "android.intent.action.CALL";
1043    /**
1044     * Activity Action: Perform a call to an emergency number specified by the
1045     * data.
1046     * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
1047     * tel: URI of an explicit phone number.
1048     * <p>Output: nothing.
1049     * @hide
1050     */
1051    public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
1052    /**
1053     * Activity action: Perform a call to any number (emergency or not)
1054     * specified by the data.
1055     * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
1056     * tel: URI of an explicit phone number.
1057     * <p>Output: nothing.
1058     * @hide
1059     */
1060    public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
1061    /**
1062     * Activity action: Activate the current SIM card.  If SIM cards do not require activation,
1063     * sending this intent is a no-op.
1064     * <p>Input: No data should be specified.  get*Extra may have an optional
1065     * {@link #EXTRA_SIM_ACTIVATION_RESPONSE} field containing a PendingIntent through which to
1066     * send the activation result.
1067     * <p>Output: nothing.
1068     * @hide
1069     */
1070    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1071    public static final String ACTION_SIM_ACTIVATION_REQUEST =
1072            "android.intent.action.SIM_ACTIVATION_REQUEST";
1073    /**
1074     * Activity Action: Send a message to someone specified by the data.
1075     * <p>Input: {@link #getData} is URI describing the target.
1076     * <p>Output: nothing.
1077     */
1078    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1079    public static final String ACTION_SENDTO = "android.intent.action.SENDTO";
1080    /**
1081     * Activity Action: Deliver some data to someone else.  Who the data is
1082     * being delivered to is not specified; it is up to the receiver of this
1083     * action to ask the user where the data should be sent.
1084     * <p>
1085     * When launching a SEND intent, you should usually wrap it in a chooser
1086     * (through {@link #createChooser}), which will give the proper interface
1087     * for the user to pick how to send your data and allow you to specify
1088     * a prompt indicating what they are doing.
1089     * <p>
1090     * Input: {@link #getType} is the MIME type of the data being sent.
1091     * get*Extra can have either a {@link #EXTRA_TEXT}
1092     * or {@link #EXTRA_STREAM} field, containing the data to be sent.  If
1093     * using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it
1094     * should be the MIME type of the data in EXTRA_STREAM.  Use {@literal *}/*
1095     * if the MIME type is unknown (this will only allow senders that can
1096     * handle generic data streams).  If using {@link #EXTRA_TEXT}, you can
1097     * also optionally supply {@link #EXTRA_HTML_TEXT} for clients to retrieve
1098     * your text with HTML formatting.
1099     * <p>
1100     * As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, the data
1101     * being sent can be supplied through {@link #setClipData(ClipData)}.  This
1102     * allows you to use {@link #FLAG_GRANT_READ_URI_PERMISSION} when sharing
1103     * content: URIs and other advanced features of {@link ClipData}.  If
1104     * using this approach, you still must supply the same data through the
1105     * {@link #EXTRA_TEXT} or {@link #EXTRA_STREAM} fields described below
1106     * for compatibility with old applications.  If you don't set a ClipData,
1107     * it will be copied there for you when calling {@link Context#startActivity(Intent)}.
1108     * <p>
1109     * Optional standard extras, which may be interpreted by some recipients as
1110     * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
1111     * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
1112     * <p>
1113     * Output: nothing.
1114     */
1115    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1116    public static final String ACTION_SEND = "android.intent.action.SEND";
1117    /**
1118     * Activity Action: Deliver multiple data to someone else.
1119     * <p>
1120     * Like {@link #ACTION_SEND}, except the data is multiple.
1121     * <p>
1122     * Input: {@link #getType} is the MIME type of the data being sent.
1123     * get*ArrayListExtra can have either a {@link #EXTRA_TEXT} or {@link
1124     * #EXTRA_STREAM} field, containing the data to be sent.  If using
1125     * {@link #EXTRA_TEXT}, you can also optionally supply {@link #EXTRA_HTML_TEXT}
1126     * for clients to retrieve your text with HTML formatting.
1127     * <p>
1128     * Multiple types are supported, and receivers should handle mixed types
1129     * whenever possible. The right way for the receiver to check them is to
1130     * use the content resolver on each URI. The intent sender should try to
1131     * put the most concrete mime type in the intent type, but it can fall
1132     * back to {@literal <type>/*} or {@literal *}/* as needed.
1133     * <p>
1134     * e.g. if you are sending image/jpg and image/jpg, the intent's type can
1135     * be image/jpg, but if you are sending image/jpg and image/png, then the
1136     * intent's type should be image/*.
1137     * <p>
1138     * As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, the data
1139     * being sent can be supplied through {@link #setClipData(ClipData)}.  This
1140     * allows you to use {@link #FLAG_GRANT_READ_URI_PERMISSION} when sharing
1141     * content: URIs and other advanced features of {@link ClipData}.  If
1142     * using this approach, you still must supply the same data through the
1143     * {@link #EXTRA_TEXT} or {@link #EXTRA_STREAM} fields described below
1144     * for compatibility with old applications.  If you don't set a ClipData,
1145     * it will be copied there for you when calling {@link Context#startActivity(Intent)}.
1146     * <p>
1147     * Optional standard extras, which may be interpreted by some recipients as
1148     * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
1149     * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
1150     * <p>
1151     * Output: nothing.
1152     */
1153    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1154    public static final String ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE";
1155    /**
1156     * Activity Action: Handle an incoming phone call.
1157     * <p>Input: nothing.
1158     * <p>Output: nothing.
1159     */
1160    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1161    public static final String ACTION_ANSWER = "android.intent.action.ANSWER";
1162    /**
1163     * Activity Action: Insert an empty item into the given container.
1164     * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
1165     * in which to place the data.
1166     * <p>Output: URI of the new data that was created.
1167     */
1168    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1169    public static final String ACTION_INSERT = "android.intent.action.INSERT";
1170    /**
1171     * Activity Action: Create a new item in the given container, initializing it
1172     * from the current contents of the clipboard.
1173     * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
1174     * in which to place the data.
1175     * <p>Output: URI of the new data that was created.
1176     */
1177    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1178    public static final String ACTION_PASTE = "android.intent.action.PASTE";
1179    /**
1180     * Activity Action: Delete the given data from its container.
1181     * <p>Input: {@link #getData} is URI of data to be deleted.
1182     * <p>Output: nothing.
1183     */
1184    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1185    public static final String ACTION_DELETE = "android.intent.action.DELETE";
1186    /**
1187     * Activity Action: Run the data, whatever that means.
1188     * <p>Input: ?  (Note: this is currently specific to the test harness.)
1189     * <p>Output: nothing.
1190     */
1191    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1192    public static final String ACTION_RUN = "android.intent.action.RUN";
1193    /**
1194     * Activity Action: Perform a data synchronization.
1195     * <p>Input: ?
1196     * <p>Output: ?
1197     */
1198    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1199    public static final String ACTION_SYNC = "android.intent.action.SYNC";
1200    /**
1201     * Activity Action: Pick an activity given an intent, returning the class
1202     * selected.
1203     * <p>Input: get*Extra field {@link #EXTRA_INTENT} is an Intent
1204     * used with {@link PackageManager#queryIntentActivities} to determine the
1205     * set of activities from which to pick.
1206     * <p>Output: Class name of the activity that was selected.
1207     */
1208    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1209    public static final String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
1210    /**
1211     * Activity Action: Perform a search.
1212     * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
1213     * is the text to search for.  If empty, simply
1214     * enter your search results Activity with the search UI activated.
1215     * <p>Output: nothing.
1216     */
1217    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1218    public static final String ACTION_SEARCH = "android.intent.action.SEARCH";
1219    /**
1220     * Activity Action: Start the platform-defined tutorial
1221     * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
1222     * is the text to search for.  If empty, simply
1223     * enter your search results Activity with the search UI activated.
1224     * <p>Output: nothing.
1225     */
1226    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1227    public static final String ACTION_SYSTEM_TUTORIAL = "android.intent.action.SYSTEM_TUTORIAL";
1228    /**
1229     * Activity Action: Perform a web search.
1230     * <p>
1231     * Input: {@link android.app.SearchManager#QUERY
1232     * getStringExtra(SearchManager.QUERY)} is the text to search for. If it is
1233     * a url starts with http or https, the site will be opened. If it is plain
1234     * text, Google search will be applied.
1235     * <p>
1236     * Output: nothing.
1237     */
1238    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1239    public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
1240
1241    /**
1242     * Activity Action: Perform assist action.
1243     * <p>
1244     * Input: {@link #EXTRA_ASSIST_PACKAGE}, {@link #EXTRA_ASSIST_CONTEXT}, can provide
1245     * additional optional contextual information about where the user was when they
1246     * requested the assist; {@link #EXTRA_REFERRER} may be set with additional referrer
1247     * information.
1248     * Output: nothing.
1249     */
1250    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1251    public static final String ACTION_ASSIST = "android.intent.action.ASSIST";
1252
1253    /**
1254     * Activity Action: Perform voice assist action.
1255     * <p>
1256     * Input: {@link #EXTRA_ASSIST_PACKAGE}, {@link #EXTRA_ASSIST_CONTEXT}, can provide
1257     * additional optional contextual information about where the user was when they
1258     * requested the voice assist.
1259     * Output: nothing.
1260     * @hide
1261     */
1262    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1263    public static final String ACTION_VOICE_ASSIST = "android.intent.action.VOICE_ASSIST";
1264
1265    /**
1266     * An optional field on {@link #ACTION_ASSIST} containing the name of the current foreground
1267     * application package at the time the assist was invoked.
1268     */
1269    public static final String EXTRA_ASSIST_PACKAGE
1270            = "android.intent.extra.ASSIST_PACKAGE";
1271
1272    /**
1273     * An optional field on {@link #ACTION_ASSIST} containing the uid of the current foreground
1274     * application package at the time the assist was invoked.
1275     */
1276    public static final String EXTRA_ASSIST_UID
1277            = "android.intent.extra.ASSIST_UID";
1278
1279    /**
1280     * An optional field on {@link #ACTION_ASSIST} and containing additional contextual
1281     * information supplied by the current foreground app at the time of the assist request.
1282     * This is a {@link Bundle} of additional data.
1283     */
1284    public static final String EXTRA_ASSIST_CONTEXT
1285            = "android.intent.extra.ASSIST_CONTEXT";
1286
1287    /**
1288     * An optional field on {@link #ACTION_ASSIST} suggesting that the user will likely use a
1289     * keyboard as the primary input device for assistance.
1290     */
1291    public static final String EXTRA_ASSIST_INPUT_HINT_KEYBOARD =
1292            "android.intent.extra.ASSIST_INPUT_HINT_KEYBOARD";
1293
1294    /**
1295     * An optional field on {@link #ACTION_ASSIST} containing the InputDevice id
1296     * that was used to invoke the assist.
1297     */
1298    public static final String EXTRA_ASSIST_INPUT_DEVICE_ID =
1299            "android.intent.extra.ASSIST_INPUT_DEVICE_ID";
1300
1301    /**
1302     * Activity Action: List all available applications
1303     * <p>Input: Nothing.
1304     * <p>Output: nothing.
1305     */
1306    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1307    public static final String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
1308    /**
1309     * Activity Action: Show settings for choosing wallpaper
1310     * <p>Input: Nothing.
1311     * <p>Output: Nothing.
1312     */
1313    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1314    public static final String ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
1315
1316    /**
1317     * Activity Action: Show activity for reporting a bug.
1318     * <p>Input: Nothing.
1319     * <p>Output: Nothing.
1320     */
1321    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1322    public static final String ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
1323
1324    /**
1325     *  Activity Action: Main entry point for factory tests.  Only used when
1326     *  the device is booting in factory test node.  The implementing package
1327     *  must be installed in the system image.
1328     *  <p>Input: nothing
1329     *  <p>Output: nothing
1330     */
1331    public static final String ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
1332
1333    /**
1334     * Activity Action: The user pressed the "call" button to go to the dialer
1335     * or other appropriate UI for placing a call.
1336     * <p>Input: Nothing.
1337     * <p>Output: Nothing.
1338     */
1339    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1340    public static final String ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
1341
1342    /**
1343     * Activity Action: Start Voice Command.
1344     * <p>Input: Nothing.
1345     * <p>Output: Nothing.
1346     */
1347    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1348    public static final String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
1349
1350    /**
1351     * Activity Action: Start action associated with long pressing on the
1352     * search key.
1353     * <p>Input: Nothing.
1354     * <p>Output: Nothing.
1355     */
1356    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1357    public static final String ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";
1358
1359    /**
1360     * Activity Action: The user pressed the "Report" button in the crash/ANR dialog.
1361     * This intent is delivered to the package which installed the application, usually
1362     * Google Play.
1363     * <p>Input: No data is specified. The bug report is passed in using
1364     * an {@link #EXTRA_BUG_REPORT} field.
1365     * <p>Output: Nothing.
1366     *
1367     * @see #EXTRA_BUG_REPORT
1368     */
1369    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1370    public static final String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
1371
1372    /**
1373     * Activity Action: Show power usage information to the user.
1374     * <p>Input: Nothing.
1375     * <p>Output: Nothing.
1376     */
1377    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1378    public static final String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
1379
1380    /**
1381     * Activity Action: Setup wizard to launch after a platform update.  This
1382     * activity should have a string meta-data field associated with it,
1383     * {@link #METADATA_SETUP_VERSION}, which defines the current version of
1384     * the platform for setup.  The activity will be launched only if
1385     * {@link android.provider.Settings.Secure#LAST_SETUP_SHOWN} is not the
1386     * same value.
1387     * <p>Input: Nothing.
1388     * <p>Output: Nothing.
1389     * @hide
1390     */
1391    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1392    public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
1393
1394    /**
1395     * Activity Action: Show settings for managing network data usage of a
1396     * specific application. Applications should define an activity that offers
1397     * options to control data usage.
1398     */
1399    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1400    public static final String ACTION_MANAGE_NETWORK_USAGE =
1401            "android.intent.action.MANAGE_NETWORK_USAGE";
1402
1403    /**
1404     * Activity Action: Launch application installer.
1405     * <p>
1406     * Input: The data must be a content: or file: URI at which the application
1407     * can be retrieved.  As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1},
1408     * you can also use "package:<package-name>" to install an application for the
1409     * current user that is already installed for another user. You can optionally supply
1410     * {@link #EXTRA_INSTALLER_PACKAGE_NAME}, {@link #EXTRA_NOT_UNKNOWN_SOURCE},
1411     * {@link #EXTRA_ALLOW_REPLACE}, and {@link #EXTRA_RETURN_RESULT}.
1412     * <p>
1413     * Output: If {@link #EXTRA_RETURN_RESULT}, returns whether the install
1414     * succeeded.
1415     * <p>
1416     * <strong>Note:</strong>If your app is targeting API level higher than 22 you
1417     * need to hold {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES}
1418     * in order to launch the application installer.
1419     * </p>
1420     *
1421     * @see #EXTRA_INSTALLER_PACKAGE_NAME
1422     * @see #EXTRA_NOT_UNKNOWN_SOURCE
1423     * @see #EXTRA_RETURN_RESULT
1424     */
1425    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1426    public static final String ACTION_INSTALL_PACKAGE = "android.intent.action.INSTALL_PACKAGE";
1427
1428    /**
1429     * Activity Action: Launch ephemeral installer.
1430     * <p>
1431     * Input: The data must be a http: URI that the ephemeral application is registered
1432     * to handle.
1433     * <p class="note">
1434     * This is a protected intent that can only be sent by the system.
1435     * </p>
1436     *
1437     * @hide
1438     */
1439    @SystemApi
1440    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1441    public static final String ACTION_INSTALL_EPHEMERAL_PACKAGE
1442            = "android.intent.action.INSTALL_EPHEMERAL_PACKAGE";
1443
1444    /**
1445     * Service Action: Resolve ephemeral application.
1446     * <p>
1447     * The system will have a persistent connection to this service.
1448     * This is a protected intent that can only be sent by the system.
1449     * </p>
1450     *
1451     * @hide
1452     */
1453    @SystemApi
1454    @SdkConstant(SdkConstantType.SERVICE_ACTION)
1455    public static final String ACTION_RESOLVE_EPHEMERAL_PACKAGE
1456            = "android.intent.action.RESOLVE_EPHEMERAL_PACKAGE";
1457
1458    /**
1459     * Used as a string extra field with {@link #ACTION_INSTALL_PACKAGE} to install a
1460     * package.  Specifies the installer package name; this package will receive the
1461     * {@link #ACTION_APP_ERROR} intent.
1462     */
1463    public static final String EXTRA_INSTALLER_PACKAGE_NAME
1464            = "android.intent.extra.INSTALLER_PACKAGE_NAME";
1465
1466    /**
1467     * Used as a boolean extra field with {@link #ACTION_INSTALL_PACKAGE} to install a
1468     * package.  Specifies that the application being installed should not be
1469     * treated as coming from an unknown source, but as coming from the app
1470     * invoking the Intent.  For this to work you must start the installer with
1471     * startActivityForResult().
1472     */
1473    public static final String EXTRA_NOT_UNKNOWN_SOURCE
1474            = "android.intent.extra.NOT_UNKNOWN_SOURCE";
1475
1476    /**
1477     * Used as a URI extra field with {@link #ACTION_INSTALL_PACKAGE} and
1478     * {@link #ACTION_VIEW} to indicate the URI from which the local APK in the Intent
1479     * data field originated from.
1480     */
1481    public static final String EXTRA_ORIGINATING_URI
1482            = "android.intent.extra.ORIGINATING_URI";
1483
1484    /**
1485     * This extra can be used with any Intent used to launch an activity, supplying information
1486     * about who is launching that activity.  This field contains a {@link android.net.Uri}
1487     * object, typically an http: or https: URI of the web site that the referral came from;
1488     * it can also use the {@link #URI_ANDROID_APP_SCHEME android-app:} scheme to identify
1489     * a native application that it came from.
1490     *
1491     * <p>To retrieve this value in a client, use {@link android.app.Activity#getReferrer}
1492     * instead of directly retrieving the extra.  It is also valid for applications to
1493     * instead supply {@link #EXTRA_REFERRER_NAME} for cases where they can only create
1494     * a string, not a Uri; the field here, if supplied, will always take precedence,
1495     * however.</p>
1496     *
1497     * @see #EXTRA_REFERRER_NAME
1498     */
1499    public static final String EXTRA_REFERRER
1500            = "android.intent.extra.REFERRER";
1501
1502    /**
1503     * Alternate version of {@link #EXTRA_REFERRER} that supplies the URI as a String rather
1504     * than a {@link android.net.Uri} object.  Only for use in cases where Uri objects can
1505     * not be created, in particular when Intent extras are supplied through the
1506     * {@link #URI_INTENT_SCHEME intent:} or {@link #URI_ANDROID_APP_SCHEME android-app:}
1507     * schemes.
1508     *
1509     * @see #EXTRA_REFERRER
1510     */
1511    public static final String EXTRA_REFERRER_NAME
1512            = "android.intent.extra.REFERRER_NAME";
1513
1514    /**
1515     * Used as an int extra field with {@link #ACTION_INSTALL_PACKAGE} and
1516     * {@link} #ACTION_VIEW} to indicate the uid of the package that initiated the install
1517     * @hide
1518     */
1519    public static final String EXTRA_ORIGINATING_UID
1520            = "android.intent.extra.ORIGINATING_UID";
1521
1522    /**
1523     * Used as a boolean extra field with {@link #ACTION_INSTALL_PACKAGE} to install a
1524     * package.  Tells the installer UI to skip the confirmation with the user
1525     * if the .apk is replacing an existing one.
1526     * @deprecated As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, Android
1527     * will no longer show an interstitial message about updating existing
1528     * applications so this is no longer needed.
1529     */
1530    @Deprecated
1531    public static final String EXTRA_ALLOW_REPLACE
1532            = "android.intent.extra.ALLOW_REPLACE";
1533
1534    /**
1535     * Used as a boolean extra field with {@link #ACTION_INSTALL_PACKAGE} or
1536     * {@link #ACTION_UNINSTALL_PACKAGE}.  Specifies that the installer UI should
1537     * return to the application the result code of the install/uninstall.  The returned result
1538     * code will be {@link android.app.Activity#RESULT_OK} on success or
1539     * {@link android.app.Activity#RESULT_FIRST_USER} on failure.
1540     */
1541    public static final String EXTRA_RETURN_RESULT
1542            = "android.intent.extra.RETURN_RESULT";
1543
1544    /**
1545     * Package manager install result code.  @hide because result codes are not
1546     * yet ready to be exposed.
1547     */
1548    public static final String EXTRA_INSTALL_RESULT
1549            = "android.intent.extra.INSTALL_RESULT";
1550
1551    /**
1552     * Activity Action: Launch application uninstaller.
1553     * <p>
1554     * Input: The data must be a package: URI whose scheme specific part is
1555     * the package name of the current installed package to be uninstalled.
1556     * You can optionally supply {@link #EXTRA_RETURN_RESULT}.
1557     * <p>
1558     * Output: If {@link #EXTRA_RETURN_RESULT}, returns whether the install
1559     * succeeded.
1560     */
1561    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1562    public static final String ACTION_UNINSTALL_PACKAGE = "android.intent.action.UNINSTALL_PACKAGE";
1563
1564    /**
1565     * Specify whether the package should be uninstalled for all users.
1566     * @hide because these should not be part of normal application flow.
1567     */
1568    public static final String EXTRA_UNINSTALL_ALL_USERS
1569            = "android.intent.extra.UNINSTALL_ALL_USERS";
1570
1571    /**
1572     * A string associated with a {@link #ACTION_UPGRADE_SETUP} activity
1573     * describing the last run version of the platform that was setup.
1574     * @hide
1575     */
1576    public static final String METADATA_SETUP_VERSION = "android.SETUP_VERSION";
1577
1578    /**
1579     * Activity action: Launch UI to manage the permissions of an app.
1580     * <p>
1581     * Input: {@link #EXTRA_PACKAGE_NAME} specifies the package whose permissions
1582     * will be managed by the launched UI.
1583     * </p>
1584     * <p>
1585     * Output: Nothing.
1586     * </p>
1587     *
1588     * @see #EXTRA_PACKAGE_NAME
1589     *
1590     * @hide
1591     */
1592    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1593    public static final String ACTION_MANAGE_APP_PERMISSIONS =
1594            "android.intent.action.MANAGE_APP_PERMISSIONS";
1595
1596    /**
1597     * Activity action: Launch UI to manage permissions.
1598     * <p>
1599     * Input: Nothing.
1600     * </p>
1601     * <p>
1602     * Output: Nothing.
1603     * </p>
1604     *
1605     * @hide
1606     */
1607    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1608    public static final String ACTION_MANAGE_PERMISSIONS =
1609            "android.intent.action.MANAGE_PERMISSIONS";
1610
1611    /**
1612     * Intent extra: An app package name.
1613     * <p>
1614     * Type: String
1615     * </p>
1616     *
1617     * @hide
1618     */
1619    @SystemApi
1620    public static final String EXTRA_PACKAGE_NAME = "android.intent.extra.PACKAGE_NAME";
1621
1622    /**
1623     * Broadcast action that requests current permission granted information.  It will respond
1624     * to the request by sending a broadcast with action defined by
1625     * {@link #EXTRA_GET_PERMISSIONS_RESPONSE_INTENT}. The response will contain
1626     * {@link #EXTRA_GET_PERMISSIONS_COUNT_RESULT}, as well as
1627     * {@link #EXTRA_GET_PERMISSIONS_GROUP_LIST_RESULT}, with contents described below or
1628     * a null upon failure.
1629     *
1630     * <p>If {@link #EXTRA_PACKAGE_NAME} is included then the number of permissions granted, the
1631     * number of permissions requested and the number of granted additional permissions
1632     * by that package will be calculated and included as the first
1633     * and second elements respectively of an int[] in the response as
1634     * {@link #EXTRA_GET_PERMISSIONS_COUNT_RESULT}.  The response will also deliver the list
1635     * of localized permission group names that are granted in
1636     * {@link #EXTRA_GET_PERMISSIONS_GROUP_LIST_RESULT}.
1637     *
1638     * <p>If {@link #EXTRA_PACKAGE_NAME} is not included then the number of apps granted any runtime
1639     * permissions and the total number of apps requesting runtime permissions will be the first
1640     * and second elements respectively of an int[] in the response as
1641     * {@link #EXTRA_GET_PERMISSIONS_COUNT_RESULT}.
1642     *
1643     * @hide
1644     */
1645    public static final String ACTION_GET_PERMISSIONS_COUNT
1646            = "android.intent.action.GET_PERMISSIONS_COUNT";
1647
1648    /**
1649     * Broadcast action that requests list of all apps that have runtime permissions.  It will
1650     * respond to the request by sending a broadcast with action defined by
1651     * {@link #EXTRA_GET_PERMISSIONS_PACKAGES_RESPONSE_INTENT}. The response will contain
1652     * {@link #EXTRA_GET_PERMISSIONS_APP_LIST_RESULT}, as well as
1653     * {@link #EXTRA_GET_PERMISSIONS_APP_LABEL_LIST_RESULT}, with contents described below or
1654     * a null upon failure.
1655     *
1656     * <p>{@link #EXTRA_GET_PERMISSIONS_APP_LIST_RESULT} will contain a list of package names of
1657     * apps that have runtime permissions. {@link #EXTRA_GET_PERMISSIONS_APP_LABEL_LIST_RESULT}
1658     * will contain the list of app labels corresponding ot the apps in the first list.
1659     *
1660     * @hide
1661     */
1662    public static final String ACTION_GET_PERMISSIONS_PACKAGES
1663            = "android.intent.action.GET_PERMISSIONS_PACKAGES";
1664
1665    /**
1666     * Extra included in response to {@link #ACTION_GET_PERMISSIONS_COUNT}.
1667     * @hide
1668     */
1669    public static final String EXTRA_GET_PERMISSIONS_COUNT_RESULT
1670            = "android.intent.extra.GET_PERMISSIONS_COUNT_RESULT";
1671
1672    /**
1673     * List of CharSequence of localized permission group labels.
1674     * @hide
1675     */
1676    public static final String EXTRA_GET_PERMISSIONS_GROUP_LIST_RESULT
1677            = "android.intent.extra.GET_PERMISSIONS_GROUP_LIST_RESULT";
1678
1679    /**
1680     * String list of apps that have one or more runtime permissions.
1681     * @hide
1682     */
1683    public static final String EXTRA_GET_PERMISSIONS_APP_LIST_RESULT
1684            = "android.intent.extra.GET_PERMISSIONS_APP_LIST_RESULT";
1685
1686    /**
1687     * String list of app labels for apps that have one or more runtime permissions.
1688     * @hide
1689     */
1690    public static final String EXTRA_GET_PERMISSIONS_APP_LABEL_LIST_RESULT
1691            = "android.intent.extra.GET_PERMISSIONS_APP_LABEL_LIST_RESULT";
1692
1693    /**
1694     * Boolean list describing if the app is a system app for apps that have one or more runtime
1695     * permissions.
1696     * @hide
1697     */
1698    public static final String EXTRA_GET_PERMISSIONS_IS_SYSTEM_APP_LIST_RESULT
1699            = "android.intent.extra.GET_PERMISSIONS_IS_SYSTEM_APP_LIST_RESULT";
1700
1701    /**
1702     * Required extra to be sent with {@link #ACTION_GET_PERMISSIONS_COUNT} broadcasts.
1703     * @hide
1704     */
1705    public static final String EXTRA_GET_PERMISSIONS_RESPONSE_INTENT
1706            = "android.intent.extra.GET_PERMISSIONS_RESONSE_INTENT";
1707
1708    /**
1709     * Required extra to be sent with {@link #ACTION_GET_PERMISSIONS_PACKAGES} broadcasts.
1710     * @hide
1711     */
1712    public static final String EXTRA_GET_PERMISSIONS_PACKAGES_RESPONSE_INTENT
1713            = "android.intent.extra.GET_PERMISSIONS_PACKAGES_RESONSE_INTENT";
1714
1715    /**
1716     * Activity action: Launch UI to manage which apps have a given permission.
1717     * <p>
1718     * Input: {@link #EXTRA_PERMISSION_NAME} specifies the permission access
1719     * to which will be managed by the launched UI.
1720     * </p>
1721     * <p>
1722     * Output: Nothing.
1723     * </p>
1724     *
1725     * @see #EXTRA_PERMISSION_NAME
1726     *
1727     * @hide
1728     */
1729    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1730    public static final String ACTION_MANAGE_PERMISSION_APPS =
1731            "android.intent.action.MANAGE_PERMISSION_APPS";
1732
1733    /**
1734     * Intent extra: The name of a permission.
1735     * <p>
1736     * Type: String
1737     * </p>
1738     *
1739     * @hide
1740     */
1741    @SystemApi
1742    public static final String EXTRA_PERMISSION_NAME = "android.intent.extra.PERMISSION_NAME";
1743
1744    // ---------------------------------------------------------------------
1745    // ---------------------------------------------------------------------
1746    // Standard intent broadcast actions (see action variable).
1747
1748    /**
1749     * Broadcast Action: Sent when the device goes to sleep and becomes non-interactive.
1750     * <p>
1751     * For historical reasons, the name of this broadcast action refers to the power
1752     * state of the screen but it is actually sent in response to changes in the
1753     * overall interactive state of the device.
1754     * </p><p>
1755     * This broadcast is sent when the device becomes non-interactive which may have
1756     * nothing to do with the screen turning off.  To determine the
1757     * actual state of the screen, use {@link android.view.Display#getState}.
1758     * </p><p>
1759     * See {@link android.os.PowerManager#isInteractive} for details.
1760     * </p>
1761     * You <em>cannot</em> receive this through components declared in
1762     * manifests, only by explicitly registering for it with
1763     * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1764     * Context.registerReceiver()}.
1765     *
1766     * <p class="note">This is a protected intent that can only be sent
1767     * by the system.
1768     */
1769    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1770    public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
1771
1772    /**
1773     * Broadcast Action: Sent when the device wakes up and becomes interactive.
1774     * <p>
1775     * For historical reasons, the name of this broadcast action refers to the power
1776     * state of the screen but it is actually sent in response to changes in the
1777     * overall interactive state of the device.
1778     * </p><p>
1779     * This broadcast is sent when the device becomes interactive which may have
1780     * nothing to do with the screen turning on.  To determine the
1781     * actual state of the screen, use {@link android.view.Display#getState}.
1782     * </p><p>
1783     * See {@link android.os.PowerManager#isInteractive} for details.
1784     * </p>
1785     * You <em>cannot</em> receive this through components declared in
1786     * manifests, only by explicitly registering for it with
1787     * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1788     * Context.registerReceiver()}.
1789     *
1790     * <p class="note">This is a protected intent that can only be sent
1791     * by the system.
1792     */
1793    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1794    public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
1795
1796    /**
1797     * Broadcast Action: Sent after the system stops dreaming.
1798     *
1799     * <p class="note">This is a protected intent that can only be sent by the system.
1800     * It is only sent to registered receivers.</p>
1801     */
1802    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1803    public static final String ACTION_DREAMING_STOPPED = "android.intent.action.DREAMING_STOPPED";
1804
1805    /**
1806     * Broadcast Action: Sent after the system starts dreaming.
1807     *
1808     * <p class="note">This is a protected intent that can only be sent by the system.
1809     * It is only sent to registered receivers.</p>
1810     */
1811    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1812    public static final String ACTION_DREAMING_STARTED = "android.intent.action.DREAMING_STARTED";
1813
1814    /**
1815     * Broadcast Action: Sent when the user is present after device wakes up (e.g when the
1816     * keyguard is gone).
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_USER_PRESENT = "android.intent.action.USER_PRESENT";
1823
1824    /**
1825     * Broadcast Action: The current time has changed.  Sent every
1826     * minute.  You <em>cannot</em> receive this through components declared
1827     * in manifests, only by explicitly registering for it with
1828     * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1829     * Context.registerReceiver()}.
1830     *
1831     * <p class="note">This is a protected intent that can only be sent
1832     * by the system.
1833     */
1834    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1835    public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
1836    /**
1837     * Broadcast Action: The time was set.
1838     */
1839    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1840    public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
1841    /**
1842     * Broadcast Action: The date has changed.
1843     */
1844    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1845    public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
1846    /**
1847     * Broadcast Action: The timezone has changed. The intent will have the following extra values:</p>
1848     * <ul>
1849     *   <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time zone.</li>
1850     * </ul>
1851     *
1852     * <p class="note">This is a protected intent that can only be sent
1853     * by the system.
1854     */
1855    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1856    public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
1857    /**
1858     * Clear DNS Cache Action: This is broadcast when networks have changed and old
1859     * DNS entries should be tossed.
1860     * @hide
1861     */
1862    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1863    public static final String ACTION_CLEAR_DNS_CACHE = "android.intent.action.CLEAR_DNS_CACHE";
1864    /**
1865     * Alarm Changed Action: This is broadcast when the AlarmClock
1866     * application's alarm is set or unset.  It is used by the
1867     * AlarmClock application and the StatusBar service.
1868     * @hide
1869     */
1870    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1871    public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
1872    /**
1873     * Broadcast Action: This is broadcast once, after the system has finished
1874     * booting.  It can be used to perform application-specific initialization,
1875     * such as installing alarms.  You must hold the
1876     * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
1877     * in order to receive this broadcast.
1878     *
1879     * <p class="note">This is a protected intent that can only be sent
1880     * by the system.
1881     */
1882    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1883    public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
1884    /**
1885     * Broadcast Action: This is broadcast when a user action should request a
1886     * temporary system dialog to dismiss.  Some examples of temporary system
1887     * dialogs are the notification window-shade and the recent tasks dialog.
1888     */
1889    public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
1890    /**
1891     * Broadcast Action: Trigger the download and eventual installation
1892     * of a package.
1893     * <p>Input: {@link #getData} is the URI of the package file to download.
1894     *
1895     * <p class="note">This is a protected intent that can only be sent
1896     * by the system.
1897     *
1898     * @deprecated This constant has never been used.
1899     */
1900    @Deprecated
1901    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1902    public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
1903    /**
1904     * Broadcast Action: A new application package has been installed on the
1905     * device. The data contains the name of the package.  Note that the
1906     * newly installed package does <em>not</em> receive this broadcast.
1907     * <p>May include the following extras:
1908     * <ul>
1909     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1910     * <li> {@link #EXTRA_REPLACING} is set to true if this is following
1911     * an {@link #ACTION_PACKAGE_REMOVED} broadcast for the same package.
1912     * </ul>
1913     *
1914     * <p class="note">This is a protected intent that can only be sent
1915     * by the system.
1916     */
1917    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1918    public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
1919    /**
1920     * Broadcast Action: A new version of an application package has been
1921     * installed, replacing an existing version that was previously installed.
1922     * The data contains the name of the package.
1923     * <p>May include the following extras:
1924     * <ul>
1925     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1926     * </ul>
1927     *
1928     * <p class="note">This is a protected intent that can only be sent
1929     * by the system.
1930     */
1931    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1932    public static final String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
1933    /**
1934     * Broadcast Action: A new version of your application has been installed
1935     * over an existing one.  This is only sent to the application that was
1936     * replaced.  It does not contain any additional data; to receive it, just
1937     * use an intent filter for this action.
1938     *
1939     * <p class="note">This is a protected intent that can only be sent
1940     * by the system.
1941     */
1942    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1943    public static final String ACTION_MY_PACKAGE_REPLACED = "android.intent.action.MY_PACKAGE_REPLACED";
1944    /**
1945     * Broadcast Action: An existing application package has been removed from
1946     * the device.  The data contains the name of the package.  The package
1947     * that is being installed does <em>not</em> receive this Intent.
1948     * <ul>
1949     * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1950     * to the package.
1951     * <li> {@link #EXTRA_DATA_REMOVED} is set to true if the entire
1952     * application -- data and code -- is being removed.
1953     * <li> {@link #EXTRA_REPLACING} is set to true if this will be followed
1954     * by an {@link #ACTION_PACKAGE_ADDED} broadcast for the same package.
1955     * </ul>
1956     *
1957     * <p class="note">This is a protected intent that can only be sent
1958     * by the system.
1959     */
1960    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1961    public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
1962    /**
1963     * Broadcast Action: An existing application package has been completely
1964     * removed from the device.  The data contains the name of the package.
1965     * This is like {@link #ACTION_PACKAGE_REMOVED}, but only set when
1966     * {@link #EXTRA_DATA_REMOVED} is true and
1967     * {@link #EXTRA_REPLACING} is false of that broadcast.
1968     *
1969     * <ul>
1970     * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1971     * to the package.
1972     * </ul>
1973     *
1974     * <p class="note">This is a protected intent that can only be sent
1975     * by the system.
1976     */
1977    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1978    public static final String ACTION_PACKAGE_FULLY_REMOVED
1979            = "android.intent.action.PACKAGE_FULLY_REMOVED";
1980    /**
1981     * Broadcast Action: An existing application package has been changed (e.g.
1982     * a component has been enabled or disabled).  The data contains the name of
1983     * the package.
1984     * <ul>
1985     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1986     * <li> {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST} containing the class name
1987     * of the changed components (or the package name itself).
1988     * <li> {@link #EXTRA_DONT_KILL_APP} containing boolean field to override the
1989     * default action of restarting the application.
1990     * </ul>
1991     *
1992     * <p class="note">This is a protected intent that can only be sent
1993     * by the system.
1994     */
1995    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1996    public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
1997    /**
1998     * @hide
1999     * Broadcast Action: Ask system services if there is any reason to
2000     * restart the given package.  The data contains the name of the
2001     * package.
2002     * <ul>
2003     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
2004     * <li> {@link #EXTRA_PACKAGES} String array of all packages to check.
2005     * </ul>
2006     *
2007     * <p class="note">This is a protected intent that can only be sent
2008     * by the system.
2009     */
2010    @SystemApi
2011    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2012    public static final String ACTION_QUERY_PACKAGE_RESTART = "android.intent.action.QUERY_PACKAGE_RESTART";
2013    /**
2014     * Broadcast Action: The user has restarted a package, and all of its
2015     * processes have been killed.  All runtime state
2016     * associated with it (processes, alarms, notifications, etc) should
2017     * be removed.  Note that the restarted package does <em>not</em>
2018     * receive this broadcast.
2019     * The data contains the name of the package.
2020     * <ul>
2021     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
2022     * </ul>
2023     *
2024     * <p class="note">This is a protected intent that can only be sent
2025     * by the system.
2026     */
2027    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2028    public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
2029    /**
2030     * Broadcast Action: The user has cleared the data of a package.  This should
2031     * be preceded by {@link #ACTION_PACKAGE_RESTARTED}, after which all of
2032     * its persistent data is erased and this broadcast sent.
2033     * Note that the cleared package does <em>not</em>
2034     * receive this broadcast. The data contains the name of the package.
2035     * <ul>
2036     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
2037     * </ul>
2038     *
2039     * <p class="note">This is a protected intent that can only be sent
2040     * by the system.
2041     */
2042    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2043    public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
2044    /**
2045     * Broadcast Action: A user ID has been removed from the system.  The user
2046     * ID number is stored in the extra data under {@link #EXTRA_UID}.
2047     *
2048     * <p class="note">This is a protected intent that can only be sent
2049     * by the system.
2050     */
2051    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2052    public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
2053
2054    /**
2055     * Broadcast Action: Sent to the installer package of an application
2056     * when that application is first launched (that is the first time it
2057     * is moved out of the stopped state).  The data contains the name of the package.
2058     *
2059     * <p class="note">This is a protected intent that can only be sent
2060     * by the system.
2061     */
2062    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2063    public static final String ACTION_PACKAGE_FIRST_LAUNCH = "android.intent.action.PACKAGE_FIRST_LAUNCH";
2064
2065    /**
2066     * Broadcast Action: Sent to the system package verifier when a package
2067     * needs to be verified. The data contains the package URI.
2068     * <p class="note">
2069     * This is a protected intent that can only be sent by the system.
2070     * </p>
2071     */
2072    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2073    public static final String ACTION_PACKAGE_NEEDS_VERIFICATION = "android.intent.action.PACKAGE_NEEDS_VERIFICATION";
2074
2075    /**
2076     * Broadcast Action: Sent to the system package verifier when a package is
2077     * verified. The data contains the package URI.
2078     * <p class="note">
2079     * This is a protected intent that can only be sent by the system.
2080     */
2081    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2082    public static final String ACTION_PACKAGE_VERIFIED = "android.intent.action.PACKAGE_VERIFIED";
2083
2084    /**
2085     * Broadcast Action: Sent to the system intent filter verifier when an intent filter
2086     * needs to be verified. The data contains the filter data hosts to be verified against.
2087     * <p class="note">
2088     * This is a protected intent that can only be sent by the system.
2089     * </p>
2090     *
2091     * @hide
2092     */
2093    @SystemApi
2094    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2095    public static final String ACTION_INTENT_FILTER_NEEDS_VERIFICATION = "android.intent.action.INTENT_FILTER_NEEDS_VERIFICATION";
2096
2097    /**
2098     * Broadcast Action: Resources for a set of packages (which were
2099     * previously unavailable) are currently
2100     * available since the media on which they exist is available.
2101     * The extra data {@link #EXTRA_CHANGED_PACKAGE_LIST} contains a
2102     * list of packages whose availability changed.
2103     * The extra data {@link #EXTRA_CHANGED_UID_LIST} contains a
2104     * list of uids of packages whose availability changed.
2105     * Note that the
2106     * packages in this list do <em>not</em> receive this broadcast.
2107     * The specified set of packages are now available on the system.
2108     * <p>Includes the following extras:
2109     * <ul>
2110     * <li> {@link #EXTRA_CHANGED_PACKAGE_LIST} is the set of packages
2111     * whose resources(were previously unavailable) are currently available.
2112     * {@link #EXTRA_CHANGED_UID_LIST} is the set of uids of the
2113     * packages whose resources(were previously unavailable)
2114     * are  currently available.
2115     * </ul>
2116     *
2117     * <p class="note">This is a protected intent that can only be sent
2118     * by the system.
2119     */
2120    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2121    public static final String ACTION_EXTERNAL_APPLICATIONS_AVAILABLE =
2122        "android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE";
2123
2124    /**
2125     * Broadcast Action: Resources for a set of packages are currently
2126     * unavailable since the media on which they exist is unavailable.
2127     * The extra data {@link #EXTRA_CHANGED_PACKAGE_LIST} contains a
2128     * list of packages whose availability changed.
2129     * The extra data {@link #EXTRA_CHANGED_UID_LIST} contains a
2130     * list of uids of packages whose availability changed.
2131     * The specified set of packages can no longer be
2132     * launched and are practically unavailable on the system.
2133     * <p>Inclues the following extras:
2134     * <ul>
2135     * <li> {@link #EXTRA_CHANGED_PACKAGE_LIST} is the set of packages
2136     * whose resources are no longer available.
2137     * {@link #EXTRA_CHANGED_UID_LIST} is the set of packages
2138     * whose resources are no longer available.
2139     * </ul>
2140     *
2141     * <p class="note">This is a protected intent that can only be sent
2142     * by the system.
2143     */
2144    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2145    public static final String ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE =
2146        "android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE";
2147
2148    /**
2149     * Broadcast Action:  The current system wallpaper has changed.  See
2150     * {@link android.app.WallpaperManager} for retrieving the new wallpaper.
2151     * This should <em>only</em> be used to determine when the wallpaper
2152     * has changed to show the new wallpaper to the user.  You should certainly
2153     * never, in response to this, change the wallpaper or other attributes of
2154     * it such as the suggested size.  That would be crazy, right?  You'd cause
2155     * all kinds of loops, especially if other apps are doing similar things,
2156     * right?  Of course.  So please don't do this.
2157     *
2158     * @deprecated Modern applications should use
2159     * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WALLPAPER
2160     * WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER} to have the wallpaper
2161     * shown behind their UI, rather than watching for this broadcast and
2162     * rendering the wallpaper on their own.
2163     */
2164    @Deprecated @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2165    public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
2166    /**
2167     * Broadcast Action: The current device {@link android.content.res.Configuration}
2168     * (orientation, locale, etc) has changed.  When such a change happens, the
2169     * UIs (view hierarchy) will need to be rebuilt based on this new
2170     * information; for the most part, applications don't need to worry about
2171     * this, because the system will take care of stopping and restarting the
2172     * application to make sure it sees the new changes.  Some system code that
2173     * can not be restarted will need to watch for this action and handle it
2174     * appropriately.
2175     *
2176     * <p class="note">
2177     * You <em>cannot</em> receive this through components declared
2178     * in manifests, only by explicitly registering for it with
2179     * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
2180     * Context.registerReceiver()}.
2181     *
2182     * <p class="note">This is a protected intent that can only be sent
2183     * by the system.
2184     *
2185     * @see android.content.res.Configuration
2186     */
2187    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2188    public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
2189    /**
2190     * Broadcast Action: The current device's locale has changed.
2191     *
2192     * <p class="note">This is a protected intent that can only be sent
2193     * by the system.
2194     */
2195    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2196    public static final String ACTION_LOCALE_CHANGED = "android.intent.action.LOCALE_CHANGED";
2197    /**
2198     * Broadcast Action:  This is a <em>sticky broadcast</em> containing the
2199     * charging state, level, and other information about the battery.
2200     * See {@link android.os.BatteryManager} for documentation on the
2201     * contents of the Intent.
2202     *
2203     * <p class="note">
2204     * You <em>cannot</em> receive this through components declared
2205     * in manifests, only by explicitly registering for it with
2206     * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
2207     * Context.registerReceiver()}.  See {@link #ACTION_BATTERY_LOW},
2208     * {@link #ACTION_BATTERY_OKAY}, {@link #ACTION_POWER_CONNECTED},
2209     * and {@link #ACTION_POWER_DISCONNECTED} for distinct battery-related
2210     * broadcasts that are sent and can be received through manifest
2211     * receivers.
2212     *
2213     * <p class="note">This is a protected intent that can only be sent
2214     * by the system.
2215     */
2216    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2217    public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
2218    /**
2219     * Broadcast Action:  Indicates low battery condition on the device.
2220     * This broadcast corresponds to the "Low battery warning" system dialog.
2221     *
2222     * <p class="note">This is a protected intent that can only be sent
2223     * by the system.
2224     */
2225    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2226    public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
2227    /**
2228     * Broadcast Action:  Indicates the battery is now okay after being low.
2229     * This will be sent after {@link #ACTION_BATTERY_LOW} once the battery has
2230     * gone back up to an okay state.
2231     *
2232     * <p class="note">This is a protected intent that can only be sent
2233     * by the system.
2234     */
2235    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2236    public static final String ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";
2237    /**
2238     * Broadcast Action:  External power has been connected to the device.
2239     * This is intended for applications that wish to register specifically to this notification.
2240     * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
2241     * stay active to receive this notification.  This action can be used to implement actions
2242     * that wait until power is available to trigger.
2243     *
2244     * <p class="note">This is a protected intent that can only be sent
2245     * by the system.
2246     */
2247    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2248    public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
2249    /**
2250     * Broadcast Action:  External power has been removed from the device.
2251     * This is intended for applications that wish to register specifically to this notification.
2252     * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
2253     * stay active to receive this notification.  This action can be used to implement actions
2254     * that wait until power is available to trigger.
2255     *
2256     * <p class="note">This is a protected intent that can only be sent
2257     * by the system.
2258     */
2259    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2260    public static final String ACTION_POWER_DISCONNECTED =
2261            "android.intent.action.ACTION_POWER_DISCONNECTED";
2262    /**
2263     * Broadcast Action:  Device is shutting down.
2264     * This is broadcast when the device is being shut down (completely turned
2265     * off, not sleeping).  Once the broadcast is complete, the final shutdown
2266     * will proceed and all unsaved data lost.  Apps will not normally need
2267     * to handle this, since the foreground activity will be paused as well.
2268     *
2269     * <p class="note">This is a protected intent that can only be sent
2270     * by the system.
2271     * <p>May include the following extras:
2272     * <ul>
2273     * <li> {@link #EXTRA_SHUTDOWN_USERSPACE_ONLY} a boolean that is set to true if this
2274     * shutdown is only for userspace processes.  If not set, assumed to be false.
2275     * </ul>
2276     */
2277    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2278    public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
2279    /**
2280     * Activity Action:  Start this activity to request system shutdown.
2281     * The optional boolean extra field {@link #EXTRA_KEY_CONFIRM} can be set to true
2282     * to request confirmation from the user before shutting down. The optional boolean
2283     * extra field {@link #EXTRA_USER_REQUESTED_SHUTDOWN} can be set to true to
2284     * indicate that the shutdown is requested by the user.
2285     *
2286     * <p class="note">This is a protected intent that can only be sent
2287     * by the system.
2288     *
2289     * {@hide}
2290     */
2291    public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
2292    /**
2293     * Broadcast Action:  A sticky broadcast that indicates low memory
2294     * condition on the device
2295     *
2296     * <p class="note">This is a protected intent that can only be sent
2297     * by the system.
2298     */
2299    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2300    public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
2301    /**
2302     * Broadcast Action:  Indicates low memory condition on the device no longer exists
2303     *
2304     * <p class="note">This is a protected intent that can only be sent
2305     * by the system.
2306     */
2307    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2308    public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
2309    /**
2310     * Broadcast Action:  A sticky broadcast that indicates a memory full
2311     * condition on the device. This is intended for activities that want
2312     * to be able to fill the data partition completely, leaving only
2313     * enough free space to prevent system-wide SQLite failures.
2314     *
2315     * <p class="note">This is a protected intent that can only be sent
2316     * by the system.
2317     *
2318     * {@hide}
2319     */
2320    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2321    public static final String ACTION_DEVICE_STORAGE_FULL = "android.intent.action.DEVICE_STORAGE_FULL";
2322    /**
2323     * Broadcast Action:  Indicates memory full condition on the device
2324     * no longer exists.
2325     *
2326     * <p class="note">This is a protected intent that can only be sent
2327     * by the system.
2328     *
2329     * {@hide}
2330     */
2331    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2332    public static final String ACTION_DEVICE_STORAGE_NOT_FULL = "android.intent.action.DEVICE_STORAGE_NOT_FULL";
2333    /**
2334     * Broadcast Action:  Indicates low memory condition notification acknowledged by user
2335     * and package management should be started.
2336     * This is triggered by the user from the ACTION_DEVICE_STORAGE_LOW
2337     * notification.
2338     */
2339    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2340    public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
2341    /**
2342     * Broadcast Action:  The device has entered USB Mass Storage mode.
2343     * This is used mainly for the USB Settings panel.
2344     * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
2345     * when the SD card file system is mounted or unmounted
2346     * @deprecated replaced by android.os.storage.StorageEventListener
2347     */
2348    @Deprecated
2349    public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
2350
2351    /**
2352     * Broadcast Action:  The device has exited USB Mass Storage mode.
2353     * This is used mainly for the USB Settings panel.
2354     * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
2355     * when the SD card file system is mounted or unmounted
2356     * @deprecated replaced by android.os.storage.StorageEventListener
2357     */
2358    @Deprecated
2359    public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
2360
2361    /**
2362     * Broadcast Action:  External media has been removed.
2363     * The path to the mount point for the removed media is contained in the Intent.mData field.
2364     */
2365    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2366    public static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
2367
2368    /**
2369     * Broadcast Action:  External media is present, but not mounted at its mount point.
2370     * The path to the mount point for the unmounted media is contained in the Intent.mData field.
2371     */
2372    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2373    public static final String ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
2374
2375    /**
2376     * Broadcast Action:  External media is present, and being disk-checked
2377     * The path to the mount point for the checking media is contained in the Intent.mData field.
2378     */
2379    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2380    public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
2381
2382    /**
2383     * Broadcast Action:  External media is present, but is using an incompatible fs (or is blank)
2384     * The path to the mount point for the checking media is contained in the Intent.mData field.
2385     */
2386    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2387    public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
2388
2389    /**
2390     * Broadcast Action:  External media is present and mounted at its mount point.
2391     * The path to the mount point for the mounted media is contained in the Intent.mData field.
2392     * The Intent contains an extra with name "read-only" and Boolean value to indicate if the
2393     * media was mounted read only.
2394     */
2395    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2396    public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
2397
2398    /**
2399     * Broadcast Action:  External media is unmounted because it is being shared via USB mass storage.
2400     * The path to the mount point for the shared media is contained in the Intent.mData field.
2401     */
2402    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2403    public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
2404
2405    /**
2406     * Broadcast Action:  External media is no longer being shared via USB mass storage.
2407     * The path to the mount point for the previously shared media is contained in the Intent.mData field.
2408     *
2409     * @hide
2410     */
2411    public static final String ACTION_MEDIA_UNSHARED = "android.intent.action.MEDIA_UNSHARED";
2412
2413    /**
2414     * Broadcast Action:  External media was removed from SD card slot, but mount point was not unmounted.
2415     * The path to the mount point for the removed media is contained in the Intent.mData field.
2416     */
2417    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2418    public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
2419
2420    /**
2421     * Broadcast Action:  External media is present but cannot be mounted.
2422     * The path to the mount point for the unmountable media is contained in the Intent.mData field.
2423     */
2424    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2425    public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
2426
2427   /**
2428     * Broadcast Action:  User has expressed the desire to remove the external storage media.
2429     * Applications should close all files they have open within the mount point when they receive this intent.
2430     * The path to the mount point for the media to be ejected is contained in the Intent.mData field.
2431     */
2432    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2433    public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
2434
2435    /**
2436     * Broadcast Action:  The media scanner has started scanning a directory.
2437     * The path to the directory being scanned is contained in the Intent.mData field.
2438     */
2439    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2440    public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
2441
2442   /**
2443     * Broadcast Action:  The media scanner has finished scanning a directory.
2444     * The path to the scanned directory is contained in the Intent.mData field.
2445     */
2446    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2447    public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
2448
2449   /**
2450     * Broadcast Action:  Request the media scanner to scan a file and add it to the media database.
2451     * The path to the file is contained in the Intent.mData field.
2452     */
2453    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2454    public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
2455
2456   /**
2457     * Broadcast Action:  The "Media Button" was pressed.  Includes a single
2458     * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
2459     * caused the broadcast.
2460     */
2461    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2462    public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
2463
2464    /**
2465     * Broadcast Action:  The "Camera Button" was pressed.  Includes a single
2466     * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
2467     * caused the broadcast.
2468     */
2469    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2470    public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
2471
2472    // *** NOTE: @todo(*) The following really should go into a more domain-specific
2473    // location; they are not general-purpose actions.
2474
2475    /**
2476     * Broadcast Action: A GTalk connection has been established.
2477     */
2478    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2479    public static final String ACTION_GTALK_SERVICE_CONNECTED =
2480            "android.intent.action.GTALK_CONNECTED";
2481
2482    /**
2483     * Broadcast Action: A GTalk connection has been disconnected.
2484     */
2485    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2486    public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
2487            "android.intent.action.GTALK_DISCONNECTED";
2488
2489    /**
2490     * Broadcast Action: An input method has been changed.
2491     */
2492    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2493    public static final String ACTION_INPUT_METHOD_CHANGED =
2494            "android.intent.action.INPUT_METHOD_CHANGED";
2495
2496    /**
2497     * <p>Broadcast Action: The user has switched the phone into or out of Airplane Mode. One or
2498     * more radios have been turned off or on. The intent will have the following extra value:</p>
2499     * <ul>
2500     *   <li><em>state</em> - A boolean value indicating whether Airplane Mode is on. If true,
2501     *   then cell radio and possibly other radios such as bluetooth or WiFi may have also been
2502     *   turned off</li>
2503     * </ul>
2504     *
2505     * <p class="note">This is a protected intent that can only be sent
2506     * by the system.
2507     */
2508    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2509    public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
2510
2511    /**
2512     * Broadcast Action: Some content providers have parts of their namespace
2513     * where they publish new events or items that the user may be especially
2514     * interested in. For these things, they may broadcast this action when the
2515     * set of interesting items change.
2516     *
2517     * For example, GmailProvider sends this notification when the set of unread
2518     * mail in the inbox changes.
2519     *
2520     * <p>The data of the intent identifies which part of which provider
2521     * changed. When queried through the content resolver, the data URI will
2522     * return the data set in question.
2523     *
2524     * <p>The intent will have the following extra values:
2525     * <ul>
2526     *   <li><em>count</em> - The number of items in the data set. This is the
2527     *       same as the number of items in the cursor returned by querying the
2528     *       data URI. </li>
2529     * </ul>
2530     *
2531     * This intent will be sent at boot (if the count is non-zero) and when the
2532     * data set changes. It is possible for the data set to change without the
2533     * count changing (for example, if a new unread message arrives in the same
2534     * sync operation in which a message is archived). The phone should still
2535     * ring/vibrate/etc as normal in this case.
2536     */
2537    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2538    public static final String ACTION_PROVIDER_CHANGED =
2539            "android.intent.action.PROVIDER_CHANGED";
2540
2541    /**
2542     * Broadcast Action: Wired Headset plugged in or unplugged.
2543     *
2544     * Same as {@link android.media.AudioManager#ACTION_HEADSET_PLUG}, to be consulted for value
2545     *   and documentation.
2546     * <p>If the minimum SDK version of your application is
2547     * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, it is recommended to refer
2548     * to the <code>AudioManager</code> constant in your receiver registration code instead.
2549     */
2550    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2551    public static final String ACTION_HEADSET_PLUG = android.media.AudioManager.ACTION_HEADSET_PLUG;
2552
2553    /**
2554     * <p>Broadcast Action: The user has switched on advanced settings in the settings app:</p>
2555     * <ul>
2556     *   <li><em>state</em> - A boolean value indicating whether the settings is on or off.</li>
2557     * </ul>
2558     *
2559     * <p class="note">This is a protected intent that can only be sent
2560     * by the system.
2561     *
2562     * @hide
2563     */
2564    //@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2565    public static final String ACTION_ADVANCED_SETTINGS_CHANGED
2566            = "android.intent.action.ADVANCED_SETTINGS";
2567
2568    /**
2569     *  Broadcast Action: Sent after application restrictions are changed.
2570     *
2571     * <p class="note">This is a protected intent that can only be sent
2572     * by the system.</p>
2573     */
2574    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2575    public static final String ACTION_APPLICATION_RESTRICTIONS_CHANGED =
2576            "android.intent.action.APPLICATION_RESTRICTIONS_CHANGED";
2577
2578    /**
2579     * Broadcast Action: An outgoing call is about to be placed.
2580     *
2581     * <p>The Intent will have the following extra value:</p>
2582     * <ul>
2583     *   <li><em>{@link android.content.Intent#EXTRA_PHONE_NUMBER}</em> -
2584     *       the phone number originally intended to be dialed.</li>
2585     * </ul>
2586     * <p>Once the broadcast is finished, the resultData is used as the actual
2587     * number to call.  If  <code>null</code>, no call will be placed.</p>
2588     * <p>It is perfectly acceptable for multiple receivers to process the
2589     * outgoing call in turn: for example, a parental control application
2590     * might verify that the user is authorized to place the call at that
2591     * time, then a number-rewriting application might add an area code if
2592     * one was not specified.</p>
2593     * <p>For consistency, any receiver whose purpose is to prohibit phone
2594     * calls should have a priority of 0, to ensure it will see the final
2595     * phone number to be dialed.
2596     * Any receiver whose purpose is to rewrite phone numbers to be called
2597     * should have a positive priority.
2598     * Negative priorities are reserved for the system for this broadcast;
2599     * using them may cause problems.</p>
2600     * <p>Any BroadcastReceiver receiving this Intent <em>must not</em>
2601     * abort the broadcast.</p>
2602     * <p>Emergency calls cannot be intercepted using this mechanism, and
2603     * other calls cannot be modified to call emergency numbers using this
2604     * mechanism.
2605     * <p>Some apps (such as VoIP apps) may want to redirect the outgoing
2606     * call to use their own service instead. Those apps should first prevent
2607     * the call from being placed by setting resultData to <code>null</code>
2608     * and then start their own app to make the call.
2609     * <p>You must hold the
2610     * {@link android.Manifest.permission#PROCESS_OUTGOING_CALLS}
2611     * permission to receive this Intent.</p>
2612     *
2613     * <p class="note">This is a protected intent that can only be sent
2614     * by the system.
2615     */
2616    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2617    public static final String ACTION_NEW_OUTGOING_CALL =
2618            "android.intent.action.NEW_OUTGOING_CALL";
2619
2620    /**
2621     * Broadcast Action: Have the device reboot.  This is only for use by
2622     * system code.
2623     *
2624     * <p class="note">This is a protected intent that can only be sent
2625     * by the system.
2626     */
2627    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2628    public static final String ACTION_REBOOT =
2629            "android.intent.action.REBOOT";
2630
2631    /**
2632     * Broadcast Action:  A sticky broadcast for changes in the physical
2633     * docking state of the device.
2634     *
2635     * <p>The intent will have the following extra values:
2636     * <ul>
2637     *   <li><em>{@link #EXTRA_DOCK_STATE}</em> - the current dock
2638     *       state, indicating which dock the device is physically in.</li>
2639     * </ul>
2640     * <p>This is intended for monitoring the current physical dock state.
2641     * See {@link android.app.UiModeManager} for the normal API dealing with
2642     * dock mode changes.
2643     */
2644    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2645    public static final String ACTION_DOCK_EVENT =
2646            "android.intent.action.DOCK_EVENT";
2647
2648    /**
2649     * Broadcast Action: A broadcast when idle maintenance can be started.
2650     * This means that the user is not interacting with the device and is
2651     * not expected to do so soon. Typical use of the idle maintenance is
2652     * to perform somehow expensive tasks that can be postponed at a moment
2653     * when they will not degrade user experience.
2654     * <p>
2655     * <p class="note">In order to keep the device responsive in case of an
2656     * unexpected user interaction, implementations of a maintenance task
2657     * should be interruptible. In such a scenario a broadcast with action
2658     * {@link #ACTION_IDLE_MAINTENANCE_END} will be sent. In other words, you
2659     * should not do the maintenance work in
2660     * {@link BroadcastReceiver#onReceive(Context, Intent)}, rather start a
2661     * maintenance service by {@link Context#startService(Intent)}. Also
2662     * you should hold a wake lock while your maintenance service is running
2663     * to prevent the device going to sleep.
2664     * </p>
2665     * <p>
2666     * <p class="note">This is a protected intent that can only be sent by
2667     * the system.
2668     * </p>
2669     *
2670     * @see #ACTION_IDLE_MAINTENANCE_END
2671     *
2672     * @hide
2673     */
2674    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2675    public static final String ACTION_IDLE_MAINTENANCE_START =
2676            "android.intent.action.ACTION_IDLE_MAINTENANCE_START";
2677
2678    /**
2679     * Broadcast Action:  A broadcast when idle maintenance should be stopped.
2680     * This means that the user was not interacting with the device as a result
2681     * of which a broadcast with action {@link #ACTION_IDLE_MAINTENANCE_START}
2682     * was sent and now the user started interacting with the device. Typical
2683     * use of the idle maintenance is to perform somehow expensive tasks that
2684     * can be postponed at a moment when they will not degrade user experience.
2685     * <p>
2686     * <p class="note">In order to keep the device responsive in case of an
2687     * unexpected user interaction, implementations of a maintenance task
2688     * should be interruptible. Hence, on receiving a broadcast with this
2689     * action, the maintenance task should be interrupted as soon as possible.
2690     * In other words, you should not do the maintenance work in
2691     * {@link BroadcastReceiver#onReceive(Context, Intent)}, rather stop the
2692     * maintenance service that was started on receiving of
2693     * {@link #ACTION_IDLE_MAINTENANCE_START}.Also you should release the wake
2694     * lock you acquired when your maintenance service started.
2695     * </p>
2696     * <p class="note">This is a protected intent that can only be sent
2697     * by the system.
2698     *
2699     * @see #ACTION_IDLE_MAINTENANCE_START
2700     *
2701     * @hide
2702     */
2703    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2704    public static final String ACTION_IDLE_MAINTENANCE_END =
2705            "android.intent.action.ACTION_IDLE_MAINTENANCE_END";
2706
2707    /**
2708     * Broadcast Action: a remote intent is to be broadcasted.
2709     *
2710     * A remote intent is used for remote RPC between devices. The remote intent
2711     * is serialized and sent from one device to another device. The receiving
2712     * device parses the remote intent and broadcasts it. Note that anyone can
2713     * broadcast a remote intent. However, if the intent receiver of the remote intent
2714     * does not trust intent broadcasts from arbitrary intent senders, it should require
2715     * the sender to hold certain permissions so only trusted sender's broadcast will be
2716     * let through.
2717     * @hide
2718     */
2719    public static final String ACTION_REMOTE_INTENT =
2720            "com.google.android.c2dm.intent.RECEIVE";
2721
2722    /**
2723     * Broadcast Action: hook for permforming cleanup after a system update.
2724     *
2725     * The broadcast is sent when the system is booting, before the
2726     * BOOT_COMPLETED broadcast.  It is only sent to receivers in the system
2727     * image.  A receiver for this should do its work and then disable itself
2728     * so that it does not get run again at the next boot.
2729     * @hide
2730     */
2731    public static final String ACTION_PRE_BOOT_COMPLETED =
2732            "android.intent.action.PRE_BOOT_COMPLETED";
2733
2734    /**
2735     * Broadcast to a specific application to query any supported restrictions to impose
2736     * on restricted users. The broadcast intent contains an extra
2737     * {@link #EXTRA_RESTRICTIONS_BUNDLE} with the currently persisted
2738     * restrictions as a Bundle of key/value pairs. The value types can be Boolean, String or
2739     * String[] depending on the restriction type.<p/>
2740     * The response should contain an extra {@link #EXTRA_RESTRICTIONS_LIST},
2741     * which is of type <code>ArrayList&lt;RestrictionEntry&gt;</code>. It can also
2742     * contain an extra {@link #EXTRA_RESTRICTIONS_INTENT}, which is of type <code>Intent</code>.
2743     * The activity specified by that intent will be launched for a result which must contain
2744     * one of the extras {@link #EXTRA_RESTRICTIONS_LIST} or {@link #EXTRA_RESTRICTIONS_BUNDLE}.
2745     * The keys and values of the returned restrictions will be persisted.
2746     * @see RestrictionEntry
2747     */
2748    public static final String ACTION_GET_RESTRICTION_ENTRIES =
2749            "android.intent.action.GET_RESTRICTION_ENTRIES";
2750
2751    /**
2752     * Sent the first time a user is starting, to allow system apps to
2753     * perform one time initialization.  (This will not be seen by third
2754     * party applications because a newly initialized user does not have any
2755     * third party applications installed for it.)  This is sent early in
2756     * starting the user, around the time the home app is started, before
2757     * {@link #ACTION_BOOT_COMPLETED} is sent.  This is sent as a foreground
2758     * broadcast, since it is part of a visible user interaction; be as quick
2759     * as possible when handling it.
2760     */
2761    public static final String ACTION_USER_INITIALIZE =
2762            "android.intent.action.USER_INITIALIZE";
2763
2764    /**
2765     * Sent when a user switch is happening, causing the process's user to be
2766     * brought to the foreground.  This is only sent to receivers registered
2767     * through {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
2768     * Context.registerReceiver}.  It is sent to the user that is going to the
2769     * foreground.  This is sent as a foreground
2770     * broadcast, since it is part of a visible user interaction; be as quick
2771     * as possible when handling it.
2772     */
2773    public static final String ACTION_USER_FOREGROUND =
2774            "android.intent.action.USER_FOREGROUND";
2775
2776    /**
2777     * Sent when a user switch is happening, causing the process's user to be
2778     * sent to the background.  This is only sent to receivers registered
2779     * through {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
2780     * Context.registerReceiver}.  It is sent to the user that is going to the
2781     * background.  This is sent as a foreground
2782     * broadcast, since it is part of a visible user interaction; be as quick
2783     * as possible when handling it.
2784     */
2785    public static final String ACTION_USER_BACKGROUND =
2786            "android.intent.action.USER_BACKGROUND";
2787
2788    /**
2789     * Broadcast sent to the system when a user is added. Carries an extra
2790     * EXTRA_USER_HANDLE that has the userHandle of the new user.  It is sent to
2791     * all running users.  You must hold
2792     * {@link android.Manifest.permission#MANAGE_USERS} to receive this broadcast.
2793     * @hide
2794     */
2795    public static final String ACTION_USER_ADDED =
2796            "android.intent.action.USER_ADDED";
2797
2798    /**
2799     * Broadcast sent by the system when a user is started. Carries an extra
2800     * EXTRA_USER_HANDLE that has the userHandle of the user.  This is only sent to
2801     * registered receivers, not manifest receivers.  It is sent to the user
2802     * that has been started.  This is sent as a foreground
2803     * broadcast, since it is part of a visible user interaction; be as quick
2804     * as possible when handling it.
2805     * @hide
2806     */
2807    public static final String ACTION_USER_STARTED =
2808            "android.intent.action.USER_STARTED";
2809
2810    /**
2811     * Broadcast sent when a user is in the process of starting.  Carries an extra
2812     * EXTRA_USER_HANDLE that has the userHandle of the user.  This is only
2813     * sent to registered receivers, not manifest receivers.  It is sent to all
2814     * users (including the one that is being started).  You must hold
2815     * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} to receive
2816     * this broadcast.  This is sent as a background broadcast, since
2817     * its result is not part of the primary UX flow; to safely keep track of
2818     * started/stopped state of a user you can use this in conjunction with
2819     * {@link #ACTION_USER_STOPPING}.  It is <b>not</b> generally safe to use with
2820     * other user state broadcasts since those are foreground broadcasts so can
2821     * execute in a different order.
2822     * @hide
2823     */
2824    public static final String ACTION_USER_STARTING =
2825            "android.intent.action.USER_STARTING";
2826
2827    /**
2828     * Broadcast sent when a user is going to be stopped.  Carries an extra
2829     * EXTRA_USER_HANDLE that has the userHandle of the user.  This is only
2830     * sent to registered receivers, not manifest receivers.  It is sent to all
2831     * users (including the one that is being stopped).  You must hold
2832     * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} to receive
2833     * this broadcast.  The user will not stop until all receivers have
2834     * handled the broadcast.  This is sent as a background broadcast, since
2835     * its result is not part of the primary UX flow; to safely keep track of
2836     * started/stopped state of a user you can use this in conjunction with
2837     * {@link #ACTION_USER_STARTING}.  It is <b>not</b> generally safe to use with
2838     * other user state broadcasts since those are foreground broadcasts so can
2839     * execute in a different order.
2840     * @hide
2841     */
2842    public static final String ACTION_USER_STOPPING =
2843            "android.intent.action.USER_STOPPING";
2844
2845    /**
2846     * Broadcast sent to the system when a user is stopped. Carries an extra
2847     * EXTRA_USER_HANDLE that has the userHandle of the user.  This is similar to
2848     * {@link #ACTION_PACKAGE_RESTARTED}, but for an entire user instead of a
2849     * specific package.  This is only sent to registered receivers, not manifest
2850     * receivers.  It is sent to all running users <em>except</em> the one that
2851     * has just been stopped (which is no longer running).
2852     * @hide
2853     */
2854    public static final String ACTION_USER_STOPPED =
2855            "android.intent.action.USER_STOPPED";
2856
2857    /**
2858     * Broadcast sent to the system when a user is removed. Carries an extra EXTRA_USER_HANDLE that has
2859     * the userHandle of the user.  It is sent to all running users except the
2860     * one that has been removed. The user will not be completely removed until all receivers have
2861     * handled the broadcast. You must hold
2862     * {@link android.Manifest.permission#MANAGE_USERS} to receive this broadcast.
2863     * @hide
2864     */
2865    public static final String ACTION_USER_REMOVED =
2866            "android.intent.action.USER_REMOVED";
2867
2868    /**
2869     * Broadcast sent to the system when the user switches. Carries an extra EXTRA_USER_HANDLE that has
2870     * the userHandle of the user to become the current one. This is only sent to
2871     * registered receivers, not manifest receivers.  It is sent to all running users.
2872     * You must hold
2873     * {@link android.Manifest.permission#MANAGE_USERS} to receive this broadcast.
2874     * @hide
2875     */
2876    public static final String ACTION_USER_SWITCHED =
2877            "android.intent.action.USER_SWITCHED";
2878
2879    /**
2880     * Broadcast sent to the system when a user's information changes. Carries an extra
2881     * {@link #EXTRA_USER_HANDLE} to indicate which user's information changed.
2882     * This is only sent to registered receivers, not manifest receivers. It is sent to all users.
2883     * @hide
2884     */
2885    public static final String ACTION_USER_INFO_CHANGED =
2886            "android.intent.action.USER_INFO_CHANGED";
2887
2888    /**
2889     * Broadcast sent to the primary user when an associated managed profile is added (the profile
2890     * was created and is ready to be used). Carries an extra {@link #EXTRA_USER} that specifies
2891     * the UserHandle of the profile that was added. Only applications (for example Launchers)
2892     * that need to display merged content across both primary and managed profiles need to
2893     * worry about this broadcast. This is only sent to registered receivers,
2894     * not manifest receivers.
2895     */
2896    public static final String ACTION_MANAGED_PROFILE_ADDED =
2897            "android.intent.action.MANAGED_PROFILE_ADDED";
2898
2899    /**
2900     * Broadcast sent to the primary user when an associated managed profile is removed. Carries an
2901     * extra {@link #EXTRA_USER} that specifies the UserHandle of the profile that was removed.
2902     * Only applications (for example Launchers) that need to display merged content across both
2903     * primary and managed profiles need to worry about this broadcast. This is only sent to
2904     * registered receivers, not manifest receivers.
2905     */
2906    public static final String ACTION_MANAGED_PROFILE_REMOVED =
2907            "android.intent.action.MANAGED_PROFILE_REMOVED";
2908
2909    /**
2910     * Sent when the user taps on the clock widget in the system's "quick settings" area.
2911     */
2912    public static final String ACTION_QUICK_CLOCK =
2913            "android.intent.action.QUICK_CLOCK";
2914
2915    /**
2916     * Activity Action: Shows the brightness setting dialog.
2917     * @hide
2918     */
2919    public static final String ACTION_SHOW_BRIGHTNESS_DIALOG =
2920            "android.intent.action.SHOW_BRIGHTNESS_DIALOG";
2921
2922    /**
2923     * Broadcast Action:  A global button was pressed.  Includes a single
2924     * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
2925     * caused the broadcast.
2926     * @hide
2927     */
2928    public static final String ACTION_GLOBAL_BUTTON = "android.intent.action.GLOBAL_BUTTON";
2929
2930    /**
2931     * Activity Action: Allow the user to select and return one or more existing
2932     * documents. When invoked, the system will display the various
2933     * {@link DocumentsProvider} instances installed on the device, letting the
2934     * user interactively navigate through them. These documents include local
2935     * media, such as photos and video, and documents provided by installed
2936     * cloud storage providers.
2937     * <p>
2938     * Each document is represented as a {@code content://} URI backed by a
2939     * {@link DocumentsProvider}, which can be opened as a stream with
2940     * {@link ContentResolver#openFileDescriptor(Uri, String)}, or queried for
2941     * {@link android.provider.DocumentsContract.Document} metadata.
2942     * <p>
2943     * All selected documents are returned to the calling application with
2944     * persistable read and write permission grants. If you want to maintain
2945     * access to the documents across device reboots, you need to explicitly
2946     * take the persistable permissions using
2947     * {@link ContentResolver#takePersistableUriPermission(Uri, int)}.
2948     * <p>
2949     * Callers must indicate the acceptable document MIME types through
2950     * {@link #setType(String)}. For example, to select photos, use
2951     * {@code image/*}. If multiple disjoint MIME types are acceptable, define
2952     * them in {@link #EXTRA_MIME_TYPES} and {@link #setType(String)} to
2953     * {@literal *}/*.
2954     * <p>
2955     * If the caller can handle multiple returned items (the user performing
2956     * multiple selection), then you can specify {@link #EXTRA_ALLOW_MULTIPLE}
2957     * to indicate this.
2958     * <p>
2959     * Callers must include {@link #CATEGORY_OPENABLE} in the Intent to obtain
2960     * URIs that can be opened with
2961     * {@link ContentResolver#openFileDescriptor(Uri, String)}.
2962     * <p>
2963     * Output: The URI of the item that was picked, returned in
2964     * {@link #getData()}. This must be a {@code content://} URI so that any
2965     * receiver can access it. If multiple documents were selected, they are
2966     * returned in {@link #getClipData()}.
2967     *
2968     * @see DocumentsContract
2969     * @see #ACTION_OPEN_DOCUMENT_TREE
2970     * @see #ACTION_CREATE_DOCUMENT
2971     * @see #FLAG_GRANT_PERSISTABLE_URI_PERMISSION
2972     */
2973    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2974    public static final String ACTION_OPEN_DOCUMENT = "android.intent.action.OPEN_DOCUMENT";
2975
2976    /**
2977     * Activity Action: Allow the user to create a new document. When invoked,
2978     * the system will display the various {@link DocumentsProvider} instances
2979     * installed on the device, letting the user navigate through them. The
2980     * returned document may be a newly created document with no content, or it
2981     * may be an existing document with the requested MIME type.
2982     * <p>
2983     * Each document is represented as a {@code content://} URI backed by a
2984     * {@link DocumentsProvider}, which can be opened as a stream with
2985     * {@link ContentResolver#openFileDescriptor(Uri, String)}, or queried for
2986     * {@link android.provider.DocumentsContract.Document} metadata.
2987     * <p>
2988     * Callers must indicate the concrete MIME type of the document being
2989     * created by setting {@link #setType(String)}. This MIME type cannot be
2990     * changed after the document is created.
2991     * <p>
2992     * Callers can provide an initial display name through {@link #EXTRA_TITLE},
2993     * but the user may change this value before creating the file.
2994     * <p>
2995     * Callers must include {@link #CATEGORY_OPENABLE} in the Intent to obtain
2996     * URIs that can be opened with
2997     * {@link ContentResolver#openFileDescriptor(Uri, String)}.
2998     * <p>
2999     * Output: The URI of the item that was created. This must be a
3000     * {@code content://} URI so that any receiver can access it.
3001     *
3002     * @see DocumentsContract
3003     * @see #ACTION_OPEN_DOCUMENT
3004     * @see #ACTION_OPEN_DOCUMENT_TREE
3005     * @see #FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3006     */
3007    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3008    public static final String ACTION_CREATE_DOCUMENT = "android.intent.action.CREATE_DOCUMENT";
3009
3010    /**
3011     * Activity Action: Allow the user to pick a directory subtree. When
3012     * invoked, the system will display the various {@link DocumentsProvider}
3013     * instances installed on the device, letting the user navigate through
3014     * them. Apps can fully manage documents within the returned directory.
3015     * <p>
3016     * To gain access to descendant (child, grandchild, etc) documents, use
3017     * {@link DocumentsContract#buildDocumentUriUsingTree(Uri, String)} and
3018     * {@link DocumentsContract#buildChildDocumentsUriUsingTree(Uri, String)}
3019     * with the returned URI.
3020     * <p>
3021     * Output: The URI representing the selected directory tree.
3022     *
3023     * @see DocumentsContract
3024     */
3025    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3026    public static final String
3027            ACTION_OPEN_DOCUMENT_TREE = "android.intent.action.OPEN_DOCUMENT_TREE";
3028
3029    /** {@hide} */
3030    public static final String ACTION_MASTER_CLEAR = "android.intent.action.MASTER_CLEAR";
3031
3032    /**
3033     * Broadcast action: report that a settings element is being restored from backup.  The intent
3034     * contains three extras: EXTRA_SETTING_NAME is a string naming the restored setting,
3035     * EXTRA_SETTING_NEW_VALUE is the value being restored, and EXTRA_SETTING_PREVIOUS_VALUE
3036     * is the value of that settings entry prior to the restore operation.  All of these values are
3037     * represented as strings.
3038     *
3039     * <p>This broadcast is sent only for settings provider entries known to require special handling
3040     * around restore time.  These entries are found in the BROADCAST_ON_RESTORE table within
3041     * the provider's backup agent implementation.
3042     *
3043     * @see #EXTRA_SETTING_NAME
3044     * @see #EXTRA_SETTING_PREVIOUS_VALUE
3045     * @see #EXTRA_SETTING_NEW_VALUE
3046     * {@hide}
3047     */
3048    public static final String ACTION_SETTING_RESTORED = "android.os.action.SETTING_RESTORED";
3049
3050    /** {@hide} */
3051    public static final String EXTRA_SETTING_NAME = "setting_name";
3052    /** {@hide} */
3053    public static final String EXTRA_SETTING_PREVIOUS_VALUE = "previous_value";
3054    /** {@hide} */
3055    public static final String EXTRA_SETTING_NEW_VALUE = "new_value";
3056
3057    /**
3058     * Activity Action: Process a piece of text.
3059     * <p>Input: {@link #EXTRA_PROCESS_TEXT} contains the text to be processed.
3060     * {@link #EXTRA_PROCESS_TEXT_READONLY} states if the resulting text will be read-only.</p>
3061     * <p>Output: {@link #EXTRA_PROCESS_TEXT} contains the processed text.</p>
3062     */
3063    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3064    public static final String ACTION_PROCESS_TEXT = "android.intent.action.PROCESS_TEXT";
3065    /**
3066     * The name of the extra used to define the text to be processed, as a
3067     * CharSequence. Note that this may be a styled CharSequence, so you must use
3068     * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to retrieve it.
3069     */
3070    public static final String EXTRA_PROCESS_TEXT = "android.intent.extra.PROCESS_TEXT";
3071    /**
3072     * The name of the boolean extra used to define if the processed text will be used as read-only.
3073     */
3074    public static final String EXTRA_PROCESS_TEXT_READONLY =
3075            "android.intent.extra.PROCESS_TEXT_READONLY";
3076
3077    /**
3078     * Broadcast action: reports when a new thermal event has been reached. When the device
3079     * is reaching its maximum temperatue, the thermal level reported
3080     * {@hide}
3081     */
3082    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3083    public static final String ACTION_THERMAL_EVENT = "android.intent.action.THERMAL_EVENT";
3084
3085    /** {@hide} */
3086    public static final String EXTRA_THERMAL_STATE = "android.intent.extra.THERMAL_STATE";
3087
3088    /**
3089     * Thermal state when the device is normal. This state is sent in the
3090     * {@link #ACTION_THERMAL_EVENT} broadcast as {@link #EXTRA_THERMAL_STATE}.
3091     * {@hide}
3092     */
3093    public static final int EXTRA_THERMAL_STATE_NORMAL = 0;
3094
3095    /**
3096     * Thermal state where the device is approaching its maximum threshold. This state is sent in
3097     * the {@link #ACTION_THERMAL_EVENT} broadcast as {@link #EXTRA_THERMAL_STATE}.
3098     * {@hide}
3099     */
3100    public static final int EXTRA_THERMAL_STATE_WARNING = 1;
3101
3102    /**
3103     * Thermal state where the device has reached its maximum threshold. This state is sent in the
3104     * {@link #ACTION_THERMAL_EVENT} broadcast as {@link #EXTRA_THERMAL_STATE}.
3105     * {@hide}
3106     */
3107    public static final int EXTRA_THERMAL_STATE_EXCEEDED = 2;
3108
3109
3110    // ---------------------------------------------------------------------
3111    // ---------------------------------------------------------------------
3112    // Standard intent categories (see addCategory()).
3113
3114    /**
3115     * Set if the activity should be an option for the default action
3116     * (center press) to perform on a piece of data.  Setting this will
3117     * hide from the user any activities without it set when performing an
3118     * action on some data.  Note that this is normally -not- set in the
3119     * Intent when initiating an action -- it is for use in intent filters
3120     * specified in packages.
3121     */
3122    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3123    public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
3124    /**
3125     * Activities that can be safely invoked from a browser must support this
3126     * category.  For example, if the user is viewing a web page or an e-mail
3127     * and clicks on a link in the text, the Intent generated execute that
3128     * link will require the BROWSABLE category, so that only activities
3129     * supporting this category will be considered as possible actions.  By
3130     * supporting this category, you are promising that there is nothing
3131     * damaging (without user intervention) that can happen by invoking any
3132     * matching Intent.
3133     */
3134    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3135    public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
3136    /**
3137     * Categories for activities that can participate in voice interaction.
3138     * An activity that supports this category must be prepared to run with
3139     * no UI shown at all (though in some case it may have a UI shown), and
3140     * rely on {@link android.app.VoiceInteractor} to interact with the user.
3141     */
3142    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3143    public static final String CATEGORY_VOICE = "android.intent.category.VOICE";
3144    /**
3145     * Set if the activity should be considered as an alternative action to
3146     * the data the user is currently viewing.  See also
3147     * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
3148     * applies to the selection in a list of items.
3149     *
3150     * <p>Supporting this category means that you would like your activity to be
3151     * displayed in the set of alternative things the user can do, usually as
3152     * part of the current activity's options menu.  You will usually want to
3153     * include a specific label in the &lt;intent-filter&gt; of this action
3154     * describing to the user what it does.
3155     *
3156     * <p>The action of IntentFilter with this category is important in that it
3157     * describes the specific action the target will perform.  This generally
3158     * should not be a generic action (such as {@link #ACTION_VIEW}, but rather
3159     * a specific name such as "com.android.camera.action.CROP.  Only one
3160     * alternative of any particular action will be shown to the user, so using
3161     * a specific action like this makes sure that your alternative will be
3162     * displayed while also allowing other applications to provide their own
3163     * overrides of that particular action.
3164     */
3165    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3166    public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
3167    /**
3168     * Set if the activity should be considered as an alternative selection
3169     * action to the data the user has currently selected.  This is like
3170     * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list
3171     * of items from which the user can select, giving them alternatives to the
3172     * default action that will be performed on it.
3173     */
3174    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3175    public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
3176    /**
3177     * Intended to be used as a tab inside of a containing TabActivity.
3178     */
3179    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3180    public static final String CATEGORY_TAB = "android.intent.category.TAB";
3181    /**
3182     * Should be displayed in the top-level launcher.
3183     */
3184    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3185    public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
3186    /**
3187     * Indicates an activity optimized for Leanback mode, and that should
3188     * be displayed in the Leanback launcher.
3189     */
3190    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3191    public static final String CATEGORY_LEANBACK_LAUNCHER = "android.intent.category.LEANBACK_LAUNCHER";
3192    /**
3193     * Indicates a Leanback settings activity to be displayed in the Leanback launcher.
3194     * @hide
3195     */
3196    @SystemApi
3197    public static final String CATEGORY_LEANBACK_SETTINGS = "android.intent.category.LEANBACK_SETTINGS";
3198    /**
3199     * Provides information about the package it is in; typically used if
3200     * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
3201     * a front-door to the user without having to be shown in the all apps list.
3202     */
3203    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3204    public static final String CATEGORY_INFO = "android.intent.category.INFO";
3205    /**
3206     * This is the home activity, that is the first activity that is displayed
3207     * when the device boots.
3208     */
3209    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3210    public static final String CATEGORY_HOME = "android.intent.category.HOME";
3211    /**
3212     * This is the home activity that is displayed when the device is finished setting up and ready
3213     * for use.
3214     * @hide
3215     */
3216    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3217    public static final String CATEGORY_HOME_MAIN = "android.intent.category.HOME_MAIN";
3218    /**
3219     * This is the setup wizard activity, that is the first activity that is displayed
3220     * when the user sets up the device for the first time.
3221     * @hide
3222     */
3223    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3224    public static final String CATEGORY_SETUP_WIZARD = "android.intent.category.SETUP_WIZARD";
3225    /**
3226     * This activity is a preference panel.
3227     */
3228    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3229    public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
3230    /**
3231     * This activity is a development preference panel.
3232     */
3233    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3234    public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
3235    /**
3236     * Capable of running inside a parent activity container.
3237     */
3238    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3239    public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
3240    /**
3241     * This activity allows the user to browse and download new applications.
3242     */
3243    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3244    public static final String CATEGORY_APP_MARKET = "android.intent.category.APP_MARKET";
3245    /**
3246     * This activity may be exercised by the monkey or other automated test tools.
3247     */
3248    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3249    public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
3250    /**
3251     * To be used as a test (not part of the normal user experience).
3252     */
3253    public static final String CATEGORY_TEST = "android.intent.category.TEST";
3254    /**
3255     * To be used as a unit test (run through the Test Harness).
3256     */
3257    public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
3258    /**
3259     * To be used as a sample code example (not part of the normal user
3260     * experience).
3261     */
3262    public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
3263
3264    /**
3265     * Used to indicate that an intent only wants URIs that can be opened with
3266     * {@link ContentResolver#openFileDescriptor(Uri, String)}. Openable URIs
3267     * must support at least the columns defined in {@link OpenableColumns} when
3268     * queried.
3269     *
3270     * @see #ACTION_GET_CONTENT
3271     * @see #ACTION_OPEN_DOCUMENT
3272     * @see #ACTION_CREATE_DOCUMENT
3273     */
3274    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3275    public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
3276
3277    /**
3278     * To be used as code under test for framework instrumentation tests.
3279     */
3280    public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
3281            "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
3282    /**
3283     * An activity to run when device is inserted into a car dock.
3284     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
3285     * information, see {@link android.app.UiModeManager}.
3286     */
3287    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3288    public static final String CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
3289    /**
3290     * An activity to run when device is inserted into a car dock.
3291     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
3292     * information, see {@link android.app.UiModeManager}.
3293     */
3294    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3295    public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
3296    /**
3297     * An activity to run when device is inserted into a analog (low end) dock.
3298     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
3299     * information, see {@link android.app.UiModeManager}.
3300     */
3301    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3302    public static final String CATEGORY_LE_DESK_DOCK = "android.intent.category.LE_DESK_DOCK";
3303
3304    /**
3305     * An activity to run when device is inserted into a digital (high end) dock.
3306     * Used with {@link #ACTION_MAIN} to launch an activity.  For more
3307     * information, see {@link android.app.UiModeManager}.
3308     */
3309    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3310    public static final String CATEGORY_HE_DESK_DOCK = "android.intent.category.HE_DESK_DOCK";
3311
3312    /**
3313     * Used to indicate that the activity can be used in a car environment.
3314     */
3315    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3316    public static final String CATEGORY_CAR_MODE = "android.intent.category.CAR_MODE";
3317
3318    // ---------------------------------------------------------------------
3319    // ---------------------------------------------------------------------
3320    // Application launch intent categories (see addCategory()).
3321
3322    /**
3323     * Used with {@link #ACTION_MAIN} to launch the browser application.
3324     * The activity should be able to browse the Internet.
3325     * <p>NOTE: This should not be used as the primary key of an Intent,
3326     * since it will not result in the app launching with the correct
3327     * action and category.  Instead, use this with
3328     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3329     * Intent with this category in the selector.</p>
3330     */
3331    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3332    public static final String CATEGORY_APP_BROWSER = "android.intent.category.APP_BROWSER";
3333
3334    /**
3335     * Used with {@link #ACTION_MAIN} to launch the calculator application.
3336     * The activity should be able to perform standard arithmetic operations.
3337     * <p>NOTE: This should not be used as the primary key of an Intent,
3338     * since it will not result in the app launching with the correct
3339     * action and category.  Instead, use this with
3340     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3341     * Intent with this category in the selector.</p>
3342     */
3343    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3344    public static final String CATEGORY_APP_CALCULATOR = "android.intent.category.APP_CALCULATOR";
3345
3346    /**
3347     * Used with {@link #ACTION_MAIN} to launch the calendar application.
3348     * The activity should be able to view and manipulate calendar entries.
3349     * <p>NOTE: This should not be used as the primary key of an Intent,
3350     * since it will not result in the app launching with the correct
3351     * action and category.  Instead, use this with
3352     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3353     * Intent with this category in the selector.</p>
3354     */
3355    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3356    public static final String CATEGORY_APP_CALENDAR = "android.intent.category.APP_CALENDAR";
3357
3358    /**
3359     * Used with {@link #ACTION_MAIN} to launch the contacts application.
3360     * The activity should be able to view and manipulate address book entries.
3361     * <p>NOTE: This should not be used as the primary key of an Intent,
3362     * since it will not result in the app launching with the correct
3363     * action and category.  Instead, use this with
3364     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3365     * Intent with this category in the selector.</p>
3366     */
3367    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3368    public static final String CATEGORY_APP_CONTACTS = "android.intent.category.APP_CONTACTS";
3369
3370    /**
3371     * Used with {@link #ACTION_MAIN} to launch the email application.
3372     * The activity should be able to send and receive email.
3373     * <p>NOTE: This should not be used as the primary key of an Intent,
3374     * since it will not result in the app launching with the correct
3375     * action and category.  Instead, use this with
3376     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3377     * Intent with this category in the selector.</p>
3378     */
3379    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3380    public static final String CATEGORY_APP_EMAIL = "android.intent.category.APP_EMAIL";
3381
3382    /**
3383     * Used with {@link #ACTION_MAIN} to launch the gallery application.
3384     * The activity should be able to view and manipulate image and video files
3385     * stored on the device.
3386     * <p>NOTE: This should not be used as the primary key of an Intent,
3387     * since it will not result in the app launching with the correct
3388     * action and category.  Instead, use this with
3389     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3390     * Intent with this category in the selector.</p>
3391     */
3392    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3393    public static final String CATEGORY_APP_GALLERY = "android.intent.category.APP_GALLERY";
3394
3395    /**
3396     * Used with {@link #ACTION_MAIN} to launch the maps application.
3397     * The activity should be able to show the user's current location and surroundings.
3398     * <p>NOTE: This should not be used as the primary key of an Intent,
3399     * since it will not result in the app launching with the correct
3400     * action and category.  Instead, use this with
3401     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3402     * Intent with this category in the selector.</p>
3403     */
3404    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3405    public static final String CATEGORY_APP_MAPS = "android.intent.category.APP_MAPS";
3406
3407    /**
3408     * Used with {@link #ACTION_MAIN} to launch the messaging application.
3409     * The activity should be able to send and receive text messages.
3410     * <p>NOTE: This should not be used as the primary key of an Intent,
3411     * since it will not result in the app launching with the correct
3412     * action and category.  Instead, use this with
3413     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3414     * Intent with this category in the selector.</p>
3415     */
3416    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3417    public static final String CATEGORY_APP_MESSAGING = "android.intent.category.APP_MESSAGING";
3418
3419    /**
3420     * Used with {@link #ACTION_MAIN} to launch the music application.
3421     * The activity should be able to play, browse, or manipulate music files
3422     * stored on the device.
3423     * <p>NOTE: This should not be used as the primary key of an Intent,
3424     * since it will not result in the app launching with the correct
3425     * action and category.  Instead, use this with
3426     * {@link #makeMainSelectorActivity(String, String)} to generate a main
3427     * Intent with this category in the selector.</p>
3428     */
3429    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
3430    public static final String CATEGORY_APP_MUSIC = "android.intent.category.APP_MUSIC";
3431
3432    // ---------------------------------------------------------------------
3433    // ---------------------------------------------------------------------
3434    // Standard extra data keys.
3435
3436    /**
3437     * The initial data to place in a newly created record.  Use with
3438     * {@link #ACTION_INSERT}.  The data here is a Map containing the same
3439     * fields as would be given to the underlying ContentProvider.insert()
3440     * call.
3441     */
3442    public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
3443
3444    /**
3445     * A constant CharSequence that is associated with the Intent, used with
3446     * {@link #ACTION_SEND} to supply the literal data to be sent.  Note that
3447     * this may be a styled CharSequence, so you must use
3448     * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to
3449     * retrieve it.
3450     */
3451    public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
3452
3453    /**
3454     * A constant String that is associated with the Intent, used with
3455     * {@link #ACTION_SEND} to supply an alternative to {@link #EXTRA_TEXT}
3456     * as HTML formatted text.  Note that you <em>must</em> also supply
3457     * {@link #EXTRA_TEXT}.
3458     */
3459    public static final String EXTRA_HTML_TEXT = "android.intent.extra.HTML_TEXT";
3460
3461    /**
3462     * A content: URI holding a stream of data associated with the Intent,
3463     * used with {@link #ACTION_SEND} to supply the data being sent.
3464     */
3465    public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
3466
3467    /**
3468     * A String[] holding e-mail addresses that should be delivered to.
3469     */
3470    public static final String EXTRA_EMAIL       = "android.intent.extra.EMAIL";
3471
3472    /**
3473     * A String[] holding e-mail addresses that should be carbon copied.
3474     */
3475    public static final String EXTRA_CC       = "android.intent.extra.CC";
3476
3477    /**
3478     * A String[] holding e-mail addresses that should be blind carbon copied.
3479     */
3480    public static final String EXTRA_BCC      = "android.intent.extra.BCC";
3481
3482    /**
3483     * A constant string holding the desired subject line of a message.
3484     */
3485    public static final String EXTRA_SUBJECT  = "android.intent.extra.SUBJECT";
3486
3487    /**
3488     * An Intent describing the choices you would like shown with
3489     * {@link #ACTION_PICK_ACTIVITY} or {@link #ACTION_CHOOSER}.
3490     */
3491    public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
3492
3493    /**
3494     * An int representing the user id to be used.
3495     *
3496     * @hide
3497     */
3498    public static final String EXTRA_USER_ID = "android.intent.extra.USER_ID";
3499
3500    /**
3501     * An Intent[] describing additional, alternate choices you would like shown with
3502     * {@link #ACTION_CHOOSER}.
3503     *
3504     * <p>An app may be capable of providing several different payload types to complete a
3505     * user's intended action. For example, an app invoking {@link #ACTION_SEND} to share photos
3506     * with another app may use EXTRA_ALTERNATE_INTENTS to have the chooser transparently offer
3507     * several different supported sending mechanisms for sharing, such as the actual "image/*"
3508     * photo data or a hosted link where the photos can be viewed.</p>
3509     *
3510     * <p>The intent present in {@link #EXTRA_INTENT} will be treated as the
3511     * first/primary/preferred intent in the set. Additional intents specified in
3512     * this extra are ordered; by default intents that appear earlier in the array will be
3513     * preferred over intents that appear later in the array as matches for the same
3514     * target component. To alter this preference, a calling app may also supply
3515     * {@link #EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER}.</p>
3516     */
3517    public static final String EXTRA_ALTERNATE_INTENTS = "android.intent.extra.ALTERNATE_INTENTS";
3518
3519    /**
3520     * An {@link IntentSender} for an Activity that will be invoked when the user makes a selection
3521     * from the chooser activity presented by {@link #ACTION_CHOOSER}.
3522     *
3523     * <p>An app preparing an action for another app to complete may wish to allow the user to
3524     * disambiguate between several options for completing the action based on the chosen target
3525     * or otherwise refine the action before it is invoked.
3526     * </p>
3527     *
3528     * <p>When sent, this IntentSender may be filled in with the following extras:</p>
3529     * <ul>
3530     *     <li>{@link #EXTRA_INTENT} The first intent that matched the user's chosen target</li>
3531     *     <li>{@link #EXTRA_ALTERNATE_INTENTS} Any additional intents that also matched the user's
3532     *     chosen target beyond the first</li>
3533     *     <li>{@link #EXTRA_RESULT_RECEIVER} A {@link ResultReceiver} that the refinement activity
3534     *     should fill in and send once the disambiguation is complete</li>
3535     * </ul>
3536     */
3537    public static final String EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER
3538            = "android.intent.extra.CHOOSER_REFINEMENT_INTENT_SENDER";
3539
3540    /**
3541     * A {@link ResultReceiver} used to return data back to the sender.
3542     *
3543     * <p>Used to complete an app-specific
3544     * {@link #EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER refinement} for {@link #ACTION_CHOOSER}.</p>
3545     *
3546     * <p>If {@link #EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER} is present in the intent
3547     * used to start a {@link #ACTION_CHOOSER} activity this extra will be
3548     * {@link #fillIn(Intent, int) filled in} to that {@link IntentSender} and sent
3549     * when the user selects a target component from the chooser. It is up to the recipient
3550     * to send a result to this ResultReceiver to signal that disambiguation is complete
3551     * and that the chooser should invoke the user's choice.</p>
3552     *
3553     * <p>The disambiguator should provide a Bundle to the ResultReceiver with an intent
3554     * assigned to the key {@link #EXTRA_INTENT}. This supplied intent will be used by the chooser
3555     * to match and fill in the final Intent or ChooserTarget before starting it.
3556     * The supplied intent must {@link #filterEquals(Intent) match} one of the intents from
3557     * {@link #EXTRA_INTENT} or {@link #EXTRA_ALTERNATE_INTENTS} passed to
3558     * {@link #EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER} to be accepted.</p>
3559     *
3560     * <p>The result code passed to the ResultReceiver should be
3561     * {@link android.app.Activity#RESULT_OK} if the refinement succeeded and the supplied intent's
3562     * target in the chooser should be started, or {@link android.app.Activity#RESULT_CANCELED} if
3563     * the chooser should finish without starting a target.</p>
3564     */
3565    public static final String EXTRA_RESULT_RECEIVER
3566            = "android.intent.extra.RESULT_RECEIVER";
3567
3568    /**
3569     * A CharSequence dialog title to provide to the user when used with a
3570     * {@link #ACTION_CHOOSER}.
3571     */
3572    public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
3573
3574    /**
3575     * A Parcelable[] of {@link Intent} or
3576     * {@link android.content.pm.LabeledIntent} objects as set with
3577     * {@link #putExtra(String, Parcelable[])} of additional activities to place
3578     * a the front of the list of choices, when shown to the user with a
3579     * {@link #ACTION_CHOOSER}.
3580     */
3581    public static final String EXTRA_INITIAL_INTENTS = "android.intent.extra.INITIAL_INTENTS";
3582
3583    /**
3584     * A Bundle forming a mapping of potential target package names to different extras Bundles
3585     * to add to the default intent extras in {@link #EXTRA_INTENT} when used with
3586     * {@link #ACTION_CHOOSER}. Each key should be a package name. The package need not
3587     * be currently installed on the device.
3588     *
3589     * <p>An application may choose to provide alternate extras for the case where a user
3590     * selects an activity from a predetermined set of target packages. If the activity
3591     * the user selects from the chooser belongs to a package with its package name as
3592     * a key in this bundle, the corresponding extras for that package will be merged with
3593     * the extras already present in the intent at {@link #EXTRA_INTENT}. If a replacement
3594     * extra has the same key as an extra already present in the intent it will overwrite
3595     * the extra from the intent.</p>
3596     *
3597     * <p><em>Examples:</em>
3598     * <ul>
3599     *     <li>An application may offer different {@link #EXTRA_TEXT} to an application
3600     *     when sharing with it via {@link #ACTION_SEND}, augmenting a link with additional query
3601     *     parameters for that target.</li>
3602     *     <li>An application may offer additional metadata for known targets of a given intent
3603     *     to pass along information only relevant to that target such as account or content
3604     *     identifiers already known to that application.</li>
3605     * </ul></p>
3606     */
3607    public static final String EXTRA_REPLACEMENT_EXTRAS =
3608            "android.intent.extra.REPLACEMENT_EXTRAS";
3609
3610    /**
3611     * An {@link IntentSender} that will be notified if a user successfully chooses a target
3612     * component to handle an action in an {@link #ACTION_CHOOSER} activity. The IntentSender
3613     * will have the extra {@link #EXTRA_CHOSEN_COMPONENT} appended to it containing the
3614     * {@link ComponentName} of the chosen component.
3615     *
3616     * <p>In some situations this callback may never come, for example if the user abandons
3617     * the chooser, switches to another task or any number of other reasons. Apps should not
3618     * be written assuming that this callback will always occur.</p>
3619     */
3620    public static final String EXTRA_CHOSEN_COMPONENT_INTENT_SENDER =
3621            "android.intent.extra.CHOSEN_COMPONENT_INTENT_SENDER";
3622
3623    /**
3624     * The {@link ComponentName} chosen by the user to complete an action.
3625     *
3626     * @see #EXTRA_CHOSEN_COMPONENT_INTENT_SENDER
3627     */
3628    public static final String EXTRA_CHOSEN_COMPONENT = "android.intent.extra.CHOSEN_COMPONENT";
3629
3630    /**
3631     * A {@link android.view.KeyEvent} object containing the event that
3632     * triggered the creation of the Intent it is in.
3633     */
3634    public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
3635
3636    /**
3637     * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to request confirmation from the user
3638     * before shutting down.
3639     *
3640     * {@hide}
3641     */
3642    public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";
3643
3644    /**
3645     * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to indicate that the shutdown is
3646     * requested by the user.
3647     *
3648     * {@hide}
3649     */
3650    public static final String EXTRA_USER_REQUESTED_SHUTDOWN =
3651            "android.intent.extra.USER_REQUESTED_SHUTDOWN";
3652
3653    /**
3654     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
3655     * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
3656     * of restarting the application.
3657     */
3658    public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
3659
3660    /**
3661     * A String holding the phone number originally entered in
3662     * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual
3663     * number to call in a {@link android.content.Intent#ACTION_CALL}.
3664     */
3665    public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
3666
3667    /**
3668     * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED}
3669     * intents to supply the uid the package had been assigned.  Also an optional
3670     * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
3671     * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same
3672     * purpose.
3673     */
3674    public static final String EXTRA_UID = "android.intent.extra.UID";
3675
3676    /**
3677     * @hide String array of package names.
3678     */
3679    @SystemApi
3680    public static final String EXTRA_PACKAGES = "android.intent.extra.PACKAGES";
3681
3682    /**
3683     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
3684     * intents to indicate whether this represents a full uninstall (removing
3685     * both the code and its data) or a partial uninstall (leaving its data,
3686     * implying that this is an update).
3687     */
3688    public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
3689
3690    /**
3691     * @hide
3692     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
3693     * intents to indicate that at this point the package has been removed for
3694     * all users on the device.
3695     */
3696    public static final String EXTRA_REMOVED_FOR_ALL_USERS
3697            = "android.intent.extra.REMOVED_FOR_ALL_USERS";
3698
3699    /**
3700     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
3701     * intents to indicate that this is a replacement of the package, so this
3702     * broadcast will immediately be followed by an add broadcast for a
3703     * different version of the same package.
3704     */
3705    public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
3706
3707    /**
3708     * Used as an int extra field in {@link android.app.AlarmManager} intents
3709     * to tell the application being invoked how many pending alarms are being
3710     * delievered with the intent.  For one-shot alarms this will always be 1.
3711     * For recurring alarms, this might be greater than 1 if the device was
3712     * asleep or powered off at the time an earlier alarm would have been
3713     * delivered.
3714     */
3715    public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
3716
3717    /**
3718     * Used as an int extra field in {@link android.content.Intent#ACTION_DOCK_EVENT}
3719     * intents to request the dock state.  Possible values are
3720     * {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
3721     * {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
3722     * {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}, or
3723     * {@link android.content.Intent#EXTRA_DOCK_STATE_LE_DESK}, or
3724     * {@link android.content.Intent#EXTRA_DOCK_STATE_HE_DESK}.
3725     */
3726    public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
3727
3728    /**
3729     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
3730     * to represent that the phone is not in any dock.
3731     */
3732    public static final int EXTRA_DOCK_STATE_UNDOCKED = 0;
3733
3734    /**
3735     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
3736     * to represent that the phone is in a desk dock.
3737     */
3738    public static final int EXTRA_DOCK_STATE_DESK = 1;
3739
3740    /**
3741     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
3742     * to represent that the phone is in a car dock.
3743     */
3744    public static final int EXTRA_DOCK_STATE_CAR = 2;
3745
3746    /**
3747     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
3748     * to represent that the phone is in a analog (low end) dock.
3749     */
3750    public static final int EXTRA_DOCK_STATE_LE_DESK = 3;
3751
3752    /**
3753     * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
3754     * to represent that the phone is in a digital (high end) dock.
3755     */
3756    public static final int EXTRA_DOCK_STATE_HE_DESK = 4;
3757
3758    /**
3759     * Boolean that can be supplied as meta-data with a dock activity, to
3760     * indicate that the dock should take over the home key when it is active.
3761     */
3762    public static final String METADATA_DOCK_HOME = "android.dock_home";
3763
3764    /**
3765     * Used as a parcelable extra field in {@link #ACTION_APP_ERROR}, containing
3766     * the bug report.
3767     */
3768    public static final String EXTRA_BUG_REPORT = "android.intent.extra.BUG_REPORT";
3769
3770    /**
3771     * Used in the extra field in the remote intent. It's astring token passed with the
3772     * remote intent.
3773     */
3774    public static final String EXTRA_REMOTE_INTENT_TOKEN =
3775            "android.intent.extra.remote_intent_token";
3776
3777    /**
3778     * @deprecated See {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST}; this field
3779     * will contain only the first name in the list.
3780     */
3781    @Deprecated public static final String EXTRA_CHANGED_COMPONENT_NAME =
3782            "android.intent.extra.changed_component_name";
3783
3784    /**
3785     * This field is part of {@link android.content.Intent#ACTION_PACKAGE_CHANGED},
3786     * and contains a string array of all of the components that have changed.  If
3787     * the state of the overall package has changed, then it will contain an entry
3788     * with the package name itself.
3789     */
3790    public static final String EXTRA_CHANGED_COMPONENT_NAME_LIST =
3791            "android.intent.extra.changed_component_name_list";
3792
3793    /**
3794     * This field is part of
3795     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_AVAILABLE},
3796     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE}
3797     * and contains a string array of all of the components that have changed.
3798     */
3799    public static final String EXTRA_CHANGED_PACKAGE_LIST =
3800            "android.intent.extra.changed_package_list";
3801
3802    /**
3803     * This field is part of
3804     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_AVAILABLE},
3805     * {@link android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE}
3806     * and contains an integer array of uids of all of the components
3807     * that have changed.
3808     */
3809    public static final String EXTRA_CHANGED_UID_LIST =
3810            "android.intent.extra.changed_uid_list";
3811
3812    /**
3813     * @hide
3814     * Magic extra system code can use when binding, to give a label for
3815     * who it is that has bound to a service.  This is an integer giving
3816     * a framework string resource that can be displayed to the user.
3817     */
3818    public static final String EXTRA_CLIENT_LABEL =
3819            "android.intent.extra.client_label";
3820
3821    /**
3822     * @hide
3823     * Magic extra system code can use when binding, to give a PendingIntent object
3824     * that can be launched for the user to disable the system's use of this
3825     * service.
3826     */
3827    public static final String EXTRA_CLIENT_INTENT =
3828            "android.intent.extra.client_intent";
3829
3830    /**
3831     * Extra used to indicate that an intent should only return data that is on
3832     * the local device. This is a boolean extra; the default is false. If true,
3833     * an implementation should only allow the user to select data that is
3834     * already on the device, not requiring it be downloaded from a remote
3835     * service when opened.
3836     *
3837     * @see #ACTION_GET_CONTENT
3838     * @see #ACTION_OPEN_DOCUMENT
3839     * @see #ACTION_OPEN_DOCUMENT_TREE
3840     * @see #ACTION_CREATE_DOCUMENT
3841     */
3842    public static final String EXTRA_LOCAL_ONLY =
3843            "android.intent.extra.LOCAL_ONLY";
3844
3845    /**
3846     * Extra used to indicate that an intent can allow the user to select and
3847     * return multiple items. This is a boolean extra; the default is false. If
3848     * true, an implementation is allowed to present the user with a UI where
3849     * they can pick multiple items that are all returned to the caller. When
3850     * this happens, they should be returned as the {@link #getClipData()} part
3851     * of the result Intent.
3852     *
3853     * @see #ACTION_GET_CONTENT
3854     * @see #ACTION_OPEN_DOCUMENT
3855     */
3856    public static final String EXTRA_ALLOW_MULTIPLE =
3857            "android.intent.extra.ALLOW_MULTIPLE";
3858
3859    /**
3860     * The integer userHandle carried with broadcast intents related to addition, removal and
3861     * switching of users and managed profiles - {@link #ACTION_USER_ADDED},
3862     * {@link #ACTION_USER_REMOVED} and {@link #ACTION_USER_SWITCHED}.
3863     *
3864     * @hide
3865     */
3866    public static final String EXTRA_USER_HANDLE =
3867            "android.intent.extra.user_handle";
3868
3869    /**
3870     * The UserHandle carried with broadcasts intents related to addition and removal of managed
3871     * profiles - {@link #ACTION_MANAGED_PROFILE_ADDED} and {@link #ACTION_MANAGED_PROFILE_REMOVED}.
3872     */
3873    public static final String EXTRA_USER =
3874            "android.intent.extra.USER";
3875
3876    /**
3877     * Extra used in the response from a BroadcastReceiver that handles
3878     * {@link #ACTION_GET_RESTRICTION_ENTRIES}. The type of the extra is
3879     * <code>ArrayList&lt;RestrictionEntry&gt;</code>.
3880     */
3881    public static final String EXTRA_RESTRICTIONS_LIST = "android.intent.extra.restrictions_list";
3882
3883    /**
3884     * Extra sent in the intent to the BroadcastReceiver that handles
3885     * {@link #ACTION_GET_RESTRICTION_ENTRIES}. The type of the extra is a Bundle containing
3886     * the restrictions as key/value pairs.
3887     */
3888    public static final String EXTRA_RESTRICTIONS_BUNDLE =
3889            "android.intent.extra.restrictions_bundle";
3890
3891    /**
3892     * Extra used in the response from a BroadcastReceiver that handles
3893     * {@link #ACTION_GET_RESTRICTION_ENTRIES}.
3894     */
3895    public static final String EXTRA_RESTRICTIONS_INTENT =
3896            "android.intent.extra.restrictions_intent";
3897
3898    /**
3899     * Extra used to communicate a set of acceptable MIME types. The type of the
3900     * extra is {@code String[]}. Values may be a combination of concrete MIME
3901     * types (such as "image/png") and/or partial MIME types (such as
3902     * "audio/*").
3903     *
3904     * @see #ACTION_GET_CONTENT
3905     * @see #ACTION_OPEN_DOCUMENT
3906     */
3907    public static final String EXTRA_MIME_TYPES = "android.intent.extra.MIME_TYPES";
3908
3909    /**
3910     * Optional extra for {@link #ACTION_SHUTDOWN} that allows the sender to qualify that
3911     * this shutdown is only for the user space of the system, not a complete shutdown.
3912     * When this is true, hardware devices can use this information to determine that
3913     * they shouldn't do a complete shutdown of their device since this is not a
3914     * complete shutdown down to the kernel, but only user space restarting.
3915     * The default if not supplied is false.
3916     */
3917    public static final String EXTRA_SHUTDOWN_USERSPACE_ONLY
3918            = "android.intent.extra.SHUTDOWN_USERSPACE_ONLY";
3919
3920    /**
3921     * Optional boolean extra for {@link #ACTION_TIME_CHANGED} that indicates the
3922     * user has set their time format preferences to the 24 hour format.
3923     *
3924     * @hide for internal use only.
3925     */
3926    public static final String EXTRA_TIME_PREF_24_HOUR_FORMAT =
3927            "android.intent.extra.TIME_PREF_24_HOUR_FORMAT";
3928
3929    /** {@hide} */
3930    public static final String EXTRA_REASON = "android.intent.extra.REASON";
3931
3932    /** {@hide} */
3933    public static final String EXTRA_WIPE_EXTERNAL_STORAGE = "android.intent.extra.WIPE_EXTERNAL_STORAGE";
3934
3935    /**
3936     * Optional {@link android.app.PendingIntent} extra used to deliver the result of the SIM
3937     * activation request.
3938     * TODO: Add information about the structure and response data used with the pending intent.
3939     * @hide
3940     */
3941    public static final String EXTRA_SIM_ACTIVATION_RESPONSE =
3942            "android.intent.extra.SIM_ACTIVATION_RESPONSE";
3943
3944    /** {@hide} */
3945    public static final String EXTRA_INDEX = "android.intent.extra.INDEX";
3946
3947    // ---------------------------------------------------------------------
3948    // ---------------------------------------------------------------------
3949    // Intent flags (see mFlags variable).
3950
3951    /** @hide */
3952    @IntDef(flag = true, value = {
3953            FLAG_GRANT_READ_URI_PERMISSION, FLAG_GRANT_WRITE_URI_PERMISSION,
3954            FLAG_GRANT_PERSISTABLE_URI_PERMISSION, FLAG_GRANT_PREFIX_URI_PERMISSION })
3955    @Retention(RetentionPolicy.SOURCE)
3956    public @interface GrantUriMode {}
3957
3958    /** @hide */
3959    @IntDef(flag = true, value = {
3960            FLAG_GRANT_READ_URI_PERMISSION, FLAG_GRANT_WRITE_URI_PERMISSION })
3961    @Retention(RetentionPolicy.SOURCE)
3962    public @interface AccessUriMode {}
3963
3964    /**
3965     * Test if given mode flags specify an access mode, which must be at least
3966     * read and/or write.
3967     *
3968     * @hide
3969     */
3970    public static boolean isAccessUriMode(int modeFlags) {
3971        return (modeFlags & (Intent.FLAG_GRANT_READ_URI_PERMISSION
3972                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)) != 0;
3973    }
3974
3975    /**
3976     * If set, the recipient of this Intent will be granted permission to
3977     * perform read operations on the URI in the Intent's data and any URIs
3978     * specified in its ClipData.  When applying to an Intent's ClipData,
3979     * all URIs as well as recursive traversals through data or other ClipData
3980     * in Intent items will be granted; only the grant flags of the top-level
3981     * Intent are used.
3982     */
3983    public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
3984    /**
3985     * If set, the recipient of this Intent will be granted permission to
3986     * perform write operations on the URI in the Intent's data and any URIs
3987     * specified in its ClipData.  When applying to an Intent's ClipData,
3988     * all URIs as well as recursive traversals through data or other ClipData
3989     * in Intent items will be granted; only the grant flags of the top-level
3990     * Intent are used.
3991     */
3992    public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
3993    /**
3994     * Can be set by the caller to indicate that this Intent is coming from
3995     * a background operation, not from direct user interaction.
3996     */
3997    public static final int FLAG_FROM_BACKGROUND = 0x00000004;
3998    /**
3999     * A flag you can enable for debugging: when set, log messages will be
4000     * printed during the resolution of this intent to show you what has
4001     * been found to create the final resolved list.
4002     */
4003    public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
4004    /**
4005     * If set, this intent will not match any components in packages that
4006     * are currently stopped.  If this is not set, then the default behavior
4007     * is to include such applications in the result.
4008     */
4009    public static final int FLAG_EXCLUDE_STOPPED_PACKAGES = 0x00000010;
4010    /**
4011     * If set, this intent will always match any components in packages that
4012     * are currently stopped.  This is the default behavior when
4013     * {@link #FLAG_EXCLUDE_STOPPED_PACKAGES} is not set.  If both of these
4014     * flags are set, this one wins (it allows overriding of exclude for
4015     * places where the framework may automatically set the exclude flag).
4016     */
4017    public static final int FLAG_INCLUDE_STOPPED_PACKAGES = 0x00000020;
4018
4019    /**
4020     * When combined with {@link #FLAG_GRANT_READ_URI_PERMISSION} and/or
4021     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION}, the URI permission grant can be
4022     * persisted across device reboots until explicitly revoked with
4023     * {@link Context#revokeUriPermission(Uri, int)}. This flag only offers the
4024     * grant for possible persisting; the receiving application must call
4025     * {@link ContentResolver#takePersistableUriPermission(Uri, int)} to
4026     * actually persist.
4027     *
4028     * @see ContentResolver#takePersistableUriPermission(Uri, int)
4029     * @see ContentResolver#releasePersistableUriPermission(Uri, int)
4030     * @see ContentResolver#getPersistedUriPermissions()
4031     * @see ContentResolver#getOutgoingPersistedUriPermissions()
4032     */
4033    public static final int FLAG_GRANT_PERSISTABLE_URI_PERMISSION = 0x00000040;
4034
4035    /**
4036     * When combined with {@link #FLAG_GRANT_READ_URI_PERMISSION} and/or
4037     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION}, the URI permission grant
4038     * applies to any URI that is a prefix match against the original granted
4039     * URI. (Without this flag, the URI must match exactly for access to be
4040     * granted.) Another URI is considered a prefix match only when scheme,
4041     * authority, and all path segments defined by the prefix are an exact
4042     * match.
4043     */
4044    public static final int FLAG_GRANT_PREFIX_URI_PERMISSION = 0x00000080;
4045
4046    /**
4047     * If set, the new activity is not kept in the history stack.  As soon as
4048     * the user navigates away from it, the activity is finished.  This may also
4049     * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
4050     * noHistory} attribute.
4051     *
4052     * <p>If set, {@link android.app.Activity#onActivityResult onActivityResult()}
4053     * is never invoked when the current activity starts a new activity which
4054     * sets a result and finishes.
4055     */
4056    public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
4057    /**
4058     * If set, the activity will not be launched if it is already running
4059     * at the top of the history stack.
4060     */
4061    public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
4062    /**
4063     * If set, this activity will become the start of a new task on this
4064     * history stack.  A task (from the activity that started it to the
4065     * next task activity) defines an atomic group of activities that the
4066     * user can move to.  Tasks can be moved to the foreground and background;
4067     * all of the activities inside of a particular task always remain in
4068     * the same order.  See
4069     * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
4070     * Stack</a> for more information about tasks.
4071     *
4072     * <p>This flag is generally used by activities that want
4073     * to present a "launcher" style behavior: they give the user a list of
4074     * separate things that can be done, which otherwise run completely
4075     * independently of the activity launching them.
4076     *
4077     * <p>When using this flag, if a task is already running for the activity
4078     * you are now starting, then a new activity will not be started; instead,
4079     * the current task will simply be brought to the front of the screen with
4080     * the state it was last in.  See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
4081     * to disable this behavior.
4082     *
4083     * <p>This flag can not be used when the caller is requesting a result from
4084     * the activity being launched.
4085     */
4086    public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
4087    /**
4088     * This flag is used to create a new task and launch an activity into it.
4089     * This flag is always paired with either {@link #FLAG_ACTIVITY_NEW_DOCUMENT}
4090     * or {@link #FLAG_ACTIVITY_NEW_TASK}. In both cases these flags alone would
4091     * search through existing tasks for ones matching this Intent. Only if no such
4092     * task is found would a new task be created. When paired with
4093     * FLAG_ACTIVITY_MULTIPLE_TASK both of these behaviors are modified to skip
4094     * the search for a matching task and unconditionally start a new task.
4095     *
4096     * <strong>When used with {@link #FLAG_ACTIVITY_NEW_TASK} do not use this
4097     * flag unless you are implementing your own
4098     * top-level application launcher.</strong>  Used in conjunction with
4099     * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the
4100     * behavior of bringing an existing task to the foreground.  When set,
4101     * a new task is <em>always</em> started to host the Activity for the
4102     * Intent, regardless of whether there is already an existing task running
4103     * the same thing.
4104     *
4105     * <p><strong>Because the default system does not include graphical task management,
4106     * you should not use this flag unless you provide some way for a user to
4107     * return back to the tasks you have launched.</strong>
4108     *
4109     * See {@link #FLAG_ACTIVITY_NEW_DOCUMENT} for details of this flag's use for
4110     * creating new document tasks.
4111     *
4112     * <p>This flag is ignored if one of {@link #FLAG_ACTIVITY_NEW_TASK} or
4113     * {@link #FLAG_ACTIVITY_NEW_DOCUMENT} is not also set.
4114     *
4115     * <p>See
4116     * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
4117     * Stack</a> for more information about tasks.
4118     *
4119     * @see #FLAG_ACTIVITY_NEW_DOCUMENT
4120     * @see #FLAG_ACTIVITY_NEW_TASK
4121     */
4122    public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
4123    /**
4124     * If set, and the activity being launched is already running in the
4125     * current task, then instead of launching a new instance of that activity,
4126     * all of the other activities on top of it will be closed and this Intent
4127     * will be delivered to the (now on top) old activity as a new Intent.
4128     *
4129     * <p>For example, consider a task consisting of the activities: A, B, C, D.
4130     * If D calls startActivity() with an Intent that resolves to the component
4131     * of activity B, then C and D will be finished and B receive the given
4132     * Intent, resulting in the stack now being: A, B.
4133     *
4134     * <p>The currently running instance of activity B in the above example will
4135     * either receive the new intent you are starting here in its
4136     * onNewIntent() method, or be itself finished and restarted with the
4137     * new intent.  If it has declared its launch mode to be "multiple" (the
4138     * default) and you have not set {@link #FLAG_ACTIVITY_SINGLE_TOP} in
4139     * the same intent, then it will be finished and re-created; for all other
4140     * launch modes or if {@link #FLAG_ACTIVITY_SINGLE_TOP} is set then this
4141     * Intent will be delivered to the current instance's onNewIntent().
4142     *
4143     * <p>This launch mode can also be used to good effect in conjunction with
4144     * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity
4145     * of a task, it will bring any currently running instance of that task
4146     * to the foreground, and then clear it to its root state.  This is
4147     * especially useful, for example, when launching an activity from the
4148     * notification manager.
4149     *
4150     * <p>See
4151     * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
4152     * Stack</a> for more information about tasks.
4153     */
4154    public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
4155    /**
4156     * If set and this intent is being used to launch a new activity from an
4157     * existing one, then the reply target of the existing activity will be
4158     * transfered to the new activity.  This way the new activity can call
4159     * {@link android.app.Activity#setResult} and have that result sent back to
4160     * the reply target of the original activity.
4161     */
4162    public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
4163    /**
4164     * If set and this intent is being used to launch a new activity from an
4165     * existing one, the current activity will not be counted as the top
4166     * activity for deciding whether the new intent should be delivered to
4167     * the top instead of starting a new one.  The previous activity will
4168     * be used as the top, with the assumption being that the current activity
4169     * will finish itself immediately.
4170     */
4171    public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
4172    /**
4173     * If set, the new activity is not kept in the list of recently launched
4174     * activities.
4175     */
4176    public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
4177    /**
4178     * This flag is not normally set by application code, but set for you by
4179     * the system as described in the
4180     * {@link android.R.styleable#AndroidManifestActivity_launchMode
4181     * launchMode} documentation for the singleTask mode.
4182     */
4183    public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
4184    /**
4185     * If set, and this activity is either being started in a new task or
4186     * bringing to the top an existing task, then it will be launched as
4187     * the front door of the task.  This will result in the application of
4188     * any affinities needed to have that task in the proper state (either
4189     * moving activities to or from it), or simply resetting that task to
4190     * its initial state if needed.
4191     */
4192    public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
4193    /**
4194     * This flag is not normally set by application code, but set for you by
4195     * the system if this activity is being launched from history
4196     * (longpress home key).
4197     */
4198    public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
4199    /**
4200     * @deprecated As of API 21 this performs identically to
4201     * {@link #FLAG_ACTIVITY_NEW_DOCUMENT} which should be used instead of this.
4202     */
4203    public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
4204    /**
4205     * This flag is used to open a document into a new task rooted at the activity launched
4206     * by this Intent. Through the use of this flag, or its equivalent attribute,
4207     * {@link android.R.attr#documentLaunchMode} multiple instances of the same activity
4208     * containing different documents will appear in the recent tasks list.
4209     *
4210     * <p>The use of the activity attribute form of this,
4211     * {@link android.R.attr#documentLaunchMode}, is
4212     * preferred over the Intent flag described here. The attribute form allows the
4213     * Activity to specify multiple document behavior for all launchers of the Activity
4214     * whereas using this flag requires each Intent that launches the Activity to specify it.
4215     *
4216     * <p>Note that the default semantics of this flag w.r.t. whether the recents entry for
4217     * it is kept after the activity is finished is different than the use of
4218     * {@link #FLAG_ACTIVITY_NEW_TASK} and {@link android.R.attr#documentLaunchMode} -- if
4219     * this flag is being used to create a new recents entry, then by default that entry
4220     * will be removed once the activity is finished.  You can modify this behavior with
4221     * {@link #FLAG_ACTIVITY_RETAIN_IN_RECENTS}.
4222     *
4223     * <p>FLAG_ACTIVITY_NEW_DOCUMENT may be used in conjunction with {@link
4224     * #FLAG_ACTIVITY_MULTIPLE_TASK}. When used alone it is the
4225     * equivalent of the Activity manifest specifying {@link
4226     * android.R.attr#documentLaunchMode}="intoExisting". When used with
4227     * FLAG_ACTIVITY_MULTIPLE_TASK it is the equivalent of the Activity manifest specifying
4228     * {@link android.R.attr#documentLaunchMode}="always".
4229     *
4230     * Refer to {@link android.R.attr#documentLaunchMode} for more information.
4231     *
4232     * @see android.R.attr#documentLaunchMode
4233     * @see #FLAG_ACTIVITY_MULTIPLE_TASK
4234     */
4235    public static final int FLAG_ACTIVITY_NEW_DOCUMENT = FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
4236    /**
4237     * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint}
4238     * callback from occurring on the current frontmost activity before it is
4239     * paused as the newly-started activity is brought to the front.
4240     *
4241     * <p>Typically, an activity can rely on that callback to indicate that an
4242     * explicit user action has caused their activity to be moved out of the
4243     * foreground. The callback marks an appropriate point in the activity's
4244     * lifecycle for it to dismiss any notifications that it intends to display
4245     * "until the user has seen them," such as a blinking LED.
4246     *
4247     * <p>If an activity is ever started via any non-user-driven events such as
4248     * phone-call receipt or an alarm handler, this flag should be passed to {@link
4249     * Context#startActivity Context.startActivity}, ensuring that the pausing
4250     * activity does not think the user has acknowledged its notification.
4251     */
4252    public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
4253    /**
4254     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
4255     * this flag will cause the launched activity to be brought to the front of its
4256     * task's history stack if it is already running.
4257     *
4258     * <p>For example, consider a task consisting of four activities: A, B, C, D.
4259     * If D calls startActivity() with an Intent that resolves to the component
4260     * of activity B, then B will be brought to the front of the history stack,
4261     * with this resulting order:  A, C, D, B.
4262     *
4263     * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also
4264     * specified.
4265     */
4266    public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
4267    /**
4268     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
4269     * this flag will prevent the system from applying an activity transition
4270     * animation to go to the next activity state.  This doesn't mean an
4271     * animation will never run -- if another activity change happens that doesn't
4272     * specify this flag before the activity started here is displayed, then
4273     * that transition will be used.  This flag can be put to good use
4274     * when you are going to do a series of activity operations but the
4275     * animation seen by the user shouldn't be driven by the first activity
4276     * change but rather a later one.
4277     */
4278    public static final int FLAG_ACTIVITY_NO_ANIMATION = 0X00010000;
4279    /**
4280     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
4281     * this flag will cause any existing task that would be associated with the
4282     * activity to be cleared before the activity is started.  That is, the activity
4283     * becomes the new root of an otherwise empty task, and any old activities
4284     * are finished.  This can only be used in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}.
4285     */
4286    public static final int FLAG_ACTIVITY_CLEAR_TASK = 0X00008000;
4287    /**
4288     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
4289     * this flag will cause a newly launching task to be placed on top of the current
4290     * home activity task (if there is one).  That is, pressing back from the task
4291     * will always return the user to home even if that was not the last activity they
4292     * saw.   This can only be used in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}.
4293     */
4294    public static final int FLAG_ACTIVITY_TASK_ON_HOME = 0X00004000;
4295    /**
4296     * By default a document created by {@link #FLAG_ACTIVITY_NEW_DOCUMENT} will
4297     * have its entry in recent tasks removed when the user closes it (with back
4298     * or however else it may finish()). If you would like to instead allow the
4299     * document to be kept in recents so that it can be re-launched, you can use
4300     * this flag. When set and the task's activity is finished, the recents
4301     * entry will remain in the interface for the user to re-launch it, like a
4302     * recents entry for a top-level application.
4303     * <p>
4304     * The receiving activity can override this request with
4305     * {@link android.R.attr#autoRemoveFromRecents} or by explcitly calling
4306     * {@link android.app.Activity#finishAndRemoveTask()
4307     * Activity.finishAndRemoveTask()}.
4308     */
4309    public static final int FLAG_ACTIVITY_RETAIN_IN_RECENTS = 0x00002000;
4310
4311    /**
4312     * If set, when sending a broadcast only registered receivers will be
4313     * called -- no BroadcastReceiver components will be launched.
4314     */
4315    public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
4316    /**
4317     * If set, when sending a broadcast the new broadcast will replace
4318     * any existing pending broadcast that matches it.  Matching is defined
4319     * by {@link Intent#filterEquals(Intent) Intent.filterEquals} returning
4320     * true for the intents of the two broadcasts.  When a match is found,
4321     * the new broadcast (and receivers associated with it) will replace the
4322     * existing one in the pending broadcast list, remaining at the same
4323     * position in the list.
4324     *
4325     * <p>This flag is most typically used with sticky broadcasts, which
4326     * only care about delivering the most recent values of the broadcast
4327     * to their receivers.
4328     */
4329    public static final int FLAG_RECEIVER_REPLACE_PENDING = 0x20000000;
4330    /**
4331     * If set, when sending a broadcast the recipient is allowed to run at
4332     * foreground priority, with a shorter timeout interval.  During normal
4333     * broadcasts the receivers are not automatically hoisted out of the
4334     * background priority class.
4335     */
4336    public static final int FLAG_RECEIVER_FOREGROUND = 0x10000000;
4337    /**
4338     * If this is an ordered broadcast, don't allow receivers to abort the broadcast.
4339     * They can still propagate results through to later receivers, but they can not prevent
4340     * later receivers from seeing the broadcast.
4341     */
4342    public static final int FLAG_RECEIVER_NO_ABORT = 0x08000000;
4343    /**
4344     * If set, when sending a broadcast <i>before boot has completed</i> only
4345     * registered receivers will be called -- no BroadcastReceiver components
4346     * will be launched.  Sticky intent state will be recorded properly even
4347     * if no receivers wind up being called.  If {@link #FLAG_RECEIVER_REGISTERED_ONLY}
4348     * is specified in the broadcast intent, this flag is unnecessary.
4349     *
4350     * <p>This flag is only for use by system sevices as a convenience to
4351     * avoid having to implement a more complex mechanism around detection
4352     * of boot completion.
4353     *
4354     * @hide
4355     */
4356    public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x04000000;
4357    /**
4358     * Set when this broadcast is for a boot upgrade, a special mode that
4359     * allows the broadcast to be sent before the system is ready and launches
4360     * the app process with no providers running in it.
4361     * @hide
4362     */
4363    public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x02000000;
4364
4365    /**
4366     * @hide Flags that can't be changed with PendingIntent.
4367     */
4368    public static final int IMMUTABLE_FLAGS = FLAG_GRANT_READ_URI_PERMISSION
4369            | FLAG_GRANT_WRITE_URI_PERMISSION | FLAG_GRANT_PERSISTABLE_URI_PERMISSION
4370            | FLAG_GRANT_PREFIX_URI_PERMISSION;
4371
4372    // ---------------------------------------------------------------------
4373    // ---------------------------------------------------------------------
4374    // toUri() and parseUri() options.
4375
4376    /**
4377     * Flag for use with {@link #toUri} and {@link #parseUri}: the URI string
4378     * always has the "intent:" scheme.  This syntax can be used when you want
4379     * to later disambiguate between URIs that are intended to describe an
4380     * Intent vs. all others that should be treated as raw URIs.  When used
4381     * with {@link #parseUri}, any other scheme will result in a generic
4382     * VIEW action for that raw URI.
4383     */
4384    public static final int URI_INTENT_SCHEME = 1<<0;
4385
4386    /**
4387     * Flag for use with {@link #toUri} and {@link #parseUri}: the URI string
4388     * always has the "android-app:" scheme.  This is a variation of
4389     * {@link #URI_INTENT_SCHEME} whose format is simpler for the case of an
4390     * http/https URI being delivered to a specific package name.  The format
4391     * is:
4392     *
4393     * <pre class="prettyprint">
4394     * android-app://{package_id}[/{scheme}[/{host}[/{path}]]][#Intent;{...}]</pre>
4395     *
4396     * <p>In this scheme, only the <code>package_id</code> is required.  If you include a host,
4397     * you must also include a scheme; including a path also requires both a host and a scheme.
4398     * The final #Intent; fragment can be used without a scheme, host, or path.
4399     * Note that this can not be
4400     * used with intents that have a {@link #setSelector}, since the base intent
4401     * will always have an explicit package name.</p>
4402     *
4403     * <p>Some examples of how this scheme maps to Intent objects:</p>
4404     * <table border="2" width="85%" align="center" frame="hsides" rules="rows">
4405     *     <colgroup align="left" />
4406     *     <colgroup align="left" />
4407     *     <thead>
4408     *     <tr><th>URI</th> <th>Intent</th></tr>
4409     *     </thead>
4410     *
4411     *     <tbody>
4412     *     <tr><td><code>android-app://com.example.app</code></td>
4413     *         <td><table style="margin:0;border:0;cellpadding:0;cellspacing:0">
4414     *             <tr><td>Action: </td><td>{@link #ACTION_MAIN}</td></tr>
4415     *             <tr><td>Package: </td><td><code>com.example.app</code></td></tr>
4416     *         </table></td>
4417     *     </tr>
4418     *     <tr><td><code>android-app://com.example.app/http/example.com</code></td>
4419     *         <td><table style="margin:0;border:0;cellpadding:0;cellspacing:0">
4420     *             <tr><td>Action: </td><td>{@link #ACTION_VIEW}</td></tr>
4421     *             <tr><td>Data: </td><td><code>http://example.com/</code></td></tr>
4422     *             <tr><td>Package: </td><td><code>com.example.app</code></td></tr>
4423     *         </table></td>
4424     *     </tr>
4425     *     <tr><td><code>android-app://com.example.app/http/example.com/foo?1234</code></td>
4426     *         <td><table style="margin:0;border:0;cellpadding:0;cellspacing:0">
4427     *             <tr><td>Action: </td><td>{@link #ACTION_VIEW}</td></tr>
4428     *             <tr><td>Data: </td><td><code>http://example.com/foo?1234</code></td></tr>
4429     *             <tr><td>Package: </td><td><code>com.example.app</code></td></tr>
4430     *         </table></td>
4431     *     </tr>
4432     *     <tr><td><code>android-app://com.example.app/<br />#Intent;action=com.example.MY_ACTION;end</code></td>
4433     *         <td><table style="margin:0;border:0;cellpadding:0;cellspacing:0">
4434     *             <tr><td>Action: </td><td><code>com.example.MY_ACTION</code></td></tr>
4435     *             <tr><td>Package: </td><td><code>com.example.app</code></td></tr>
4436     *         </table></td>
4437     *     </tr>
4438     *     <tr><td><code>android-app://com.example.app/http/example.com/foo?1234<br />#Intent;action=com.example.MY_ACTION;end</code></td>
4439     *         <td><table style="margin:0;border:0;cellpadding:0;cellspacing:0">
4440     *             <tr><td>Action: </td><td><code>com.example.MY_ACTION</code></td></tr>
4441     *             <tr><td>Data: </td><td><code>http://example.com/foo?1234</code></td></tr>
4442     *             <tr><td>Package: </td><td><code>com.example.app</code></td></tr>
4443     *         </table></td>
4444     *     </tr>
4445     *     <tr><td><code>android-app://com.example.app/<br />#Intent;action=com.example.MY_ACTION;<br />i.some_int=100;S.some_str=hello;end</code></td>
4446     *         <td><table border="" style="margin:0" >
4447     *             <tr><td>Action: </td><td><code>com.example.MY_ACTION</code></td></tr>
4448     *             <tr><td>Package: </td><td><code>com.example.app</code></td></tr>
4449     *             <tr><td>Extras: </td><td><code>some_int=(int)100<br />some_str=(String)hello</code></td></tr>
4450     *         </table></td>
4451     *     </tr>
4452     *     </tbody>
4453     * </table>
4454     */
4455    public static final int URI_ANDROID_APP_SCHEME = 1<<1;
4456
4457    /**
4458     * Flag for use with {@link #toUri} and {@link #parseUri}: allow parsing
4459     * of unsafe information.  In particular, the flags {@link #FLAG_GRANT_READ_URI_PERMISSION},
4460     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION}, {@link #FLAG_GRANT_PERSISTABLE_URI_PERMISSION},
4461     * and {@link #FLAG_GRANT_PREFIX_URI_PERMISSION} flags can not be set, so that the
4462     * generated Intent can not cause unexpected data access to happen.
4463     *
4464     * <p>If you do not trust the source of the URI being parsed, you should still do further
4465     * processing to protect yourself from it.  In particular, when using it to start an
4466     * activity you should usually add in {@link #CATEGORY_BROWSABLE} to limit the activities
4467     * that can handle it.</p>
4468     */
4469    public static final int URI_ALLOW_UNSAFE = 1<<2;
4470
4471    // ---------------------------------------------------------------------
4472
4473    private String mAction;
4474    private Uri mData;
4475    private String mType;
4476    private String mPackage;
4477    private ComponentName mComponent;
4478    private int mFlags;
4479    private ArraySet<String> mCategories;
4480    private Bundle mExtras;
4481    private Rect mSourceBounds;
4482    private Intent mSelector;
4483    private ClipData mClipData;
4484    private int mContentUserHint = UserHandle.USER_CURRENT;
4485
4486    // ---------------------------------------------------------------------
4487
4488    /**
4489     * Create an empty intent.
4490     */
4491    public Intent() {
4492    }
4493
4494    /**
4495     * Copy constructor.
4496     */
4497    public Intent(Intent o) {
4498        this.mAction = o.mAction;
4499        this.mData = o.mData;
4500        this.mType = o.mType;
4501        this.mPackage = o.mPackage;
4502        this.mComponent = o.mComponent;
4503        this.mFlags = o.mFlags;
4504        this.mContentUserHint = o.mContentUserHint;
4505        if (o.mCategories != null) {
4506            this.mCategories = new ArraySet<String>(o.mCategories);
4507        }
4508        if (o.mExtras != null) {
4509            this.mExtras = new Bundle(o.mExtras);
4510        }
4511        if (o.mSourceBounds != null) {
4512            this.mSourceBounds = new Rect(o.mSourceBounds);
4513        }
4514        if (o.mSelector != null) {
4515            this.mSelector = new Intent(o.mSelector);
4516        }
4517        if (o.mClipData != null) {
4518            this.mClipData = new ClipData(o.mClipData);
4519        }
4520    }
4521
4522    @Override
4523    public Object clone() {
4524        return new Intent(this);
4525    }
4526
4527    private Intent(Intent o, boolean all) {
4528        this.mAction = o.mAction;
4529        this.mData = o.mData;
4530        this.mType = o.mType;
4531        this.mPackage = o.mPackage;
4532        this.mComponent = o.mComponent;
4533        if (o.mCategories != null) {
4534            this.mCategories = new ArraySet<String>(o.mCategories);
4535        }
4536    }
4537
4538    /**
4539     * Make a clone of only the parts of the Intent that are relevant for
4540     * filter matching: the action, data, type, component, and categories.
4541     */
4542    public Intent cloneFilter() {
4543        return new Intent(this, false);
4544    }
4545
4546    /**
4547     * Create an intent with a given action.  All other fields (data, type,
4548     * class) are null.  Note that the action <em>must</em> be in a
4549     * namespace because Intents are used globally in the system -- for
4550     * example the system VIEW action is android.intent.action.VIEW; an
4551     * application's custom action would be something like
4552     * com.google.app.myapp.CUSTOM_ACTION.
4553     *
4554     * @param action The Intent action, such as ACTION_VIEW.
4555     */
4556    public Intent(String action) {
4557        setAction(action);
4558    }
4559
4560    /**
4561     * Create an intent with a given action and for a given data url.  Note
4562     * that the action <em>must</em> be in a namespace because Intents are
4563     * used globally in the system -- for example the system VIEW action is
4564     * android.intent.action.VIEW; an application's custom action would be
4565     * something like com.google.app.myapp.CUSTOM_ACTION.
4566     *
4567     * <p><em>Note: scheme and host name matching in the Android framework is
4568     * case-sensitive, unlike the formal RFC.  As a result,
4569     * you should always ensure that you write your Uri with these elements
4570     * using lower case letters, and normalize any Uris you receive from
4571     * outside of Android to ensure the scheme and host is lower case.</em></p>
4572     *
4573     * @param action The Intent action, such as ACTION_VIEW.
4574     * @param uri The Intent data URI.
4575     */
4576    public Intent(String action, Uri uri) {
4577        setAction(action);
4578        mData = uri;
4579    }
4580
4581    /**
4582     * Create an intent for a specific component.  All other fields (action, data,
4583     * type, class) are null, though they can be modified later with explicit
4584     * calls.  This provides a convenient way to create an intent that is
4585     * intended to execute a hard-coded class name, rather than relying on the
4586     * system to find an appropriate class for you; see {@link #setComponent}
4587     * for more information on the repercussions of this.
4588     *
4589     * @param packageContext A Context of the application package implementing
4590     * this class.
4591     * @param cls The component class that is to be used for the intent.
4592     *
4593     * @see #setClass
4594     * @see #setComponent
4595     * @see #Intent(String, android.net.Uri , Context, Class)
4596     */
4597    public Intent(Context packageContext, Class<?> cls) {
4598        mComponent = new ComponentName(packageContext, cls);
4599    }
4600
4601    /**
4602     * Create an intent for a specific component with a specified action and data.
4603     * This is equivalent to using {@link #Intent(String, android.net.Uri)} to
4604     * construct the Intent and then calling {@link #setClass} to set its
4605     * class.
4606     *
4607     * <p><em>Note: scheme and host name matching in the Android framework is
4608     * case-sensitive, unlike the formal RFC.  As a result,
4609     * you should always ensure that you write your Uri with these elements
4610     * using lower case letters, and normalize any Uris you receive from
4611     * outside of Android to ensure the scheme and host is lower case.</em></p>
4612     *
4613     * @param action The Intent action, such as ACTION_VIEW.
4614     * @param uri The Intent data URI.
4615     * @param packageContext A Context of the application package implementing
4616     * this class.
4617     * @param cls The component class that is to be used for the intent.
4618     *
4619     * @see #Intent(String, android.net.Uri)
4620     * @see #Intent(Context, Class)
4621     * @see #setClass
4622     * @see #setComponent
4623     */
4624    public Intent(String action, Uri uri,
4625            Context packageContext, Class<?> cls) {
4626        setAction(action);
4627        mData = uri;
4628        mComponent = new ComponentName(packageContext, cls);
4629    }
4630
4631    /**
4632     * Create an intent to launch the main (root) activity of a task.  This
4633     * is the Intent that is started when the application's is launched from
4634     * Home.  For anything else that wants to launch an application in the
4635     * same way, it is important that they use an Intent structured the same
4636     * way, and can use this function to ensure this is the case.
4637     *
4638     * <p>The returned Intent has the given Activity component as its explicit
4639     * component, {@link #ACTION_MAIN} as its action, and includes the
4640     * category {@link #CATEGORY_LAUNCHER}.  This does <em>not</em> have
4641     * {@link #FLAG_ACTIVITY_NEW_TASK} set, though typically you will want
4642     * to do that through {@link #addFlags(int)} on the returned Intent.
4643     *
4644     * @param mainActivity The main activity component that this Intent will
4645     * launch.
4646     * @return Returns a newly created Intent that can be used to launch the
4647     * activity as a main application entry.
4648     *
4649     * @see #setClass
4650     * @see #setComponent
4651     */
4652    public static Intent makeMainActivity(ComponentName mainActivity) {
4653        Intent intent = new Intent(ACTION_MAIN);
4654        intent.setComponent(mainActivity);
4655        intent.addCategory(CATEGORY_LAUNCHER);
4656        return intent;
4657    }
4658
4659    /**
4660     * Make an Intent for the main activity of an application, without
4661     * specifying a specific activity to run but giving a selector to find
4662     * the activity.  This results in a final Intent that is structured
4663     * the same as when the application is launched from
4664     * Home.  For anything else that wants to launch an application in the
4665     * same way, it is important that they use an Intent structured the same
4666     * way, and can use this function to ensure this is the case.
4667     *
4668     * <p>The returned Intent has {@link #ACTION_MAIN} as its action, and includes the
4669     * category {@link #CATEGORY_LAUNCHER}.  This does <em>not</em> have
4670     * {@link #FLAG_ACTIVITY_NEW_TASK} set, though typically you will want
4671     * to do that through {@link #addFlags(int)} on the returned Intent.
4672     *
4673     * @param selectorAction The action name of the Intent's selector.
4674     * @param selectorCategory The name of a category to add to the Intent's
4675     * selector.
4676     * @return Returns a newly created Intent that can be used to launch the
4677     * activity as a main application entry.
4678     *
4679     * @see #setSelector(Intent)
4680     */
4681    public static Intent makeMainSelectorActivity(String selectorAction,
4682            String selectorCategory) {
4683        Intent intent = new Intent(ACTION_MAIN);
4684        intent.addCategory(CATEGORY_LAUNCHER);
4685        Intent selector = new Intent();
4686        selector.setAction(selectorAction);
4687        selector.addCategory(selectorCategory);
4688        intent.setSelector(selector);
4689        return intent;
4690    }
4691
4692    /**
4693     * Make an Intent that can be used to re-launch an application's task
4694     * in its base state.  This is like {@link #makeMainActivity(ComponentName)},
4695     * but also sets the flags {@link #FLAG_ACTIVITY_NEW_TASK} and
4696     * {@link #FLAG_ACTIVITY_CLEAR_TASK}.
4697     *
4698     * @param mainActivity The activity component that is the root of the
4699     * task; this is the activity that has been published in the application's
4700     * manifest as the main launcher icon.
4701     *
4702     * @return Returns a newly created Intent that can be used to relaunch the
4703     * activity's task in its root state.
4704     */
4705    public static Intent makeRestartActivityTask(ComponentName mainActivity) {
4706        Intent intent = makeMainActivity(mainActivity);
4707        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
4708                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
4709        return intent;
4710    }
4711
4712    /**
4713     * Call {@link #parseUri} with 0 flags.
4714     * @deprecated Use {@link #parseUri} instead.
4715     */
4716    @Deprecated
4717    public static Intent getIntent(String uri) throws URISyntaxException {
4718        return parseUri(uri, 0);
4719    }
4720
4721    /**
4722     * Create an intent from a URI.  This URI may encode the action,
4723     * category, and other intent fields, if it was returned by
4724     * {@link #toUri}.  If the Intent was not generate by toUri(), its data
4725     * will be the entire URI and its action will be ACTION_VIEW.
4726     *
4727     * <p>The URI given here must not be relative -- that is, it must include
4728     * the scheme and full path.
4729     *
4730     * @param uri The URI to turn into an Intent.
4731     * @param flags Additional processing flags.  Either 0,
4732     * {@link #URI_INTENT_SCHEME}, or {@link #URI_ANDROID_APP_SCHEME}.
4733     *
4734     * @return Intent The newly created Intent object.
4735     *
4736     * @throws URISyntaxException Throws URISyntaxError if the basic URI syntax
4737     * it bad (as parsed by the Uri class) or the Intent data within the
4738     * URI is invalid.
4739     *
4740     * @see #toUri
4741     */
4742    public static Intent parseUri(String uri, int flags) throws URISyntaxException {
4743        int i = 0;
4744        try {
4745            final boolean androidApp = uri.startsWith("android-app:");
4746
4747            // Validate intent scheme if requested.
4748            if ((flags&(URI_INTENT_SCHEME|URI_ANDROID_APP_SCHEME)) != 0) {
4749                if (!uri.startsWith("intent:") && !androidApp) {
4750                    Intent intent = new Intent(ACTION_VIEW);
4751                    try {
4752                        intent.setData(Uri.parse(uri));
4753                    } catch (IllegalArgumentException e) {
4754                        throw new URISyntaxException(uri, e.getMessage());
4755                    }
4756                    return intent;
4757                }
4758            }
4759
4760            i = uri.lastIndexOf("#");
4761            // simple case
4762            if (i == -1) {
4763                if (!androidApp) {
4764                    return new Intent(ACTION_VIEW, Uri.parse(uri));
4765                }
4766
4767            // old format Intent URI
4768            } else if (!uri.startsWith("#Intent;", i)) {
4769                if (!androidApp) {
4770                    return getIntentOld(uri, flags);
4771                } else {
4772                    i = -1;
4773                }
4774            }
4775
4776            // new format
4777            Intent intent = new Intent(ACTION_VIEW);
4778            Intent baseIntent = intent;
4779            boolean explicitAction = false;
4780            boolean inSelector = false;
4781
4782            // fetch data part, if present
4783            String scheme = null;
4784            String data;
4785            if (i >= 0) {
4786                data = uri.substring(0, i);
4787                i += 8; // length of "#Intent;"
4788            } else {
4789                data = uri;
4790            }
4791
4792            // loop over contents of Intent, all name=value;
4793            while (i >= 0 && !uri.startsWith("end", i)) {
4794                int eq = uri.indexOf('=', i);
4795                if (eq < 0) eq = i-1;
4796                int semi = uri.indexOf(';', i);
4797                String value = eq < semi ? Uri.decode(uri.substring(eq + 1, semi)) : "";
4798
4799                // action
4800                if (uri.startsWith("action=", i)) {
4801                    intent.setAction(value);
4802                    if (!inSelector) {
4803                        explicitAction = true;
4804                    }
4805                }
4806
4807                // categories
4808                else if (uri.startsWith("category=", i)) {
4809                    intent.addCategory(value);
4810                }
4811
4812                // type
4813                else if (uri.startsWith("type=", i)) {
4814                    intent.mType = value;
4815                }
4816
4817                // launch flags
4818                else if (uri.startsWith("launchFlags=", i)) {
4819                    intent.mFlags = Integer.decode(value).intValue();
4820                    if ((flags& URI_ALLOW_UNSAFE) == 0) {
4821                        intent.mFlags &= ~IMMUTABLE_FLAGS;
4822                    }
4823                }
4824
4825                // package
4826                else if (uri.startsWith("package=", i)) {
4827                    intent.mPackage = value;
4828                }
4829
4830                // component
4831                else if (uri.startsWith("component=", i)) {
4832                    intent.mComponent = ComponentName.unflattenFromString(value);
4833                }
4834
4835                // scheme
4836                else if (uri.startsWith("scheme=", i)) {
4837                    if (inSelector) {
4838                        intent.mData = Uri.parse(value + ":");
4839                    } else {
4840                        scheme = value;
4841                    }
4842                }
4843
4844                // source bounds
4845                else if (uri.startsWith("sourceBounds=", i)) {
4846                    intent.mSourceBounds = Rect.unflattenFromString(value);
4847                }
4848
4849                // selector
4850                else if (semi == (i+3) && uri.startsWith("SEL", i)) {
4851                    intent = new Intent();
4852                    inSelector = true;
4853                }
4854
4855                // extra
4856                else {
4857                    String key = Uri.decode(uri.substring(i + 2, eq));
4858                    // create Bundle if it doesn't already exist
4859                    if (intent.mExtras == null) intent.mExtras = new Bundle();
4860                    Bundle b = intent.mExtras;
4861                    // add EXTRA
4862                    if      (uri.startsWith("S.", i)) b.putString(key, value);
4863                    else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
4864                    else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
4865                    else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
4866                    else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
4867                    else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
4868                    else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
4869                    else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
4870                    else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
4871                    else throw new URISyntaxException(uri, "unknown EXTRA type", i);
4872                }
4873
4874                // move to the next item
4875                i = semi + 1;
4876            }
4877
4878            if (inSelector) {
4879                // The Intent had a selector; fix it up.
4880                if (baseIntent.mPackage == null) {
4881                    baseIntent.setSelector(intent);
4882                }
4883                intent = baseIntent;
4884            }
4885
4886            if (data != null) {
4887                if (data.startsWith("intent:")) {
4888                    data = data.substring(7);
4889                    if (scheme != null) {
4890                        data = scheme + ':' + data;
4891                    }
4892                } else if (data.startsWith("android-app:")) {
4893                    if (data.charAt(12) == '/' && data.charAt(13) == '/') {
4894                        // Correctly formed android-app, first part is package name.
4895                        int end = data.indexOf('/', 14);
4896                        if (end < 0) {
4897                            // All we have is a package name.
4898                            intent.mPackage = data.substring(14);
4899                            if (!explicitAction) {
4900                                intent.setAction(ACTION_MAIN);
4901                            }
4902                            data = "";
4903                        } else {
4904                            // Target the Intent at the given package name always.
4905                            String authority = null;
4906                            intent.mPackage = data.substring(14, end);
4907                            int newEnd;
4908                            if ((end+1) < data.length()) {
4909                                if ((newEnd=data.indexOf('/', end+1)) >= 0) {
4910                                    // Found a scheme, remember it.
4911                                    scheme = data.substring(end+1, newEnd);
4912                                    end = newEnd;
4913                                    if (end < data.length() && (newEnd=data.indexOf('/', end+1)) >= 0) {
4914                                        // Found a authority, remember it.
4915                                        authority = data.substring(end+1, newEnd);
4916                                        end = newEnd;
4917                                    }
4918                                } else {
4919                                    // All we have is a scheme.
4920                                    scheme = data.substring(end+1);
4921                                }
4922                            }
4923                            if (scheme == null) {
4924                                // If there was no scheme, then this just targets the package.
4925                                if (!explicitAction) {
4926                                    intent.setAction(ACTION_MAIN);
4927                                }
4928                                data = "";
4929                            } else if (authority == null) {
4930                                data = scheme + ":";
4931                            } else {
4932                                data = scheme + "://" + authority + data.substring(end);
4933                            }
4934                        }
4935                    } else {
4936                        data = "";
4937                    }
4938                }
4939
4940                if (data.length() > 0) {
4941                    try {
4942                        intent.mData = Uri.parse(data);
4943                    } catch (IllegalArgumentException e) {
4944                        throw new URISyntaxException(uri, e.getMessage());
4945                    }
4946                }
4947            }
4948
4949            return intent;
4950
4951        } catch (IndexOutOfBoundsException e) {
4952            throw new URISyntaxException(uri, "illegal Intent URI format", i);
4953        }
4954    }
4955
4956    public static Intent getIntentOld(String uri) throws URISyntaxException {
4957        return getIntentOld(uri, 0);
4958    }
4959
4960    private static Intent getIntentOld(String uri, int flags) throws URISyntaxException {
4961        Intent intent;
4962
4963        int i = uri.lastIndexOf('#');
4964        if (i >= 0) {
4965            String action = null;
4966            final int intentFragmentStart = i;
4967            boolean isIntentFragment = false;
4968
4969            i++;
4970
4971            if (uri.regionMatches(i, "action(", 0, 7)) {
4972                isIntentFragment = true;
4973                i += 7;
4974                int j = uri.indexOf(')', i);
4975                action = uri.substring(i, j);
4976                i = j + 1;
4977            }
4978
4979            intent = new Intent(action);
4980
4981            if (uri.regionMatches(i, "categories(", 0, 11)) {
4982                isIntentFragment = true;
4983                i += 11;
4984                int j = uri.indexOf(')', i);
4985                while (i < j) {
4986                    int sep = uri.indexOf('!', i);
4987                    if (sep < 0 || sep > j) sep = j;
4988                    if (i < sep) {
4989                        intent.addCategory(uri.substring(i, sep));
4990                    }
4991                    i = sep + 1;
4992                }
4993                i = j + 1;
4994            }
4995
4996            if (uri.regionMatches(i, "type(", 0, 5)) {
4997                isIntentFragment = true;
4998                i += 5;
4999                int j = uri.indexOf(')', i);
5000                intent.mType = uri.substring(i, j);
5001                i = j + 1;
5002            }
5003
5004            if (uri.regionMatches(i, "launchFlags(", 0, 12)) {
5005                isIntentFragment = true;
5006                i += 12;
5007                int j = uri.indexOf(')', i);
5008                intent.mFlags = Integer.decode(uri.substring(i, j)).intValue();
5009                if ((flags& URI_ALLOW_UNSAFE) == 0) {
5010                    intent.mFlags &= ~IMMUTABLE_FLAGS;
5011                }
5012                i = j + 1;
5013            }
5014
5015            if (uri.regionMatches(i, "component(", 0, 10)) {
5016                isIntentFragment = true;
5017                i += 10;
5018                int j = uri.indexOf(')', i);
5019                int sep = uri.indexOf('!', i);
5020                if (sep >= 0 && sep < j) {
5021                    String pkg = uri.substring(i, sep);
5022                    String cls = uri.substring(sep + 1, j);
5023                    intent.mComponent = new ComponentName(pkg, cls);
5024                }
5025                i = j + 1;
5026            }
5027
5028            if (uri.regionMatches(i, "extras(", 0, 7)) {
5029                isIntentFragment = true;
5030                i += 7;
5031
5032                final int closeParen = uri.indexOf(')', i);
5033                if (closeParen == -1) throw new URISyntaxException(uri,
5034                        "EXTRA missing trailing ')'", i);
5035
5036                while (i < closeParen) {
5037                    // fetch the key value
5038                    int j = uri.indexOf('=', i);
5039                    if (j <= i + 1 || i >= closeParen) {
5040                        throw new URISyntaxException(uri, "EXTRA missing '='", i);
5041                    }
5042                    char type = uri.charAt(i);
5043                    i++;
5044                    String key = uri.substring(i, j);
5045                    i = j + 1;
5046
5047                    // get type-value
5048                    j = uri.indexOf('!', i);
5049                    if (j == -1 || j >= closeParen) j = closeParen;
5050                    if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i);
5051                    String value = uri.substring(i, j);
5052                    i = j;
5053
5054                    // create Bundle if it doesn't already exist
5055                    if (intent.mExtras == null) intent.mExtras = new Bundle();
5056
5057                    // add item to bundle
5058                    try {
5059                        switch (type) {
5060                            case 'S':
5061                                intent.mExtras.putString(key, Uri.decode(value));
5062                                break;
5063                            case 'B':
5064                                intent.mExtras.putBoolean(key, Boolean.parseBoolean(value));
5065                                break;
5066                            case 'b':
5067                                intent.mExtras.putByte(key, Byte.parseByte(value));
5068                                break;
5069                            case 'c':
5070                                intent.mExtras.putChar(key, Uri.decode(value).charAt(0));
5071                                break;
5072                            case 'd':
5073                                intent.mExtras.putDouble(key, Double.parseDouble(value));
5074                                break;
5075                            case 'f':
5076                                intent.mExtras.putFloat(key, Float.parseFloat(value));
5077                                break;
5078                            case 'i':
5079                                intent.mExtras.putInt(key, Integer.parseInt(value));
5080                                break;
5081                            case 'l':
5082                                intent.mExtras.putLong(key, Long.parseLong(value));
5083                                break;
5084                            case 's':
5085                                intent.mExtras.putShort(key, Short.parseShort(value));
5086                                break;
5087                            default:
5088                                throw new URISyntaxException(uri, "EXTRA has unknown type", i);
5089                        }
5090                    } catch (NumberFormatException e) {
5091                        throw new URISyntaxException(uri, "EXTRA value can't be parsed", i);
5092                    }
5093
5094                    char ch = uri.charAt(i);
5095                    if (ch == ')') break;
5096                    if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i);
5097                    i++;
5098                }
5099            }
5100
5101            if (isIntentFragment) {
5102                intent.mData = Uri.parse(uri.substring(0, intentFragmentStart));
5103            } else {
5104                intent.mData = Uri.parse(uri);
5105            }
5106
5107            if (intent.mAction == null) {
5108                // By default, if no action is specified, then use VIEW.
5109                intent.mAction = ACTION_VIEW;
5110            }
5111
5112        } else {
5113            intent = new Intent(ACTION_VIEW, Uri.parse(uri));
5114        }
5115
5116        return intent;
5117    }
5118
5119    /** @hide */
5120    public interface CommandOptionHandler {
5121        boolean handleOption(String opt, ShellCommand cmd);
5122    }
5123
5124    /** @hide */
5125    public static Intent parseCommandArgs(ShellCommand cmd, CommandOptionHandler optionHandler)
5126            throws URISyntaxException {
5127        Intent intent = new Intent();
5128        Intent baseIntent = intent;
5129        boolean hasIntentInfo = false;
5130
5131        Uri data = null;
5132        String type = null;
5133
5134        String opt;
5135        while ((opt=cmd.getNextOption()) != null) {
5136            switch (opt) {
5137                case "-a":
5138                    intent.setAction(cmd.getNextArgRequired());
5139                    if (intent == baseIntent) {
5140                        hasIntentInfo = true;
5141                    }
5142                    break;
5143                case "-d":
5144                    data = Uri.parse(cmd.getNextArgRequired());
5145                    if (intent == baseIntent) {
5146                        hasIntentInfo = true;
5147                    }
5148                    break;
5149                case "-t":
5150                    type = cmd.getNextArgRequired();
5151                    if (intent == baseIntent) {
5152                        hasIntentInfo = true;
5153                    }
5154                    break;
5155                case "-c":
5156                    intent.addCategory(cmd.getNextArgRequired());
5157                    if (intent == baseIntent) {
5158                        hasIntentInfo = true;
5159                    }
5160                    break;
5161                case "-e":
5162                case "--es": {
5163                    String key = cmd.getNextArgRequired();
5164                    String value = cmd.getNextArgRequired();
5165                    intent.putExtra(key, value);
5166                }
5167                break;
5168                case "--esn": {
5169                    String key = cmd.getNextArgRequired();
5170                    intent.putExtra(key, (String) null);
5171                }
5172                break;
5173                case "--ei": {
5174                    String key = cmd.getNextArgRequired();
5175                    String value = cmd.getNextArgRequired();
5176                    intent.putExtra(key, Integer.decode(value));
5177                }
5178                break;
5179                case "--eu": {
5180                    String key = cmd.getNextArgRequired();
5181                    String value = cmd.getNextArgRequired();
5182                    intent.putExtra(key, Uri.parse(value));
5183                }
5184                break;
5185                case "--ecn": {
5186                    String key = cmd.getNextArgRequired();
5187                    String value = cmd.getNextArgRequired();
5188                    ComponentName cn = ComponentName.unflattenFromString(value);
5189                    if (cn == null)
5190                        throw new IllegalArgumentException("Bad component name: " + value);
5191                    intent.putExtra(key, cn);
5192                }
5193                break;
5194                case "--eia": {
5195                    String key = cmd.getNextArgRequired();
5196                    String value = cmd.getNextArgRequired();
5197                    String[] strings = value.split(",");
5198                    int[] list = new int[strings.length];
5199                    for (int i = 0; i < strings.length; i++) {
5200                        list[i] = Integer.decode(strings[i]);
5201                    }
5202                    intent.putExtra(key, list);
5203                }
5204                break;
5205                case "--eial": {
5206                    String key = cmd.getNextArgRequired();
5207                    String value = cmd.getNextArgRequired();
5208                    String[] strings = value.split(",");
5209                    ArrayList<Integer> list = new ArrayList<>(strings.length);
5210                    for (int i = 0; i < strings.length; i++) {
5211                        list.add(Integer.decode(strings[i]));
5212                    }
5213                    intent.putExtra(key, list);
5214                }
5215                break;
5216                case "--el": {
5217                    String key = cmd.getNextArgRequired();
5218                    String value = cmd.getNextArgRequired();
5219                    intent.putExtra(key, Long.valueOf(value));
5220                }
5221                break;
5222                case "--ela": {
5223                    String key = cmd.getNextArgRequired();
5224                    String value = cmd.getNextArgRequired();
5225                    String[] strings = value.split(",");
5226                    long[] list = new long[strings.length];
5227                    for (int i = 0; i < strings.length; i++) {
5228                        list[i] = Long.valueOf(strings[i]);
5229                    }
5230                    intent.putExtra(key, list);
5231                    hasIntentInfo = true;
5232                }
5233                break;
5234                case "--elal": {
5235                    String key = cmd.getNextArgRequired();
5236                    String value = cmd.getNextArgRequired();
5237                    String[] strings = value.split(",");
5238                    ArrayList<Long> list = new ArrayList<>(strings.length);
5239                    for (int i = 0; i < strings.length; i++) {
5240                        list.add(Long.valueOf(strings[i]));
5241                    }
5242                    intent.putExtra(key, list);
5243                    hasIntentInfo = true;
5244                }
5245                break;
5246                case "--ef": {
5247                    String key = cmd.getNextArgRequired();
5248                    String value = cmd.getNextArgRequired();
5249                    intent.putExtra(key, Float.valueOf(value));
5250                    hasIntentInfo = true;
5251                }
5252                break;
5253                case "--efa": {
5254                    String key = cmd.getNextArgRequired();
5255                    String value = cmd.getNextArgRequired();
5256                    String[] strings = value.split(",");
5257                    float[] list = new float[strings.length];
5258                    for (int i = 0; i < strings.length; i++) {
5259                        list[i] = Float.valueOf(strings[i]);
5260                    }
5261                    intent.putExtra(key, list);
5262                    hasIntentInfo = true;
5263                }
5264                break;
5265                case "--efal": {
5266                    String key = cmd.getNextArgRequired();
5267                    String value = cmd.getNextArgRequired();
5268                    String[] strings = value.split(",");
5269                    ArrayList<Float> list = new ArrayList<>(strings.length);
5270                    for (int i = 0; i < strings.length; i++) {
5271                        list.add(Float.valueOf(strings[i]));
5272                    }
5273                    intent.putExtra(key, list);
5274                    hasIntentInfo = true;
5275                }
5276                break;
5277                case "--esa": {
5278                    String key = cmd.getNextArgRequired();
5279                    String value = cmd.getNextArgRequired();
5280                    // Split on commas unless they are preceeded by an escape.
5281                    // The escape character must be escaped for the string and
5282                    // again for the regex, thus four escape characters become one.
5283                    String[] strings = value.split("(?<!\\\\),");
5284                    intent.putExtra(key, strings);
5285                    hasIntentInfo = true;
5286                }
5287                break;
5288                case "--esal": {
5289                    String key = cmd.getNextArgRequired();
5290                    String value = cmd.getNextArgRequired();
5291                    // Split on commas unless they are preceeded by an escape.
5292                    // The escape character must be escaped for the string and
5293                    // again for the regex, thus four escape characters become one.
5294                    String[] strings = value.split("(?<!\\\\),");
5295                    ArrayList<String> list = new ArrayList<>(strings.length);
5296                    for (int i = 0; i < strings.length; i++) {
5297                        list.add(strings[i]);
5298                    }
5299                    intent.putExtra(key, list);
5300                    hasIntentInfo = true;
5301                }
5302                break;
5303                case "--ez": {
5304                    String key = cmd.getNextArgRequired();
5305                    String value = cmd.getNextArgRequired().toLowerCase();
5306                    // Boolean.valueOf() results in false for anything that is not "true", which is
5307                    // error-prone in shell commands
5308                    boolean arg;
5309                    if ("true".equals(value) || "t".equals(value)) {
5310                        arg = true;
5311                    } else if ("false".equals(value) || "f".equals(value)) {
5312                        arg = false;
5313                    } else {
5314                        try {
5315                            arg = Integer.decode(value) != 0;
5316                        } catch (NumberFormatException ex) {
5317                            throw new IllegalArgumentException("Invalid boolean value: " + value);
5318                        }
5319                    }
5320
5321                    intent.putExtra(key, arg);
5322                }
5323                break;
5324                case "-n": {
5325                    String str = cmd.getNextArgRequired();
5326                    ComponentName cn = ComponentName.unflattenFromString(str);
5327                    if (cn == null)
5328                        throw new IllegalArgumentException("Bad component name: " + str);
5329                    intent.setComponent(cn);
5330                    if (intent == baseIntent) {
5331                        hasIntentInfo = true;
5332                    }
5333                }
5334                break;
5335                case "-p": {
5336                    String str = cmd.getNextArgRequired();
5337                    intent.setPackage(str);
5338                    if (intent == baseIntent) {
5339                        hasIntentInfo = true;
5340                    }
5341                }
5342                break;
5343                case "-f":
5344                    String str = cmd.getNextArgRequired();
5345                    intent.setFlags(Integer.decode(str).intValue());
5346                    break;
5347                case "--grant-read-uri-permission":
5348                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
5349                    break;
5350                case "--grant-write-uri-permission":
5351                    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
5352                    break;
5353                case "--grant-persistable-uri-permission":
5354                    intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
5355                    break;
5356                case "--grant-prefix-uri-permission":
5357                    intent.addFlags(Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
5358                    break;
5359                case "--exclude-stopped-packages":
5360                    intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
5361                    break;
5362                case "--include-stopped-packages":
5363                    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
5364                    break;
5365                case "--debug-log-resolution":
5366                    intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
5367                    break;
5368                case "--activity-brought-to-front":
5369                    intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
5370                    break;
5371                case "--activity-clear-top":
5372                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
5373                    break;
5374                case "--activity-clear-when-task-reset":
5375                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
5376                    break;
5377                case "--activity-exclude-from-recents":
5378                    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
5379                    break;
5380                case "--activity-launched-from-history":
5381                    intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
5382                    break;
5383                case "--activity-multiple-task":
5384                    intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
5385                    break;
5386                case "--activity-no-animation":
5387                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
5388                    break;
5389                case "--activity-no-history":
5390                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
5391                    break;
5392                case "--activity-no-user-action":
5393                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
5394                    break;
5395                case "--activity-previous-is-top":
5396                    intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
5397                    break;
5398                case "--activity-reorder-to-front":
5399                    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
5400                    break;
5401                case "--activity-reset-task-if-needed":
5402                    intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
5403                    break;
5404                case "--activity-single-top":
5405                    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
5406                    break;
5407                case "--activity-clear-task":
5408                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
5409                    break;
5410                case "--activity-task-on-home":
5411                    intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
5412                    break;
5413                case "--receiver-registered-only":
5414                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
5415                    break;
5416                case "--receiver-replace-pending":
5417                    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
5418                    break;
5419                case "--selector":
5420                    intent.setDataAndType(data, type);
5421                    intent = new Intent();
5422                    break;
5423                default:
5424                    if (optionHandler != null && optionHandler.handleOption(opt, cmd)) {
5425                        // Okay, caller handled this option.
5426                    } else {
5427                        throw new IllegalArgumentException("Unknown option: " + opt);
5428                    }
5429                    break;
5430            }
5431        }
5432        intent.setDataAndType(data, type);
5433
5434        final boolean hasSelector = intent != baseIntent;
5435        if (hasSelector) {
5436            // A selector was specified; fix up.
5437            baseIntent.setSelector(intent);
5438            intent = baseIntent;
5439        }
5440
5441        String arg = cmd.getNextArg();
5442        baseIntent = null;
5443        if (arg == null) {
5444            if (hasSelector) {
5445                // If a selector has been specified, and no arguments
5446                // have been supplied for the main Intent, then we can
5447                // assume it is ACTION_MAIN CATEGORY_LAUNCHER; we don't
5448                // need to have a component name specified yet, the
5449                // selector will take care of that.
5450                baseIntent = new Intent(Intent.ACTION_MAIN);
5451                baseIntent.addCategory(Intent.CATEGORY_LAUNCHER);
5452            }
5453        } else if (arg.indexOf(':') >= 0) {
5454            // The argument is a URI.  Fully parse it, and use that result
5455            // to fill in any data not specified so far.
5456            baseIntent = Intent.parseUri(arg, Intent.URI_INTENT_SCHEME
5457                    | Intent.URI_ANDROID_APP_SCHEME | Intent.URI_ALLOW_UNSAFE);
5458        } else if (arg.indexOf('/') >= 0) {
5459            // The argument is a component name.  Build an Intent to launch
5460            // it.
5461            baseIntent = new Intent(Intent.ACTION_MAIN);
5462            baseIntent.addCategory(Intent.CATEGORY_LAUNCHER);
5463            baseIntent.setComponent(ComponentName.unflattenFromString(arg));
5464        } else {
5465            // Assume the argument is a package name.
5466            baseIntent = new Intent(Intent.ACTION_MAIN);
5467            baseIntent.addCategory(Intent.CATEGORY_LAUNCHER);
5468            baseIntent.setPackage(arg);
5469        }
5470        if (baseIntent != null) {
5471            Bundle extras = intent.getExtras();
5472            intent.replaceExtras((Bundle)null);
5473            Bundle uriExtras = baseIntent.getExtras();
5474            baseIntent.replaceExtras((Bundle)null);
5475            if (intent.getAction() != null && baseIntent.getCategories() != null) {
5476                HashSet<String> cats = new HashSet<String>(baseIntent.getCategories());
5477                for (String c : cats) {
5478                    baseIntent.removeCategory(c);
5479                }
5480            }
5481            intent.fillIn(baseIntent, Intent.FILL_IN_COMPONENT | Intent.FILL_IN_SELECTOR);
5482            if (extras == null) {
5483                extras = uriExtras;
5484            } else if (uriExtras != null) {
5485                uriExtras.putAll(extras);
5486                extras = uriExtras;
5487            }
5488            intent.replaceExtras(extras);
5489            hasIntentInfo = true;
5490        }
5491
5492        if (!hasIntentInfo) throw new IllegalArgumentException("No intent supplied");
5493        return intent;
5494    }
5495
5496    /** @hide */
5497    public static void printIntentArgsHelp(PrintWriter pw, String prefix) {
5498        final String[] lines = new String[] {
5499                "<INTENT> specifications include these flags and arguments:",
5500                "    [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]",
5501                "    [-c <CATEGORY> [-c <CATEGORY>] ...]",
5502                "    [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]",
5503                "    [--esn <EXTRA_KEY> ...]",
5504                "    [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]",
5505                "    [--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]",
5506                "    [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]",
5507                "    [--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]",
5508                "    [--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]",
5509                "    [--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]",
5510                "    [--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]",
5511                "        (mutiple extras passed as Integer[])",
5512                "    [--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]",
5513                "        (mutiple extras passed as List<Integer>)",
5514                "    [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]",
5515                "        (mutiple extras passed as Long[])",
5516                "    [--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]",
5517                "        (mutiple extras passed as List<Long>)",
5518                "    [--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]",
5519                "        (mutiple extras passed as Float[])",
5520                "    [--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]",
5521                "        (mutiple extras passed as List<Float>)",
5522                "    [--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]",
5523                "        (mutiple extras passed as String[]; to embed a comma into a string,",
5524                "         escape it using \"\\,\")",
5525                "    [--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]",
5526                "        (mutiple extras passed as List<String>; to embed a comma into a string,",
5527                "         escape it using \"\\,\")",
5528                "    [--grant-read-uri-permission] [--grant-write-uri-permission]",
5529                "    [--grant-persistable-uri-permission] [--grant-prefix-uri-permission]",
5530                "    [--debug-log-resolution] [--exclude-stopped-packages]",
5531                "    [--include-stopped-packages]",
5532                "    [--activity-brought-to-front] [--activity-clear-top]",
5533                "    [--activity-clear-when-task-reset] [--activity-exclude-from-recents]",
5534                "    [--activity-launched-from-history] [--activity-multiple-task]",
5535                "    [--activity-no-animation] [--activity-no-history]",
5536                "    [--activity-no-user-action] [--activity-previous-is-top]",
5537                "    [--activity-reorder-to-front] [--activity-reset-task-if-needed]",
5538                "    [--activity-single-top] [--activity-clear-task]",
5539                "    [--activity-task-on-home]",
5540                "    [--receiver-registered-only] [--receiver-replace-pending]",
5541                "    [--selector]",
5542                "    [<URI> | <PACKAGE> | <COMPONENT>]"
5543        };
5544        for (String line : lines) {
5545            pw.print(prefix);
5546            pw.println(line);
5547        }
5548    }
5549
5550    /**
5551     * Retrieve the general action to be performed, such as
5552     * {@link #ACTION_VIEW}.  The action describes the general way the rest of
5553     * the information in the intent should be interpreted -- most importantly,
5554     * what to do with the data returned by {@link #getData}.
5555     *
5556     * @return The action of this intent or null if none is specified.
5557     *
5558     * @see #setAction
5559     */
5560    public String getAction() {
5561        return mAction;
5562    }
5563
5564    /**
5565     * Retrieve data this intent is operating on.  This URI specifies the name
5566     * of the data; often it uses the content: scheme, specifying data in a
5567     * content provider.  Other schemes may be handled by specific activities,
5568     * such as http: by the web browser.
5569     *
5570     * @return The URI of the data this intent is targeting or null.
5571     *
5572     * @see #getScheme
5573     * @see #setData
5574     */
5575    public Uri getData() {
5576        return mData;
5577    }
5578
5579    /**
5580     * The same as {@link #getData()}, but returns the URI as an encoded
5581     * String.
5582     */
5583    public String getDataString() {
5584        return mData != null ? mData.toString() : null;
5585    }
5586
5587    /**
5588     * Return the scheme portion of the intent's data.  If the data is null or
5589     * does not include a scheme, null is returned.  Otherwise, the scheme
5590     * prefix without the final ':' is returned, i.e. "http".
5591     *
5592     * <p>This is the same as calling getData().getScheme() (and checking for
5593     * null data).
5594     *
5595     * @return The scheme of this intent.
5596     *
5597     * @see #getData
5598     */
5599    public String getScheme() {
5600        return mData != null ? mData.getScheme() : null;
5601    }
5602
5603    /**
5604     * Retrieve any explicit MIME type included in the intent.  This is usually
5605     * null, as the type is determined by the intent data.
5606     *
5607     * @return If a type was manually set, it is returned; else null is
5608     *         returned.
5609     *
5610     * @see #resolveType(ContentResolver)
5611     * @see #setType
5612     */
5613    public String getType() {
5614        return mType;
5615    }
5616
5617    /**
5618     * Return the MIME data type of this intent.  If the type field is
5619     * explicitly set, that is simply returned.  Otherwise, if the data is set,
5620     * the type of that data is returned.  If neither fields are set, a null is
5621     * returned.
5622     *
5623     * @return The MIME type of this intent.
5624     *
5625     * @see #getType
5626     * @see #resolveType(ContentResolver)
5627     */
5628    public String resolveType(Context context) {
5629        return resolveType(context.getContentResolver());
5630    }
5631
5632    /**
5633     * Return the MIME data type of this intent.  If the type field is
5634     * explicitly set, that is simply returned.  Otherwise, if the data is set,
5635     * the type of that data is returned.  If neither fields are set, a null is
5636     * returned.
5637     *
5638     * @param resolver A ContentResolver that can be used to determine the MIME
5639     *                 type of the intent's data.
5640     *
5641     * @return The MIME type of this intent.
5642     *
5643     * @see #getType
5644     * @see #resolveType(Context)
5645     */
5646    public String resolveType(ContentResolver resolver) {
5647        if (mType != null) {
5648            return mType;
5649        }
5650        if (mData != null) {
5651            if ("content".equals(mData.getScheme())) {
5652                return resolver.getType(mData);
5653            }
5654        }
5655        return null;
5656    }
5657
5658    /**
5659     * Return the MIME data type of this intent, only if it will be needed for
5660     * intent resolution.  This is not generally useful for application code;
5661     * it is used by the frameworks for communicating with back-end system
5662     * services.
5663     *
5664     * @param resolver A ContentResolver that can be used to determine the MIME
5665     *                 type of the intent's data.
5666     *
5667     * @return The MIME type of this intent, or null if it is unknown or not
5668     *         needed.
5669     */
5670    public String resolveTypeIfNeeded(ContentResolver resolver) {
5671        if (mComponent != null) {
5672            return mType;
5673        }
5674        return resolveType(resolver);
5675    }
5676
5677    /**
5678     * Check if a category exists in the intent.
5679     *
5680     * @param category The category to check.
5681     *
5682     * @return boolean True if the intent contains the category, else false.
5683     *
5684     * @see #getCategories
5685     * @see #addCategory
5686     */
5687    public boolean hasCategory(String category) {
5688        return mCategories != null && mCategories.contains(category);
5689    }
5690
5691    /**
5692     * Return the set of all categories in the intent.  If there are no categories,
5693     * returns NULL.
5694     *
5695     * @return The set of categories you can examine.  Do not modify!
5696     *
5697     * @see #hasCategory
5698     * @see #addCategory
5699     */
5700    public Set<String> getCategories() {
5701        return mCategories;
5702    }
5703
5704    /**
5705     * Return the specific selector associated with this Intent.  If there is
5706     * none, returns null.  See {@link #setSelector} for more information.
5707     *
5708     * @see #setSelector
5709     */
5710    public Intent getSelector() {
5711        return mSelector;
5712    }
5713
5714    /**
5715     * Return the {@link ClipData} associated with this Intent.  If there is
5716     * none, returns null.  See {@link #setClipData} for more information.
5717     *
5718     * @see #setClipData
5719     */
5720    public ClipData getClipData() {
5721        return mClipData;
5722    }
5723
5724    /** @hide */
5725    public int getContentUserHint() {
5726        return mContentUserHint;
5727    }
5728
5729    /**
5730     * Sets the ClassLoader that will be used when unmarshalling
5731     * any Parcelable values from the extras of this Intent.
5732     *
5733     * @param loader a ClassLoader, or null to use the default loader
5734     * at the time of unmarshalling.
5735     */
5736    public void setExtrasClassLoader(ClassLoader loader) {
5737        if (mExtras != null) {
5738            mExtras.setClassLoader(loader);
5739        }
5740    }
5741
5742    /**
5743     * Returns true if an extra value is associated with the given name.
5744     * @param name the extra's name
5745     * @return true if the given extra is present.
5746     */
5747    public boolean hasExtra(String name) {
5748        return mExtras != null && mExtras.containsKey(name);
5749    }
5750
5751    /**
5752     * Returns true if the Intent's extras contain a parcelled file descriptor.
5753     * @return true if the Intent contains a parcelled file descriptor.
5754     */
5755    public boolean hasFileDescriptors() {
5756        return mExtras != null && mExtras.hasFileDescriptors();
5757    }
5758
5759    /** @hide */
5760    public void setAllowFds(boolean allowFds) {
5761        if (mExtras != null) {
5762            mExtras.setAllowFds(allowFds);
5763        }
5764    }
5765
5766    /**
5767     * Retrieve extended data from the intent.
5768     *
5769     * @param name The name of the desired item.
5770     *
5771     * @return the value of an item that previously added with putExtra()
5772     * or null if none was found.
5773     *
5774     * @deprecated
5775     * @hide
5776     */
5777    @Deprecated
5778    public Object getExtra(String name) {
5779        return getExtra(name, null);
5780    }
5781
5782    /**
5783     * Retrieve extended data from the intent.
5784     *
5785     * @param name The name of the desired item.
5786     * @param defaultValue the value to be returned if no value of the desired
5787     * type is stored with the given name.
5788     *
5789     * @return the value of an item that previously added with putExtra()
5790     * or the default value if none was found.
5791     *
5792     * @see #putExtra(String, boolean)
5793     */
5794    public boolean getBooleanExtra(String name, boolean defaultValue) {
5795        return mExtras == null ? defaultValue :
5796            mExtras.getBoolean(name, defaultValue);
5797    }
5798
5799    /**
5800     * Retrieve extended data from the intent.
5801     *
5802     * @param name The name of the desired item.
5803     * @param defaultValue the value to be returned if no value of the desired
5804     * type is stored with the given name.
5805     *
5806     * @return the value of an item that previously added with putExtra()
5807     * or the default value if none was found.
5808     *
5809     * @see #putExtra(String, byte)
5810     */
5811    public byte getByteExtra(String name, byte defaultValue) {
5812        return mExtras == null ? defaultValue :
5813            mExtras.getByte(name, defaultValue);
5814    }
5815
5816    /**
5817     * Retrieve extended data from the intent.
5818     *
5819     * @param name The name of the desired item.
5820     * @param defaultValue the value to be returned if no value of the desired
5821     * type is stored with the given name.
5822     *
5823     * @return the value of an item that previously added with putExtra()
5824     * or the default value if none was found.
5825     *
5826     * @see #putExtra(String, short)
5827     */
5828    public short getShortExtra(String name, short defaultValue) {
5829        return mExtras == null ? defaultValue :
5830            mExtras.getShort(name, defaultValue);
5831    }
5832
5833    /**
5834     * Retrieve extended data from the intent.
5835     *
5836     * @param name The name of the desired item.
5837     * @param defaultValue the value to be returned if no value of the desired
5838     * type is stored with the given name.
5839     *
5840     * @return the value of an item that previously added with putExtra()
5841     * or the default value if none was found.
5842     *
5843     * @see #putExtra(String, char)
5844     */
5845    public char getCharExtra(String name, char defaultValue) {
5846        return mExtras == null ? defaultValue :
5847            mExtras.getChar(name, defaultValue);
5848    }
5849
5850    /**
5851     * Retrieve extended data from the intent.
5852     *
5853     * @param name The name of the desired item.
5854     * @param defaultValue the value to be returned if no value of the desired
5855     * type is stored with the given name.
5856     *
5857     * @return the value of an item that previously added with putExtra()
5858     * or the default value if none was found.
5859     *
5860     * @see #putExtra(String, int)
5861     */
5862    public int getIntExtra(String name, int defaultValue) {
5863        return mExtras == null ? defaultValue :
5864            mExtras.getInt(name, defaultValue);
5865    }
5866
5867    /**
5868     * Retrieve extended data from the intent.
5869     *
5870     * @param name The name of the desired item.
5871     * @param defaultValue the value to be returned if no value of the desired
5872     * type is stored with the given name.
5873     *
5874     * @return the value of an item that previously added with putExtra()
5875     * or the default value if none was found.
5876     *
5877     * @see #putExtra(String, long)
5878     */
5879    public long getLongExtra(String name, long defaultValue) {
5880        return mExtras == null ? defaultValue :
5881            mExtras.getLong(name, defaultValue);
5882    }
5883
5884    /**
5885     * Retrieve extended data from the intent.
5886     *
5887     * @param name The name of the desired item.
5888     * @param defaultValue the value to be returned if no value of the desired
5889     * type is stored with the given name.
5890     *
5891     * @return the value of an item that previously added with putExtra(),
5892     * or the default value if no such item is present
5893     *
5894     * @see #putExtra(String, float)
5895     */
5896    public float getFloatExtra(String name, float defaultValue) {
5897        return mExtras == null ? defaultValue :
5898            mExtras.getFloat(name, defaultValue);
5899    }
5900
5901    /**
5902     * Retrieve extended data from the intent.
5903     *
5904     * @param name The name of the desired item.
5905     * @param defaultValue the value to be returned if no value of the desired
5906     * type is stored with the given name.
5907     *
5908     * @return the value of an item that previously added with putExtra()
5909     * or the default value if none was found.
5910     *
5911     * @see #putExtra(String, double)
5912     */
5913    public double getDoubleExtra(String name, double defaultValue) {
5914        return mExtras == null ? defaultValue :
5915            mExtras.getDouble(name, defaultValue);
5916    }
5917
5918    /**
5919     * Retrieve extended data from the intent.
5920     *
5921     * @param name The name of the desired item.
5922     *
5923     * @return the value of an item that previously added with putExtra()
5924     * or null if no String value was found.
5925     *
5926     * @see #putExtra(String, String)
5927     */
5928    public String getStringExtra(String name) {
5929        return mExtras == null ? null : mExtras.getString(name);
5930    }
5931
5932    /**
5933     * Retrieve extended data from the intent.
5934     *
5935     * @param name The name of the desired item.
5936     *
5937     * @return the value of an item that previously added with putExtra()
5938     * or null if no CharSequence value was found.
5939     *
5940     * @see #putExtra(String, CharSequence)
5941     */
5942    public CharSequence getCharSequenceExtra(String name) {
5943        return mExtras == null ? null : mExtras.getCharSequence(name);
5944    }
5945
5946    /**
5947     * Retrieve extended data from the intent.
5948     *
5949     * @param name The name of the desired item.
5950     *
5951     * @return the value of an item that previously added with putExtra()
5952     * or null if no Parcelable value was found.
5953     *
5954     * @see #putExtra(String, Parcelable)
5955     */
5956    public <T extends Parcelable> T getParcelableExtra(String name) {
5957        return mExtras == null ? null : mExtras.<T>getParcelable(name);
5958    }
5959
5960    /**
5961     * Retrieve extended data from the intent.
5962     *
5963     * @param name The name of the desired item.
5964     *
5965     * @return the value of an item that previously added with putExtra()
5966     * or null if no Parcelable[] value was found.
5967     *
5968     * @see #putExtra(String, Parcelable[])
5969     */
5970    public Parcelable[] getParcelableArrayExtra(String name) {
5971        return mExtras == null ? null : mExtras.getParcelableArray(name);
5972    }
5973
5974    /**
5975     * Retrieve extended data from the intent.
5976     *
5977     * @param name The name of the desired item.
5978     *
5979     * @return the value of an item that previously added with putExtra()
5980     * or null if no ArrayList<Parcelable> value was found.
5981     *
5982     * @see #putParcelableArrayListExtra(String, ArrayList)
5983     */
5984    public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
5985        return mExtras == null ? null : mExtras.<T>getParcelableArrayList(name);
5986    }
5987
5988    /**
5989     * Retrieve extended data from the intent.
5990     *
5991     * @param name The name of the desired item.
5992     *
5993     * @return the value of an item that previously added with putExtra()
5994     * or null if no Serializable value was found.
5995     *
5996     * @see #putExtra(String, Serializable)
5997     */
5998    public Serializable getSerializableExtra(String name) {
5999        return mExtras == null ? null : mExtras.getSerializable(name);
6000    }
6001
6002    /**
6003     * Retrieve extended data from the intent.
6004     *
6005     * @param name The name of the desired item.
6006     *
6007     * @return the value of an item that previously added with putExtra()
6008     * or null if no ArrayList<Integer> value was found.
6009     *
6010     * @see #putIntegerArrayListExtra(String, ArrayList)
6011     */
6012    public ArrayList<Integer> getIntegerArrayListExtra(String name) {
6013        return mExtras == null ? null : mExtras.getIntegerArrayList(name);
6014    }
6015
6016    /**
6017     * Retrieve extended data from the intent.
6018     *
6019     * @param name The name of the desired item.
6020     *
6021     * @return the value of an item that previously added with putExtra()
6022     * or null if no ArrayList<String> value was found.
6023     *
6024     * @see #putStringArrayListExtra(String, ArrayList)
6025     */
6026    public ArrayList<String> getStringArrayListExtra(String name) {
6027        return mExtras == null ? null : mExtras.getStringArrayList(name);
6028    }
6029
6030    /**
6031     * Retrieve extended data from the intent.
6032     *
6033     * @param name The name of the desired item.
6034     *
6035     * @return the value of an item that previously added with putExtra()
6036     * or null if no ArrayList<CharSequence> value was found.
6037     *
6038     * @see #putCharSequenceArrayListExtra(String, ArrayList)
6039     */
6040    public ArrayList<CharSequence> getCharSequenceArrayListExtra(String name) {
6041        return mExtras == null ? null : mExtras.getCharSequenceArrayList(name);
6042    }
6043
6044    /**
6045     * Retrieve extended data from the intent.
6046     *
6047     * @param name The name of the desired item.
6048     *
6049     * @return the value of an item that previously added with putExtra()
6050     * or null if no boolean array value was found.
6051     *
6052     * @see #putExtra(String, boolean[])
6053     */
6054    public boolean[] getBooleanArrayExtra(String name) {
6055        return mExtras == null ? null : mExtras.getBooleanArray(name);
6056    }
6057
6058    /**
6059     * Retrieve extended data from the intent.
6060     *
6061     * @param name The name of the desired item.
6062     *
6063     * @return the value of an item that previously added with putExtra()
6064     * or null if no byte array value was found.
6065     *
6066     * @see #putExtra(String, byte[])
6067     */
6068    public byte[] getByteArrayExtra(String name) {
6069        return mExtras == null ? null : mExtras.getByteArray(name);
6070    }
6071
6072    /**
6073     * Retrieve extended data from the intent.
6074     *
6075     * @param name The name of the desired item.
6076     *
6077     * @return the value of an item that previously added with putExtra()
6078     * or null if no short array value was found.
6079     *
6080     * @see #putExtra(String, short[])
6081     */
6082    public short[] getShortArrayExtra(String name) {
6083        return mExtras == null ? null : mExtras.getShortArray(name);
6084    }
6085
6086    /**
6087     * Retrieve extended data from the intent.
6088     *
6089     * @param name The name of the desired item.
6090     *
6091     * @return the value of an item that previously added with putExtra()
6092     * or null if no char array value was found.
6093     *
6094     * @see #putExtra(String, char[])
6095     */
6096    public char[] getCharArrayExtra(String name) {
6097        return mExtras == null ? null : mExtras.getCharArray(name);
6098    }
6099
6100    /**
6101     * Retrieve extended data from the intent.
6102     *
6103     * @param name The name of the desired item.
6104     *
6105     * @return the value of an item that previously added with putExtra()
6106     * or null if no int array value was found.
6107     *
6108     * @see #putExtra(String, int[])
6109     */
6110    public int[] getIntArrayExtra(String name) {
6111        return mExtras == null ? null : mExtras.getIntArray(name);
6112    }
6113
6114    /**
6115     * Retrieve extended data from the intent.
6116     *
6117     * @param name The name of the desired item.
6118     *
6119     * @return the value of an item that previously added with putExtra()
6120     * or null if no long array value was found.
6121     *
6122     * @see #putExtra(String, long[])
6123     */
6124    public long[] getLongArrayExtra(String name) {
6125        return mExtras == null ? null : mExtras.getLongArray(name);
6126    }
6127
6128    /**
6129     * Retrieve extended data from the intent.
6130     *
6131     * @param name The name of the desired item.
6132     *
6133     * @return the value of an item that previously added with putExtra()
6134     * or null if no float array value was found.
6135     *
6136     * @see #putExtra(String, float[])
6137     */
6138    public float[] getFloatArrayExtra(String name) {
6139        return mExtras == null ? null : mExtras.getFloatArray(name);
6140    }
6141
6142    /**
6143     * Retrieve extended data from the intent.
6144     *
6145     * @param name The name of the desired item.
6146     *
6147     * @return the value of an item that previously added with putExtra()
6148     * or null if no double array value was found.
6149     *
6150     * @see #putExtra(String, double[])
6151     */
6152    public double[] getDoubleArrayExtra(String name) {
6153        return mExtras == null ? null : mExtras.getDoubleArray(name);
6154    }
6155
6156    /**
6157     * Retrieve extended data from the intent.
6158     *
6159     * @param name The name of the desired item.
6160     *
6161     * @return the value of an item that previously added with putExtra()
6162     * or null if no String array value was found.
6163     *
6164     * @see #putExtra(String, String[])
6165     */
6166    public String[] getStringArrayExtra(String name) {
6167        return mExtras == null ? null : mExtras.getStringArray(name);
6168    }
6169
6170    /**
6171     * Retrieve extended data from the intent.
6172     *
6173     * @param name The name of the desired item.
6174     *
6175     * @return the value of an item that previously added with putExtra()
6176     * or null if no CharSequence array value was found.
6177     *
6178     * @see #putExtra(String, CharSequence[])
6179     */
6180    public CharSequence[] getCharSequenceArrayExtra(String name) {
6181        return mExtras == null ? null : mExtras.getCharSequenceArray(name);
6182    }
6183
6184    /**
6185     * Retrieve extended data from the intent.
6186     *
6187     * @param name The name of the desired item.
6188     *
6189     * @return the value of an item that previously added with putExtra()
6190     * or null if no Bundle value was found.
6191     *
6192     * @see #putExtra(String, Bundle)
6193     */
6194    public Bundle getBundleExtra(String name) {
6195        return mExtras == null ? null : mExtras.getBundle(name);
6196    }
6197
6198    /**
6199     * Retrieve extended data from the intent.
6200     *
6201     * @param name The name of the desired item.
6202     *
6203     * @return the value of an item that previously added with putExtra()
6204     * or null if no IBinder value was found.
6205     *
6206     * @see #putExtra(String, IBinder)
6207     *
6208     * @deprecated
6209     * @hide
6210     */
6211    @Deprecated
6212    public IBinder getIBinderExtra(String name) {
6213        return mExtras == null ? null : mExtras.getIBinder(name);
6214    }
6215
6216    /**
6217     * Retrieve extended data from the intent.
6218     *
6219     * @param name The name of the desired item.
6220     * @param defaultValue The default value to return in case no item is
6221     * associated with the key 'name'
6222     *
6223     * @return the value of an item that previously added with putExtra()
6224     * or defaultValue if none was found.
6225     *
6226     * @see #putExtra
6227     *
6228     * @deprecated
6229     * @hide
6230     */
6231    @Deprecated
6232    public Object getExtra(String name, Object defaultValue) {
6233        Object result = defaultValue;
6234        if (mExtras != null) {
6235            Object result2 = mExtras.get(name);
6236            if (result2 != null) {
6237                result = result2;
6238            }
6239        }
6240
6241        return result;
6242    }
6243
6244    /**
6245     * Retrieves a map of extended data from the intent.
6246     *
6247     * @return the map of all extras previously added with putExtra(),
6248     * or null if none have been added.
6249     */
6250    public Bundle getExtras() {
6251        return (mExtras != null)
6252                ? new Bundle(mExtras)
6253                : null;
6254    }
6255
6256    /**
6257     * Filter extras to only basic types.
6258     * @hide
6259     */
6260    public void removeUnsafeExtras() {
6261        if (mExtras != null) {
6262            mExtras.filterValues();
6263        }
6264    }
6265
6266    /**
6267     * Retrieve any special flags associated with this intent.  You will
6268     * normally just set them with {@link #setFlags} and let the system
6269     * take the appropriate action with them.
6270     *
6271     * @return int The currently set flags.
6272     *
6273     * @see #setFlags
6274     */
6275    public int getFlags() {
6276        return mFlags;
6277    }
6278
6279    /** @hide */
6280    public boolean isExcludingStopped() {
6281        return (mFlags&(FLAG_EXCLUDE_STOPPED_PACKAGES|FLAG_INCLUDE_STOPPED_PACKAGES))
6282                == FLAG_EXCLUDE_STOPPED_PACKAGES;
6283    }
6284
6285    /**
6286     * Retrieve the application package name this Intent is limited to.  When
6287     * resolving an Intent, if non-null this limits the resolution to only
6288     * components in the given application package.
6289     *
6290     * @return The name of the application package for the Intent.
6291     *
6292     * @see #resolveActivity
6293     * @see #setPackage
6294     */
6295    public String getPackage() {
6296        return mPackage;
6297    }
6298
6299    /**
6300     * Retrieve the concrete component associated with the intent.  When receiving
6301     * an intent, this is the component that was found to best handle it (that is,
6302     * yourself) and will always be non-null; in all other cases it will be
6303     * null unless explicitly set.
6304     *
6305     * @return The name of the application component to handle the intent.
6306     *
6307     * @see #resolveActivity
6308     * @see #setComponent
6309     */
6310    public ComponentName getComponent() {
6311        return mComponent;
6312    }
6313
6314    /**
6315     * Get the bounds of the sender of this intent, in screen coordinates.  This can be
6316     * used as a hint to the receiver for animations and the like.  Null means that there
6317     * is no source bounds.
6318     */
6319    public Rect getSourceBounds() {
6320        return mSourceBounds;
6321    }
6322
6323    /**
6324     * Return the Activity component that should be used to handle this intent.
6325     * The appropriate component is determined based on the information in the
6326     * intent, evaluated as follows:
6327     *
6328     * <p>If {@link #getComponent} returns an explicit class, that is returned
6329     * without any further consideration.
6330     *
6331     * <p>The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent
6332     * category to be considered.
6333     *
6334     * <p>If {@link #getAction} is non-NULL, the activity must handle this
6335     * action.
6336     *
6337     * <p>If {@link #resolveType} returns non-NULL, the activity must handle
6338     * this type.
6339     *
6340     * <p>If {@link #addCategory} has added any categories, the activity must
6341     * handle ALL of the categories specified.
6342     *
6343     * <p>If {@link #getPackage} is non-NULL, only activity components in
6344     * that application package will be considered.
6345     *
6346     * <p>If there are no activities that satisfy all of these conditions, a
6347     * null string is returned.
6348     *
6349     * <p>If multiple activities are found to satisfy the intent, the one with
6350     * the highest priority will be used.  If there are multiple activities
6351     * with the same priority, the system will either pick the best activity
6352     * based on user preference, or resolve to a system class that will allow
6353     * the user to pick an activity and forward from there.
6354     *
6355     * <p>This method is implemented simply by calling
6356     * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter
6357     * true.</p>
6358     * <p> This API is called for you as part of starting an activity from an
6359     * intent.  You do not normally need to call it yourself.</p>
6360     *
6361     * @param pm The package manager with which to resolve the Intent.
6362     *
6363     * @return Name of the component implementing an activity that can
6364     *         display the intent.
6365     *
6366     * @see #setComponent
6367     * @see #getComponent
6368     * @see #resolveActivityInfo
6369     */
6370    public ComponentName resolveActivity(PackageManager pm) {
6371        if (mComponent != null) {
6372            return mComponent;
6373        }
6374
6375        ResolveInfo info = pm.resolveActivity(
6376            this, PackageManager.MATCH_DEFAULT_ONLY);
6377        if (info != null) {
6378            return new ComponentName(
6379                    info.activityInfo.applicationInfo.packageName,
6380                    info.activityInfo.name);
6381        }
6382
6383        return null;
6384    }
6385
6386    /**
6387     * Resolve the Intent into an {@link ActivityInfo}
6388     * describing the activity that should execute the intent.  Resolution
6389     * follows the same rules as described for {@link #resolveActivity}, but
6390     * you get back the completely information about the resolved activity
6391     * instead of just its class name.
6392     *
6393     * @param pm The package manager with which to resolve the Intent.
6394     * @param flags Addition information to retrieve as per
6395     * {@link PackageManager#getActivityInfo(ComponentName, int)
6396     * PackageManager.getActivityInfo()}.
6397     *
6398     * @return PackageManager.ActivityInfo
6399     *
6400     * @see #resolveActivity
6401     */
6402    public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) {
6403        ActivityInfo ai = null;
6404        if (mComponent != null) {
6405            try {
6406                ai = pm.getActivityInfo(mComponent, flags);
6407            } catch (PackageManager.NameNotFoundException e) {
6408                // ignore
6409            }
6410        } else {
6411            ResolveInfo info = pm.resolveActivity(
6412                this, PackageManager.MATCH_DEFAULT_ONLY | flags);
6413            if (info != null) {
6414                ai = info.activityInfo;
6415            }
6416        }
6417
6418        return ai;
6419    }
6420
6421    /**
6422     * Special function for use by the system to resolve service
6423     * intents to system apps.  Throws an exception if there are
6424     * multiple potential matches to the Intent.  Returns null if
6425     * there are no matches.
6426     * @hide
6427     */
6428    public ComponentName resolveSystemService(PackageManager pm, int flags) {
6429        if (mComponent != null) {
6430            return mComponent;
6431        }
6432
6433        List<ResolveInfo> results = pm.queryIntentServices(this, flags);
6434        if (results == null) {
6435            return null;
6436        }
6437        ComponentName comp = null;
6438        for (int i=0; i<results.size(); i++) {
6439            ResolveInfo ri = results.get(i);
6440            if ((ri.serviceInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
6441                continue;
6442            }
6443            ComponentName foundComp = new ComponentName(ri.serviceInfo.applicationInfo.packageName,
6444                    ri.serviceInfo.name);
6445            if (comp != null) {
6446                throw new IllegalStateException("Multiple system services handle " + this
6447                        + ": " + comp + ", " + foundComp);
6448            }
6449            comp = foundComp;
6450        }
6451        return comp;
6452    }
6453
6454    /**
6455     * Set the general action to be performed.
6456     *
6457     * @param action An action name, such as ACTION_VIEW.  Application-specific
6458     *               actions should be prefixed with the vendor's package name.
6459     *
6460     * @return Returns the same Intent object, for chaining multiple calls
6461     * into a single statement.
6462     *
6463     * @see #getAction
6464     */
6465    public Intent setAction(String action) {
6466        mAction = action != null ? action.intern() : null;
6467        return this;
6468    }
6469
6470    /**
6471     * Set the data this intent is operating on.  This method automatically
6472     * clears any type that was previously set by {@link #setType} or
6473     * {@link #setTypeAndNormalize}.
6474     *
6475     * <p><em>Note: scheme matching in the Android framework is
6476     * case-sensitive, unlike the formal RFC. As a result,
6477     * you should always write your Uri with a lower case scheme,
6478     * or use {@link Uri#normalizeScheme} or
6479     * {@link #setDataAndNormalize}
6480     * to ensure that the scheme is converted to lower case.</em>
6481     *
6482     * @param data The Uri of the data this intent is now targeting.
6483     *
6484     * @return Returns the same Intent object, for chaining multiple calls
6485     * into a single statement.
6486     *
6487     * @see #getData
6488     * @see #setDataAndNormalize
6489     * @see android.net.Uri#normalizeScheme()
6490     */
6491    public Intent setData(Uri data) {
6492        mData = data;
6493        mType = null;
6494        return this;
6495    }
6496
6497    /**
6498     * Normalize and set the data this intent is operating on.
6499     *
6500     * <p>This method automatically clears any type that was
6501     * previously set (for example, by {@link #setType}).
6502     *
6503     * <p>The data Uri is normalized using
6504     * {@link android.net.Uri#normalizeScheme} before it is set,
6505     * so really this is just a convenience method for
6506     * <pre>
6507     * setData(data.normalize())
6508     * </pre>
6509     *
6510     * @param data The Uri of the data this intent is now targeting.
6511     *
6512     * @return Returns the same Intent object, for chaining multiple calls
6513     * into a single statement.
6514     *
6515     * @see #getData
6516     * @see #setType
6517     * @see android.net.Uri#normalizeScheme
6518     */
6519    public Intent setDataAndNormalize(Uri data) {
6520        return setData(data.normalizeScheme());
6521    }
6522
6523    /**
6524     * Set an explicit MIME data type.
6525     *
6526     * <p>This is used to create intents that only specify a type and not data,
6527     * for example to indicate the type of data to return.
6528     *
6529     * <p>This method automatically clears any data that was
6530     * previously set (for example by {@link #setData}).
6531     *
6532     * <p><em>Note: MIME type matching in the Android framework is
6533     * case-sensitive, unlike formal RFC MIME types.  As a result,
6534     * you should always write your MIME types with lower case letters,
6535     * or use {@link #normalizeMimeType} or {@link #setTypeAndNormalize}
6536     * to ensure that it is converted to lower case.</em>
6537     *
6538     * @param type The MIME type of the data being handled by this intent.
6539     *
6540     * @return Returns the same Intent object, for chaining multiple calls
6541     * into a single statement.
6542     *
6543     * @see #getType
6544     * @see #setTypeAndNormalize
6545     * @see #setDataAndType
6546     * @see #normalizeMimeType
6547     */
6548    public Intent setType(String type) {
6549        mData = null;
6550        mType = type;
6551        return this;
6552    }
6553
6554    /**
6555     * Normalize and set an explicit MIME data type.
6556     *
6557     * <p>This is used to create intents that only specify a type and not data,
6558     * for example to indicate the type of data to return.
6559     *
6560     * <p>This method automatically clears any data that was
6561     * previously set (for example by {@link #setData}).
6562     *
6563     * <p>The MIME type is normalized using
6564     * {@link #normalizeMimeType} before it is set,
6565     * so really this is just a convenience method for
6566     * <pre>
6567     * setType(Intent.normalizeMimeType(type))
6568     * </pre>
6569     *
6570     * @param type The MIME type of the data being handled by this intent.
6571     *
6572     * @return Returns the same Intent object, for chaining multiple calls
6573     * into a single statement.
6574     *
6575     * @see #getType
6576     * @see #setData
6577     * @see #normalizeMimeType
6578     */
6579    public Intent setTypeAndNormalize(String type) {
6580        return setType(normalizeMimeType(type));
6581    }
6582
6583    /**
6584     * (Usually optional) Set the data for the intent along with an explicit
6585     * MIME data type.  This method should very rarely be used -- it allows you
6586     * to override the MIME type that would ordinarily be inferred from the
6587     * data with your own type given here.
6588     *
6589     * <p><em>Note: MIME type and Uri scheme matching in the
6590     * Android framework is case-sensitive, unlike the formal RFC definitions.
6591     * As a result, you should always write these elements with lower case letters,
6592     * or use {@link #normalizeMimeType} or {@link android.net.Uri#normalizeScheme} or
6593     * {@link #setDataAndTypeAndNormalize}
6594     * to ensure that they are converted to lower case.</em>
6595     *
6596     * @param data The Uri of the data this intent is now targeting.
6597     * @param type The MIME type of the data being handled by this intent.
6598     *
6599     * @return Returns the same Intent object, for chaining multiple calls
6600     * into a single statement.
6601     *
6602     * @see #setType
6603     * @see #setData
6604     * @see #normalizeMimeType
6605     * @see android.net.Uri#normalizeScheme
6606     * @see #setDataAndTypeAndNormalize
6607     */
6608    public Intent setDataAndType(Uri data, String type) {
6609        mData = data;
6610        mType = type;
6611        return this;
6612    }
6613
6614    /**
6615     * (Usually optional) Normalize and set both the data Uri and an explicit
6616     * MIME data type.  This method should very rarely be used -- it allows you
6617     * to override the MIME type that would ordinarily be inferred from the
6618     * data with your own type given here.
6619     *
6620     * <p>The data Uri and the MIME type are normalize using
6621     * {@link android.net.Uri#normalizeScheme} and {@link #normalizeMimeType}
6622     * before they are set, so really this is just a convenience method for
6623     * <pre>
6624     * setDataAndType(data.normalize(), Intent.normalizeMimeType(type))
6625     * </pre>
6626     *
6627     * @param data The Uri of the data this intent is now targeting.
6628     * @param type The MIME type of the data being handled by this intent.
6629     *
6630     * @return Returns the same Intent object, for chaining multiple calls
6631     * into a single statement.
6632     *
6633     * @see #setType
6634     * @see #setData
6635     * @see #setDataAndType
6636     * @see #normalizeMimeType
6637     * @see android.net.Uri#normalizeScheme
6638     */
6639    public Intent setDataAndTypeAndNormalize(Uri data, String type) {
6640        return setDataAndType(data.normalizeScheme(), normalizeMimeType(type));
6641    }
6642
6643    /**
6644     * Add a new category to the intent.  Categories provide additional detail
6645     * about the action the intent performs.  When resolving an intent, only
6646     * activities that provide <em>all</em> of the requested categories will be
6647     * used.
6648     *
6649     * @param category The desired category.  This can be either one of the
6650     *               predefined Intent categories, or a custom category in your own
6651     *               namespace.
6652     *
6653     * @return Returns the same Intent object, for chaining multiple calls
6654     * into a single statement.
6655     *
6656     * @see #hasCategory
6657     * @see #removeCategory
6658     */
6659    public Intent addCategory(String category) {
6660        if (mCategories == null) {
6661            mCategories = new ArraySet<String>();
6662        }
6663        mCategories.add(category.intern());
6664        return this;
6665    }
6666
6667    /**
6668     * Remove a category from an intent.
6669     *
6670     * @param category The category to remove.
6671     *
6672     * @see #addCategory
6673     */
6674    public void removeCategory(String category) {
6675        if (mCategories != null) {
6676            mCategories.remove(category);
6677            if (mCategories.size() == 0) {
6678                mCategories = null;
6679            }
6680        }
6681    }
6682
6683    /**
6684     * Set a selector for this Intent.  This is a modification to the kinds of
6685     * things the Intent will match.  If the selector is set, it will be used
6686     * when trying to find entities that can handle the Intent, instead of the
6687     * main contents of the Intent.  This allows you build an Intent containing
6688     * a generic protocol while targeting it more specifically.
6689     *
6690     * <p>An example of where this may be used is with things like
6691     * {@link #CATEGORY_APP_BROWSER}.  This category allows you to build an
6692     * Intent that will launch the Browser application.  However, the correct
6693     * main entry point of an application is actually {@link #ACTION_MAIN}
6694     * {@link #CATEGORY_LAUNCHER} with {@link #setComponent(ComponentName)}
6695     * used to specify the actual Activity to launch.  If you launch the browser
6696     * with something different, undesired behavior may happen if the user has
6697     * previously or later launches it the normal way, since they do not match.
6698     * Instead, you can build an Intent with the MAIN action (but no ComponentName
6699     * yet specified) and set a selector with {@link #ACTION_MAIN} and
6700     * {@link #CATEGORY_APP_BROWSER} to point it specifically to the browser activity.
6701     *
6702     * <p>Setting a selector does not impact the behavior of
6703     * {@link #filterEquals(Intent)} and {@link #filterHashCode()}.  This is part of the
6704     * desired behavior of a selector -- it does not impact the base meaning
6705     * of the Intent, just what kinds of things will be matched against it
6706     * when determining who can handle it.</p>
6707     *
6708     * <p>You can not use both a selector and {@link #setPackage(String)} on
6709     * the same base Intent.</p>
6710     *
6711     * @param selector The desired selector Intent; set to null to not use
6712     * a special selector.
6713     */
6714    public void setSelector(Intent selector) {
6715        if (selector == this) {
6716            throw new IllegalArgumentException(
6717                    "Intent being set as a selector of itself");
6718        }
6719        if (selector != null && mPackage != null) {
6720            throw new IllegalArgumentException(
6721                    "Can't set selector when package name is already set");
6722        }
6723        mSelector = selector;
6724    }
6725
6726    /**
6727     * Set a {@link ClipData} associated with this Intent.  This replaces any
6728     * previously set ClipData.
6729     *
6730     * <p>The ClipData in an intent is not used for Intent matching or other
6731     * such operations.  Semantically it is like extras, used to transmit
6732     * additional data with the Intent.  The main feature of using this over
6733     * the extras for data is that {@link #FLAG_GRANT_READ_URI_PERMISSION}
6734     * and {@link #FLAG_GRANT_WRITE_URI_PERMISSION} will operate on any URI
6735     * items included in the clip data.  This is useful, in particular, if
6736     * you want to transmit an Intent containing multiple <code>content:</code>
6737     * URIs for which the recipient may not have global permission to access the
6738     * content provider.
6739     *
6740     * <p>If the ClipData contains items that are themselves Intents, any
6741     * grant flags in those Intents will be ignored.  Only the top-level flags
6742     * of the main Intent are respected, and will be applied to all Uri or
6743     * Intent items in the clip (or sub-items of the clip).
6744     *
6745     * <p>The MIME type, label, and icon in the ClipData object are not
6746     * directly used by Intent.  Applications should generally rely on the
6747     * MIME type of the Intent itself, not what it may find in the ClipData.
6748     * A common practice is to construct a ClipData for use with an Intent
6749     * with a MIME type of "*&#47;*".
6750     *
6751     * @param clip The new clip to set.  May be null to clear the current clip.
6752     */
6753    public void setClipData(ClipData clip) {
6754        mClipData = clip;
6755    }
6756
6757    /**
6758     * This is NOT a secure mechanism to identify the user who sent the intent.
6759     * When the intent is sent to a different user, it is used to fix uris by adding the userId
6760     * who sent the intent.
6761     * @hide
6762     */
6763    public void prepareToLeaveUser(int userId) {
6764        // If mContentUserHint is not UserHandle.USER_CURRENT, the intent has already left a user.
6765        // We want mContentUserHint to refer to the original user, so don't do anything.
6766        if (mContentUserHint == UserHandle.USER_CURRENT) {
6767            mContentUserHint = userId;
6768        }
6769    }
6770
6771    /**
6772     * Add extended data to the intent.  The name must include a package
6773     * prefix, for example the app com.android.contacts would use names
6774     * like "com.android.contacts.ShowAll".
6775     *
6776     * @param name The name of the extra data, with package prefix.
6777     * @param value The boolean data value.
6778     *
6779     * @return Returns the same Intent object, for chaining multiple calls
6780     * into a single statement.
6781     *
6782     * @see #putExtras
6783     * @see #removeExtra
6784     * @see #getBooleanExtra(String, boolean)
6785     */
6786    public Intent putExtra(String name, boolean value) {
6787        if (mExtras == null) {
6788            mExtras = new Bundle();
6789        }
6790        mExtras.putBoolean(name, value);
6791        return this;
6792    }
6793
6794    /**
6795     * Add extended data to the intent.  The name must include a package
6796     * prefix, for example the app com.android.contacts would use names
6797     * like "com.android.contacts.ShowAll".
6798     *
6799     * @param name The name of the extra data, with package prefix.
6800     * @param value The byte data value.
6801     *
6802     * @return Returns the same Intent object, for chaining multiple calls
6803     * into a single statement.
6804     *
6805     * @see #putExtras
6806     * @see #removeExtra
6807     * @see #getByteExtra(String, byte)
6808     */
6809    public Intent putExtra(String name, byte value) {
6810        if (mExtras == null) {
6811            mExtras = new Bundle();
6812        }
6813        mExtras.putByte(name, value);
6814        return this;
6815    }
6816
6817    /**
6818     * Add extended data to the intent.  The name must include a package
6819     * prefix, for example the app com.android.contacts would use names
6820     * like "com.android.contacts.ShowAll".
6821     *
6822     * @param name The name of the extra data, with package prefix.
6823     * @param value The char data value.
6824     *
6825     * @return Returns the same Intent object, for chaining multiple calls
6826     * into a single statement.
6827     *
6828     * @see #putExtras
6829     * @see #removeExtra
6830     * @see #getCharExtra(String, char)
6831     */
6832    public Intent putExtra(String name, char value) {
6833        if (mExtras == null) {
6834            mExtras = new Bundle();
6835        }
6836        mExtras.putChar(name, value);
6837        return this;
6838    }
6839
6840    /**
6841     * Add extended data to the intent.  The name must include a package
6842     * prefix, for example the app com.android.contacts would use names
6843     * like "com.android.contacts.ShowAll".
6844     *
6845     * @param name The name of the extra data, with package prefix.
6846     * @param value The short data value.
6847     *
6848     * @return Returns the same Intent object, for chaining multiple calls
6849     * into a single statement.
6850     *
6851     * @see #putExtras
6852     * @see #removeExtra
6853     * @see #getShortExtra(String, short)
6854     */
6855    public Intent putExtra(String name, short value) {
6856        if (mExtras == null) {
6857            mExtras = new Bundle();
6858        }
6859        mExtras.putShort(name, value);
6860        return this;
6861    }
6862
6863    /**
6864     * Add extended data to the intent.  The name must include a package
6865     * prefix, for example the app com.android.contacts would use names
6866     * like "com.android.contacts.ShowAll".
6867     *
6868     * @param name The name of the extra data, with package prefix.
6869     * @param value The integer data value.
6870     *
6871     * @return Returns the same Intent object, for chaining multiple calls
6872     * into a single statement.
6873     *
6874     * @see #putExtras
6875     * @see #removeExtra
6876     * @see #getIntExtra(String, int)
6877     */
6878    public Intent putExtra(String name, int value) {
6879        if (mExtras == null) {
6880            mExtras = new Bundle();
6881        }
6882        mExtras.putInt(name, value);
6883        return this;
6884    }
6885
6886    /**
6887     * Add extended data to the intent.  The name must include a package
6888     * prefix, for example the app com.android.contacts would use names
6889     * like "com.android.contacts.ShowAll".
6890     *
6891     * @param name The name of the extra data, with package prefix.
6892     * @param value The long data value.
6893     *
6894     * @return Returns the same Intent object, for chaining multiple calls
6895     * into a single statement.
6896     *
6897     * @see #putExtras
6898     * @see #removeExtra
6899     * @see #getLongExtra(String, long)
6900     */
6901    public Intent putExtra(String name, long value) {
6902        if (mExtras == null) {
6903            mExtras = new Bundle();
6904        }
6905        mExtras.putLong(name, value);
6906        return this;
6907    }
6908
6909    /**
6910     * Add extended data to the intent.  The name must include a package
6911     * prefix, for example the app com.android.contacts would use names
6912     * like "com.android.contacts.ShowAll".
6913     *
6914     * @param name The name of the extra data, with package prefix.
6915     * @param value The float data value.
6916     *
6917     * @return Returns the same Intent object, for chaining multiple calls
6918     * into a single statement.
6919     *
6920     * @see #putExtras
6921     * @see #removeExtra
6922     * @see #getFloatExtra(String, float)
6923     */
6924    public Intent putExtra(String name, float value) {
6925        if (mExtras == null) {
6926            mExtras = new Bundle();
6927        }
6928        mExtras.putFloat(name, value);
6929        return this;
6930    }
6931
6932    /**
6933     * Add extended data to the intent.  The name must include a package
6934     * prefix, for example the app com.android.contacts would use names
6935     * like "com.android.contacts.ShowAll".
6936     *
6937     * @param name The name of the extra data, with package prefix.
6938     * @param value The double data value.
6939     *
6940     * @return Returns the same Intent object, for chaining multiple calls
6941     * into a single statement.
6942     *
6943     * @see #putExtras
6944     * @see #removeExtra
6945     * @see #getDoubleExtra(String, double)
6946     */
6947    public Intent putExtra(String name, double value) {
6948        if (mExtras == null) {
6949            mExtras = new Bundle();
6950        }
6951        mExtras.putDouble(name, value);
6952        return this;
6953    }
6954
6955    /**
6956     * Add extended data to the intent.  The name must include a package
6957     * prefix, for example the app com.android.contacts would use names
6958     * like "com.android.contacts.ShowAll".
6959     *
6960     * @param name The name of the extra data, with package prefix.
6961     * @param value The String data value.
6962     *
6963     * @return Returns the same Intent object, for chaining multiple calls
6964     * into a single statement.
6965     *
6966     * @see #putExtras
6967     * @see #removeExtra
6968     * @see #getStringExtra(String)
6969     */
6970    public Intent putExtra(String name, String value) {
6971        if (mExtras == null) {
6972            mExtras = new Bundle();
6973        }
6974        mExtras.putString(name, value);
6975        return this;
6976    }
6977
6978    /**
6979     * Add extended data to the intent.  The name must include a package
6980     * prefix, for example the app com.android.contacts would use names
6981     * like "com.android.contacts.ShowAll".
6982     *
6983     * @param name The name of the extra data, with package prefix.
6984     * @param value The CharSequence data value.
6985     *
6986     * @return Returns the same Intent object, for chaining multiple calls
6987     * into a single statement.
6988     *
6989     * @see #putExtras
6990     * @see #removeExtra
6991     * @see #getCharSequenceExtra(String)
6992     */
6993    public Intent putExtra(String name, CharSequence value) {
6994        if (mExtras == null) {
6995            mExtras = new Bundle();
6996        }
6997        mExtras.putCharSequence(name, value);
6998        return this;
6999    }
7000
7001    /**
7002     * Add extended data to the intent.  The name must include a package
7003     * prefix, for example the app com.android.contacts would use names
7004     * like "com.android.contacts.ShowAll".
7005     *
7006     * @param name The name of the extra data, with package prefix.
7007     * @param value The Parcelable data value.
7008     *
7009     * @return Returns the same Intent object, for chaining multiple calls
7010     * into a single statement.
7011     *
7012     * @see #putExtras
7013     * @see #removeExtra
7014     * @see #getParcelableExtra(String)
7015     */
7016    public Intent putExtra(String name, Parcelable value) {
7017        if (mExtras == null) {
7018            mExtras = new Bundle();
7019        }
7020        mExtras.putParcelable(name, value);
7021        return this;
7022    }
7023
7024    /**
7025     * Add extended data to the intent.  The name must include a package
7026     * prefix, for example the app com.android.contacts would use names
7027     * like "com.android.contacts.ShowAll".
7028     *
7029     * @param name The name of the extra data, with package prefix.
7030     * @param value The Parcelable[] data value.
7031     *
7032     * @return Returns the same Intent object, for chaining multiple calls
7033     * into a single statement.
7034     *
7035     * @see #putExtras
7036     * @see #removeExtra
7037     * @see #getParcelableArrayExtra(String)
7038     */
7039    public Intent putExtra(String name, Parcelable[] value) {
7040        if (mExtras == null) {
7041            mExtras = new Bundle();
7042        }
7043        mExtras.putParcelableArray(name, value);
7044        return this;
7045    }
7046
7047    /**
7048     * Add extended data to the intent.  The name must include a package
7049     * prefix, for example the app com.android.contacts would use names
7050     * like "com.android.contacts.ShowAll".
7051     *
7052     * @param name The name of the extra data, with package prefix.
7053     * @param value The ArrayList<Parcelable> data value.
7054     *
7055     * @return Returns the same Intent object, for chaining multiple calls
7056     * into a single statement.
7057     *
7058     * @see #putExtras
7059     * @see #removeExtra
7060     * @see #getParcelableArrayListExtra(String)
7061     */
7062    public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
7063        if (mExtras == null) {
7064            mExtras = new Bundle();
7065        }
7066        mExtras.putParcelableArrayList(name, value);
7067        return this;
7068    }
7069
7070    /**
7071     * Add extended data to the intent.  The name must include a package
7072     * prefix, for example the app com.android.contacts would use names
7073     * like "com.android.contacts.ShowAll".
7074     *
7075     * @param name The name of the extra data, with package prefix.
7076     * @param value The ArrayList<Integer> data value.
7077     *
7078     * @return Returns the same Intent object, for chaining multiple calls
7079     * into a single statement.
7080     *
7081     * @see #putExtras
7082     * @see #removeExtra
7083     * @see #getIntegerArrayListExtra(String)
7084     */
7085    public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
7086        if (mExtras == null) {
7087            mExtras = new Bundle();
7088        }
7089        mExtras.putIntegerArrayList(name, value);
7090        return this;
7091    }
7092
7093    /**
7094     * Add extended data to the intent.  The name must include a package
7095     * prefix, for example the app com.android.contacts would use names
7096     * like "com.android.contacts.ShowAll".
7097     *
7098     * @param name The name of the extra data, with package prefix.
7099     * @param value The ArrayList<String> data value.
7100     *
7101     * @return Returns the same Intent object, for chaining multiple calls
7102     * into a single statement.
7103     *
7104     * @see #putExtras
7105     * @see #removeExtra
7106     * @see #getStringArrayListExtra(String)
7107     */
7108    public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
7109        if (mExtras == null) {
7110            mExtras = new Bundle();
7111        }
7112        mExtras.putStringArrayList(name, value);
7113        return this;
7114    }
7115
7116    /**
7117     * Add extended data to the intent.  The name must include a package
7118     * prefix, for example the app com.android.contacts would use names
7119     * like "com.android.contacts.ShowAll".
7120     *
7121     * @param name The name of the extra data, with package prefix.
7122     * @param value The ArrayList<CharSequence> data value.
7123     *
7124     * @return Returns the same Intent object, for chaining multiple calls
7125     * into a single statement.
7126     *
7127     * @see #putExtras
7128     * @see #removeExtra
7129     * @see #getCharSequenceArrayListExtra(String)
7130     */
7131    public Intent putCharSequenceArrayListExtra(String name, ArrayList<CharSequence> value) {
7132        if (mExtras == null) {
7133            mExtras = new Bundle();
7134        }
7135        mExtras.putCharSequenceArrayList(name, value);
7136        return this;
7137    }
7138
7139    /**
7140     * Add extended data to the intent.  The name must include a package
7141     * prefix, for example the app com.android.contacts would use names
7142     * like "com.android.contacts.ShowAll".
7143     *
7144     * @param name The name of the extra data, with package prefix.
7145     * @param value The Serializable data value.
7146     *
7147     * @return Returns the same Intent object, for chaining multiple calls
7148     * into a single statement.
7149     *
7150     * @see #putExtras
7151     * @see #removeExtra
7152     * @see #getSerializableExtra(String)
7153     */
7154    public Intent putExtra(String name, Serializable value) {
7155        if (mExtras == null) {
7156            mExtras = new Bundle();
7157        }
7158        mExtras.putSerializable(name, value);
7159        return this;
7160    }
7161
7162    /**
7163     * Add extended data to the intent.  The name must include a package
7164     * prefix, for example the app com.android.contacts would use names
7165     * like "com.android.contacts.ShowAll".
7166     *
7167     * @param name The name of the extra data, with package prefix.
7168     * @param value The boolean array data value.
7169     *
7170     * @return Returns the same Intent object, for chaining multiple calls
7171     * into a single statement.
7172     *
7173     * @see #putExtras
7174     * @see #removeExtra
7175     * @see #getBooleanArrayExtra(String)
7176     */
7177    public Intent putExtra(String name, boolean[] value) {
7178        if (mExtras == null) {
7179            mExtras = new Bundle();
7180        }
7181        mExtras.putBooleanArray(name, value);
7182        return this;
7183    }
7184
7185    /**
7186     * Add extended data to the intent.  The name must include a package
7187     * prefix, for example the app com.android.contacts would use names
7188     * like "com.android.contacts.ShowAll".
7189     *
7190     * @param name The name of the extra data, with package prefix.
7191     * @param value The byte array data value.
7192     *
7193     * @return Returns the same Intent object, for chaining multiple calls
7194     * into a single statement.
7195     *
7196     * @see #putExtras
7197     * @see #removeExtra
7198     * @see #getByteArrayExtra(String)
7199     */
7200    public Intent putExtra(String name, byte[] value) {
7201        if (mExtras == null) {
7202            mExtras = new Bundle();
7203        }
7204        mExtras.putByteArray(name, value);
7205        return this;
7206    }
7207
7208    /**
7209     * Add extended data to the intent.  The name must include a package
7210     * prefix, for example the app com.android.contacts would use names
7211     * like "com.android.contacts.ShowAll".
7212     *
7213     * @param name The name of the extra data, with package prefix.
7214     * @param value The short array data value.
7215     *
7216     * @return Returns the same Intent object, for chaining multiple calls
7217     * into a single statement.
7218     *
7219     * @see #putExtras
7220     * @see #removeExtra
7221     * @see #getShortArrayExtra(String)
7222     */
7223    public Intent putExtra(String name, short[] value) {
7224        if (mExtras == null) {
7225            mExtras = new Bundle();
7226        }
7227        mExtras.putShortArray(name, value);
7228        return this;
7229    }
7230
7231    /**
7232     * Add extended data to the intent.  The name must include a package
7233     * prefix, for example the app com.android.contacts would use names
7234     * like "com.android.contacts.ShowAll".
7235     *
7236     * @param name The name of the extra data, with package prefix.
7237     * @param value The char array data value.
7238     *
7239     * @return Returns the same Intent object, for chaining multiple calls
7240     * into a single statement.
7241     *
7242     * @see #putExtras
7243     * @see #removeExtra
7244     * @see #getCharArrayExtra(String)
7245     */
7246    public Intent putExtra(String name, char[] value) {
7247        if (mExtras == null) {
7248            mExtras = new Bundle();
7249        }
7250        mExtras.putCharArray(name, value);
7251        return this;
7252    }
7253
7254    /**
7255     * Add extended data to the intent.  The name must include a package
7256     * prefix, for example the app com.android.contacts would use names
7257     * like "com.android.contacts.ShowAll".
7258     *
7259     * @param name The name of the extra data, with package prefix.
7260     * @param value The int array data value.
7261     *
7262     * @return Returns the same Intent object, for chaining multiple calls
7263     * into a single statement.
7264     *
7265     * @see #putExtras
7266     * @see #removeExtra
7267     * @see #getIntArrayExtra(String)
7268     */
7269    public Intent putExtra(String name, int[] value) {
7270        if (mExtras == null) {
7271            mExtras = new Bundle();
7272        }
7273        mExtras.putIntArray(name, value);
7274        return this;
7275    }
7276
7277    /**
7278     * Add extended data to the intent.  The name must include a package
7279     * prefix, for example the app com.android.contacts would use names
7280     * like "com.android.contacts.ShowAll".
7281     *
7282     * @param name The name of the extra data, with package prefix.
7283     * @param value The byte array data value.
7284     *
7285     * @return Returns the same Intent object, for chaining multiple calls
7286     * into a single statement.
7287     *
7288     * @see #putExtras
7289     * @see #removeExtra
7290     * @see #getLongArrayExtra(String)
7291     */
7292    public Intent putExtra(String name, long[] value) {
7293        if (mExtras == null) {
7294            mExtras = new Bundle();
7295        }
7296        mExtras.putLongArray(name, value);
7297        return this;
7298    }
7299
7300    /**
7301     * Add extended data to the intent.  The name must include a package
7302     * prefix, for example the app com.android.contacts would use names
7303     * like "com.android.contacts.ShowAll".
7304     *
7305     * @param name The name of the extra data, with package prefix.
7306     * @param value The float array data value.
7307     *
7308     * @return Returns the same Intent object, for chaining multiple calls
7309     * into a single statement.
7310     *
7311     * @see #putExtras
7312     * @see #removeExtra
7313     * @see #getFloatArrayExtra(String)
7314     */
7315    public Intent putExtra(String name, float[] value) {
7316        if (mExtras == null) {
7317            mExtras = new Bundle();
7318        }
7319        mExtras.putFloatArray(name, value);
7320        return this;
7321    }
7322
7323    /**
7324     * Add extended data to the intent.  The name must include a package
7325     * prefix, for example the app com.android.contacts would use names
7326     * like "com.android.contacts.ShowAll".
7327     *
7328     * @param name The name of the extra data, with package prefix.
7329     * @param value The double array data value.
7330     *
7331     * @return Returns the same Intent object, for chaining multiple calls
7332     * into a single statement.
7333     *
7334     * @see #putExtras
7335     * @see #removeExtra
7336     * @see #getDoubleArrayExtra(String)
7337     */
7338    public Intent putExtra(String name, double[] value) {
7339        if (mExtras == null) {
7340            mExtras = new Bundle();
7341        }
7342        mExtras.putDoubleArray(name, value);
7343        return this;
7344    }
7345
7346    /**
7347     * Add extended data to the intent.  The name must include a package
7348     * prefix, for example the app com.android.contacts would use names
7349     * like "com.android.contacts.ShowAll".
7350     *
7351     * @param name The name of the extra data, with package prefix.
7352     * @param value The String array data value.
7353     *
7354     * @return Returns the same Intent object, for chaining multiple calls
7355     * into a single statement.
7356     *
7357     * @see #putExtras
7358     * @see #removeExtra
7359     * @see #getStringArrayExtra(String)
7360     */
7361    public Intent putExtra(String name, String[] value) {
7362        if (mExtras == null) {
7363            mExtras = new Bundle();
7364        }
7365        mExtras.putStringArray(name, value);
7366        return this;
7367    }
7368
7369    /**
7370     * Add extended data to the intent.  The name must include a package
7371     * prefix, for example the app com.android.contacts would use names
7372     * like "com.android.contacts.ShowAll".
7373     *
7374     * @param name The name of the extra data, with package prefix.
7375     * @param value The CharSequence array data value.
7376     *
7377     * @return Returns the same Intent object, for chaining multiple calls
7378     * into a single statement.
7379     *
7380     * @see #putExtras
7381     * @see #removeExtra
7382     * @see #getCharSequenceArrayExtra(String)
7383     */
7384    public Intent putExtra(String name, CharSequence[] value) {
7385        if (mExtras == null) {
7386            mExtras = new Bundle();
7387        }
7388        mExtras.putCharSequenceArray(name, value);
7389        return this;
7390    }
7391
7392    /**
7393     * Add extended data to the intent.  The name must include a package
7394     * prefix, for example the app com.android.contacts would use names
7395     * like "com.android.contacts.ShowAll".
7396     *
7397     * @param name The name of the extra data, with package prefix.
7398     * @param value The Bundle data value.
7399     *
7400     * @return Returns the same Intent object, for chaining multiple calls
7401     * into a single statement.
7402     *
7403     * @see #putExtras
7404     * @see #removeExtra
7405     * @see #getBundleExtra(String)
7406     */
7407    public Intent putExtra(String name, Bundle value) {
7408        if (mExtras == null) {
7409            mExtras = new Bundle();
7410        }
7411        mExtras.putBundle(name, value);
7412        return this;
7413    }
7414
7415    /**
7416     * Add extended data to the intent.  The name must include a package
7417     * prefix, for example the app com.android.contacts would use names
7418     * like "com.android.contacts.ShowAll".
7419     *
7420     * @param name The name of the extra data, with package prefix.
7421     * @param value The IBinder data value.
7422     *
7423     * @return Returns the same Intent object, for chaining multiple calls
7424     * into a single statement.
7425     *
7426     * @see #putExtras
7427     * @see #removeExtra
7428     * @see #getIBinderExtra(String)
7429     *
7430     * @deprecated
7431     * @hide
7432     */
7433    @Deprecated
7434    public Intent putExtra(String name, IBinder value) {
7435        if (mExtras == null) {
7436            mExtras = new Bundle();
7437        }
7438        mExtras.putIBinder(name, value);
7439        return this;
7440    }
7441
7442    /**
7443     * Copy all extras in 'src' in to this intent.
7444     *
7445     * @param src Contains the extras to copy.
7446     *
7447     * @see #putExtra
7448     */
7449    public Intent putExtras(Intent src) {
7450        if (src.mExtras != null) {
7451            if (mExtras == null) {
7452                mExtras = new Bundle(src.mExtras);
7453            } else {
7454                mExtras.putAll(src.mExtras);
7455            }
7456        }
7457        return this;
7458    }
7459
7460    /**
7461     * Add a set of extended data to the intent.  The keys must include a package
7462     * prefix, for example the app com.android.contacts would use names
7463     * like "com.android.contacts.ShowAll".
7464     *
7465     * @param extras The Bundle of extras to add to this intent.
7466     *
7467     * @see #putExtra
7468     * @see #removeExtra
7469     */
7470    public Intent putExtras(Bundle extras) {
7471        if (mExtras == null) {
7472            mExtras = new Bundle();
7473        }
7474        mExtras.putAll(extras);
7475        return this;
7476    }
7477
7478    /**
7479     * Completely replace the extras in the Intent with the extras in the
7480     * given Intent.
7481     *
7482     * @param src The exact extras contained in this Intent are copied
7483     * into the target intent, replacing any that were previously there.
7484     */
7485    public Intent replaceExtras(Intent src) {
7486        mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null;
7487        return this;
7488    }
7489
7490    /**
7491     * Completely replace the extras in the Intent with the given Bundle of
7492     * extras.
7493     *
7494     * @param extras The new set of extras in the Intent, or null to erase
7495     * all extras.
7496     */
7497    public Intent replaceExtras(Bundle extras) {
7498        mExtras = extras != null ? new Bundle(extras) : null;
7499        return this;
7500    }
7501
7502    /**
7503     * Remove extended data from the intent.
7504     *
7505     * @see #putExtra
7506     */
7507    public void removeExtra(String name) {
7508        if (mExtras != null) {
7509            mExtras.remove(name);
7510            if (mExtras.size() == 0) {
7511                mExtras = null;
7512            }
7513        }
7514    }
7515
7516    /**
7517     * Set special flags controlling how this intent is handled.  Most values
7518     * here depend on the type of component being executed by the Intent,
7519     * specifically the FLAG_ACTIVITY_* flags are all for use with
7520     * {@link Context#startActivity Context.startActivity()} and the
7521     * FLAG_RECEIVER_* flags are all for use with
7522     * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
7523     *
7524     * <p>See the
7525     * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
7526     * Stack</a> documentation for important information on how some of these options impact
7527     * the behavior of your application.
7528     *
7529     * @param flags The desired flags.
7530     *
7531     * @return Returns the same Intent object, for chaining multiple calls
7532     * into a single statement.
7533     *
7534     * @see #getFlags
7535     * @see #addFlags
7536     *
7537     * @see #FLAG_GRANT_READ_URI_PERMISSION
7538     * @see #FLAG_GRANT_WRITE_URI_PERMISSION
7539     * @see #FLAG_GRANT_PERSISTABLE_URI_PERMISSION
7540     * @see #FLAG_GRANT_PREFIX_URI_PERMISSION
7541     * @see #FLAG_DEBUG_LOG_RESOLUTION
7542     * @see #FLAG_FROM_BACKGROUND
7543     * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT
7544     * @see #FLAG_ACTIVITY_CLEAR_TASK
7545     * @see #FLAG_ACTIVITY_CLEAR_TOP
7546     * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
7547     * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
7548     * @see #FLAG_ACTIVITY_FORWARD_RESULT
7549     * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
7550     * @see #FLAG_ACTIVITY_MULTIPLE_TASK
7551     * @see #FLAG_ACTIVITY_NEW_DOCUMENT
7552     * @see #FLAG_ACTIVITY_NEW_TASK
7553     * @see #FLAG_ACTIVITY_NO_ANIMATION
7554     * @see #FLAG_ACTIVITY_NO_HISTORY
7555     * @see #FLAG_ACTIVITY_NO_USER_ACTION
7556     * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP
7557     * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
7558     * @see #FLAG_ACTIVITY_REORDER_TO_FRONT
7559     * @see #FLAG_ACTIVITY_SINGLE_TOP
7560     * @see #FLAG_ACTIVITY_TASK_ON_HOME
7561     * @see #FLAG_RECEIVER_REGISTERED_ONLY
7562     */
7563    public Intent setFlags(int flags) {
7564        mFlags = flags;
7565        return this;
7566    }
7567
7568    /**
7569     * Add additional flags to the intent (or with existing flags
7570     * value).
7571     *
7572     * @param flags The new flags to set.
7573     *
7574     * @return Returns the same Intent object, for chaining multiple calls
7575     * into a single statement.
7576     *
7577     * @see #setFlags
7578     */
7579    public Intent addFlags(int flags) {
7580        mFlags |= flags;
7581        return this;
7582    }
7583
7584    /**
7585     * (Usually optional) Set an explicit application package name that limits
7586     * the components this Intent will resolve to.  If left to the default
7587     * value of null, all components in all applications will considered.
7588     * If non-null, the Intent can only match the components in the given
7589     * application package.
7590     *
7591     * @param packageName The name of the application package to handle the
7592     * intent, or null to allow any application package.
7593     *
7594     * @return Returns the same Intent object, for chaining multiple calls
7595     * into a single statement.
7596     *
7597     * @see #getPackage
7598     * @see #resolveActivity
7599     */
7600    public Intent setPackage(String packageName) {
7601        if (packageName != null && mSelector != null) {
7602            throw new IllegalArgumentException(
7603                    "Can't set package name when selector is already set");
7604        }
7605        mPackage = packageName;
7606        return this;
7607    }
7608
7609    /**
7610     * (Usually optional) Explicitly set the component to handle the intent.
7611     * If left with the default value of null, the system will determine the
7612     * appropriate class to use based on the other fields (action, data,
7613     * type, categories) in the Intent.  If this class is defined, the
7614     * specified class will always be used regardless of the other fields.  You
7615     * should only set this value when you know you absolutely want a specific
7616     * class to be used; otherwise it is better to let the system find the
7617     * appropriate class so that you will respect the installed applications
7618     * and user preferences.
7619     *
7620     * @param component The name of the application component to handle the
7621     * intent, or null to let the system find one for you.
7622     *
7623     * @return Returns the same Intent object, for chaining multiple calls
7624     * into a single statement.
7625     *
7626     * @see #setClass
7627     * @see #setClassName(Context, String)
7628     * @see #setClassName(String, String)
7629     * @see #getComponent
7630     * @see #resolveActivity
7631     */
7632    public Intent setComponent(ComponentName component) {
7633        mComponent = component;
7634        return this;
7635    }
7636
7637    /**
7638     * Convenience for calling {@link #setComponent} with an
7639     * explicit class name.
7640     *
7641     * @param packageContext A Context of the application package implementing
7642     * this class.
7643     * @param className The name of a class inside of the application package
7644     * that will be used as the component for this Intent.
7645     *
7646     * @return Returns the same Intent object, for chaining multiple calls
7647     * into a single statement.
7648     *
7649     * @see #setComponent
7650     * @see #setClass
7651     */
7652    public Intent setClassName(Context packageContext, String className) {
7653        mComponent = new ComponentName(packageContext, className);
7654        return this;
7655    }
7656
7657    /**
7658     * Convenience for calling {@link #setComponent} with an
7659     * explicit application package name and class name.
7660     *
7661     * @param packageName The name of the package implementing the desired
7662     * component.
7663     * @param className The name of a class inside of the application package
7664     * that will be used as the component for this Intent.
7665     *
7666     * @return Returns the same Intent object, for chaining multiple calls
7667     * into a single statement.
7668     *
7669     * @see #setComponent
7670     * @see #setClass
7671     */
7672    public Intent setClassName(String packageName, String className) {
7673        mComponent = new ComponentName(packageName, className);
7674        return this;
7675    }
7676
7677    /**
7678     * Convenience for calling {@link #setComponent(ComponentName)} with the
7679     * name returned by a {@link Class} object.
7680     *
7681     * @param packageContext A Context of the application package implementing
7682     * this class.
7683     * @param cls The class name to set, equivalent to
7684     *            <code>setClassName(context, cls.getName())</code>.
7685     *
7686     * @return Returns the same Intent object, for chaining multiple calls
7687     * into a single statement.
7688     *
7689     * @see #setComponent
7690     */
7691    public Intent setClass(Context packageContext, Class<?> cls) {
7692        mComponent = new ComponentName(packageContext, cls);
7693        return this;
7694    }
7695
7696    /**
7697     * Set the bounds of the sender of this intent, in screen coordinates.  This can be
7698     * used as a hint to the receiver for animations and the like.  Null means that there
7699     * is no source bounds.
7700     */
7701    public void setSourceBounds(Rect r) {
7702        if (r != null) {
7703            mSourceBounds = new Rect(r);
7704        } else {
7705            mSourceBounds = null;
7706        }
7707    }
7708
7709    /** @hide */
7710    @IntDef(flag = true,
7711            value = {
7712                    FILL_IN_ACTION,
7713                    FILL_IN_DATA,
7714                    FILL_IN_CATEGORIES,
7715                    FILL_IN_COMPONENT,
7716                    FILL_IN_PACKAGE,
7717                    FILL_IN_SOURCE_BOUNDS,
7718                    FILL_IN_SELECTOR,
7719                    FILL_IN_CLIP_DATA
7720            })
7721    @Retention(RetentionPolicy.SOURCE)
7722    public @interface FillInFlags {}
7723
7724    /**
7725     * Use with {@link #fillIn} to allow the current action value to be
7726     * overwritten, even if it is already set.
7727     */
7728    public static final int FILL_IN_ACTION = 1<<0;
7729
7730    /**
7731     * Use with {@link #fillIn} to allow the current data or type value
7732     * overwritten, even if it is already set.
7733     */
7734    public static final int FILL_IN_DATA = 1<<1;
7735
7736    /**
7737     * Use with {@link #fillIn} to allow the current categories to be
7738     * overwritten, even if they are already set.
7739     */
7740    public static final int FILL_IN_CATEGORIES = 1<<2;
7741
7742    /**
7743     * Use with {@link #fillIn} to allow the current component value to be
7744     * overwritten, even if it is already set.
7745     */
7746    public static final int FILL_IN_COMPONENT = 1<<3;
7747
7748    /**
7749     * Use with {@link #fillIn} to allow the current package value to be
7750     * overwritten, even if it is already set.
7751     */
7752    public static final int FILL_IN_PACKAGE = 1<<4;
7753
7754    /**
7755     * Use with {@link #fillIn} to allow the current bounds rectangle to be
7756     * overwritten, even if it is already set.
7757     */
7758    public static final int FILL_IN_SOURCE_BOUNDS = 1<<5;
7759
7760    /**
7761     * Use with {@link #fillIn} to allow the current selector to be
7762     * overwritten, even if it is already set.
7763     */
7764    public static final int FILL_IN_SELECTOR = 1<<6;
7765
7766    /**
7767     * Use with {@link #fillIn} to allow the current ClipData to be
7768     * overwritten, even if it is already set.
7769     */
7770    public static final int FILL_IN_CLIP_DATA = 1<<7;
7771
7772    /**
7773     * Copy the contents of <var>other</var> in to this object, but only
7774     * where fields are not defined by this object.  For purposes of a field
7775     * being defined, the following pieces of data in the Intent are
7776     * considered to be separate fields:
7777     *
7778     * <ul>
7779     * <li> action, as set by {@link #setAction}.
7780     * <li> data Uri and MIME type, as set by {@link #setData(Uri)},
7781     * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}.
7782     * <li> categories, as set by {@link #addCategory}.
7783     * <li> package, as set by {@link #setPackage}.
7784     * <li> component, as set by {@link #setComponent(ComponentName)} or
7785     * related methods.
7786     * <li> source bounds, as set by {@link #setSourceBounds}.
7787     * <li> selector, as set by {@link #setSelector(Intent)}.
7788     * <li> clip data, as set by {@link #setClipData(ClipData)}.
7789     * <li> each top-level name in the associated extras.
7790     * </ul>
7791     *
7792     * <p>In addition, you can use the {@link #FILL_IN_ACTION},
7793     * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
7794     * {@link #FILL_IN_COMPONENT}, {@link #FILL_IN_SOURCE_BOUNDS},
7795     * {@link #FILL_IN_SELECTOR}, and {@link #FILL_IN_CLIP_DATA} to override
7796     * the restriction where the corresponding field will not be replaced if
7797     * it is already set.
7798     *
7799     * <p>Note: The component field will only be copied if {@link #FILL_IN_COMPONENT}
7800     * is explicitly specified.  The selector will only be copied if
7801     * {@link #FILL_IN_SELECTOR} is explicitly specified.
7802     *
7803     * <p>For example, consider Intent A with {data="foo", categories="bar"}
7804     * and Intent B with {action="gotit", data-type="some/thing",
7805     * categories="one","two"}.
7806     *
7807     * <p>Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now
7808     * containing: {action="gotit", data-type="some/thing",
7809     * categories="bar"}.
7810     *
7811     * @param other Another Intent whose values are to be used to fill in
7812     * the current one.
7813     * @param flags Options to control which fields can be filled in.
7814     *
7815     * @return Returns a bit mask of {@link #FILL_IN_ACTION},
7816     * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
7817     * {@link #FILL_IN_COMPONENT}, {@link #FILL_IN_SOURCE_BOUNDS},
7818     * {@link #FILL_IN_SELECTOR} and {@link #FILL_IN_CLIP_DATA indicating which fields were
7819     * changed.
7820     */
7821    @FillInFlags
7822    public int fillIn(Intent other, @FillInFlags int flags) {
7823        int changes = 0;
7824        boolean mayHaveCopiedUris = false;
7825        if (other.mAction != null
7826                && (mAction == null || (flags&FILL_IN_ACTION) != 0)) {
7827            mAction = other.mAction;
7828            changes |= FILL_IN_ACTION;
7829        }
7830        if ((other.mData != null || other.mType != null)
7831                && ((mData == null && mType == null)
7832                        || (flags&FILL_IN_DATA) != 0)) {
7833            mData = other.mData;
7834            mType = other.mType;
7835            changes |= FILL_IN_DATA;
7836            mayHaveCopiedUris = true;
7837        }
7838        if (other.mCategories != null
7839                && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) {
7840            if (other.mCategories != null) {
7841                mCategories = new ArraySet<String>(other.mCategories);
7842            }
7843            changes |= FILL_IN_CATEGORIES;
7844        }
7845        if (other.mPackage != null
7846                && (mPackage == null || (flags&FILL_IN_PACKAGE) != 0)) {
7847            // Only do this if mSelector is not set.
7848            if (mSelector == null) {
7849                mPackage = other.mPackage;
7850                changes |= FILL_IN_PACKAGE;
7851            }
7852        }
7853        // Selector is special: it can only be set if explicitly allowed,
7854        // for the same reason as the component name.
7855        if (other.mSelector != null && (flags&FILL_IN_SELECTOR) != 0) {
7856            if (mPackage == null) {
7857                mSelector = new Intent(other.mSelector);
7858                mPackage = null;
7859                changes |= FILL_IN_SELECTOR;
7860            }
7861        }
7862        if (other.mClipData != null
7863                && (mClipData == null || (flags&FILL_IN_CLIP_DATA) != 0)) {
7864            mClipData = other.mClipData;
7865            changes |= FILL_IN_CLIP_DATA;
7866            mayHaveCopiedUris = true;
7867        }
7868        // Component is special: it can -only- be set if explicitly allowed,
7869        // since otherwise the sender could force the intent somewhere the
7870        // originator didn't intend.
7871        if (other.mComponent != null && (flags&FILL_IN_COMPONENT) != 0) {
7872            mComponent = other.mComponent;
7873            changes |= FILL_IN_COMPONENT;
7874        }
7875        mFlags |= other.mFlags;
7876        if (other.mSourceBounds != null
7877                && (mSourceBounds == null || (flags&FILL_IN_SOURCE_BOUNDS) != 0)) {
7878            mSourceBounds = new Rect(other.mSourceBounds);
7879            changes |= FILL_IN_SOURCE_BOUNDS;
7880        }
7881        if (mExtras == null) {
7882            if (other.mExtras != null) {
7883                mExtras = new Bundle(other.mExtras);
7884                mayHaveCopiedUris = true;
7885            }
7886        } else if (other.mExtras != null) {
7887            try {
7888                Bundle newb = new Bundle(other.mExtras);
7889                newb.putAll(mExtras);
7890                mExtras = newb;
7891                mayHaveCopiedUris = true;
7892            } catch (RuntimeException e) {
7893                // Modifying the extras can cause us to unparcel the contents
7894                // of the bundle, and if we do this in the system process that
7895                // may fail.  We really should handle this (i.e., the Bundle
7896                // impl shouldn't be on top of a plain map), but for now just
7897                // ignore it and keep the original contents. :(
7898                Log.w("Intent", "Failure filling in extras", e);
7899            }
7900        }
7901        if (mayHaveCopiedUris && mContentUserHint == UserHandle.USER_CURRENT
7902                && other.mContentUserHint != UserHandle.USER_CURRENT) {
7903            mContentUserHint = other.mContentUserHint;
7904        }
7905        return changes;
7906    }
7907
7908    /**
7909     * Wrapper class holding an Intent and implementing comparisons on it for
7910     * the purpose of filtering.  The class implements its
7911     * {@link #equals equals()} and {@link #hashCode hashCode()} methods as
7912     * simple calls to {@link Intent#filterEquals(Intent)}  filterEquals()} and
7913     * {@link android.content.Intent#filterHashCode()}  filterHashCode()}
7914     * on the wrapped Intent.
7915     */
7916    public static final class FilterComparison {
7917        private final Intent mIntent;
7918        private final int mHashCode;
7919
7920        public FilterComparison(Intent intent) {
7921            mIntent = intent;
7922            mHashCode = intent.filterHashCode();
7923        }
7924
7925        /**
7926         * Return the Intent that this FilterComparison represents.
7927         * @return Returns the Intent held by the FilterComparison.  Do
7928         * not modify!
7929         */
7930        public Intent getIntent() {
7931            return mIntent;
7932        }
7933
7934        @Override
7935        public boolean equals(Object obj) {
7936            if (obj instanceof FilterComparison) {
7937                Intent other = ((FilterComparison)obj).mIntent;
7938                return mIntent.filterEquals(other);
7939            }
7940            return false;
7941        }
7942
7943        @Override
7944        public int hashCode() {
7945            return mHashCode;
7946        }
7947    }
7948
7949    /**
7950     * Determine if two intents are the same for the purposes of intent
7951     * resolution (filtering). That is, if their action, data, type,
7952     * class, and categories are the same.  This does <em>not</em> compare
7953     * any extra data included in the intents.
7954     *
7955     * @param other The other Intent to compare against.
7956     *
7957     * @return Returns true if action, data, type, class, and categories
7958     *         are the same.
7959     */
7960    public boolean filterEquals(Intent other) {
7961        if (other == null) {
7962            return false;
7963        }
7964        if (!Objects.equals(this.mAction, other.mAction)) return false;
7965        if (!Objects.equals(this.mData, other.mData)) return false;
7966        if (!Objects.equals(this.mType, other.mType)) return false;
7967        if (!Objects.equals(this.mPackage, other.mPackage)) return false;
7968        if (!Objects.equals(this.mComponent, other.mComponent)) return false;
7969        if (!Objects.equals(this.mCategories, other.mCategories)) return false;
7970
7971        return true;
7972    }
7973
7974    /**
7975     * Generate hash code that matches semantics of filterEquals().
7976     *
7977     * @return Returns the hash value of the action, data, type, class, and
7978     *         categories.
7979     *
7980     * @see #filterEquals
7981     */
7982    public int filterHashCode() {
7983        int code = 0;
7984        if (mAction != null) {
7985            code += mAction.hashCode();
7986        }
7987        if (mData != null) {
7988            code += mData.hashCode();
7989        }
7990        if (mType != null) {
7991            code += mType.hashCode();
7992        }
7993        if (mPackage != null) {
7994            code += mPackage.hashCode();
7995        }
7996        if (mComponent != null) {
7997            code += mComponent.hashCode();
7998        }
7999        if (mCategories != null) {
8000            code += mCategories.hashCode();
8001        }
8002        return code;
8003    }
8004
8005    @Override
8006    public String toString() {
8007        StringBuilder b = new StringBuilder(128);
8008
8009        b.append("Intent { ");
8010        toShortString(b, true, true, true, false);
8011        b.append(" }");
8012
8013        return b.toString();
8014    }
8015
8016    /** @hide */
8017    public String toInsecureString() {
8018        StringBuilder b = new StringBuilder(128);
8019
8020        b.append("Intent { ");
8021        toShortString(b, false, true, true, false);
8022        b.append(" }");
8023
8024        return b.toString();
8025    }
8026
8027    /** @hide */
8028    public String toInsecureStringWithClip() {
8029        StringBuilder b = new StringBuilder(128);
8030
8031        b.append("Intent { ");
8032        toShortString(b, false, true, true, true);
8033        b.append(" }");
8034
8035        return b.toString();
8036    }
8037
8038    /** @hide */
8039    public String toShortString(boolean secure, boolean comp, boolean extras, boolean clip) {
8040        StringBuilder b = new StringBuilder(128);
8041        toShortString(b, secure, comp, extras, clip);
8042        return b.toString();
8043    }
8044
8045    /** @hide */
8046    public void toShortString(StringBuilder b, boolean secure, boolean comp, boolean extras,
8047            boolean clip) {
8048        boolean first = true;
8049        if (mAction != null) {
8050            b.append("act=").append(mAction);
8051            first = false;
8052        }
8053        if (mCategories != null) {
8054            if (!first) {
8055                b.append(' ');
8056            }
8057            first = false;
8058            b.append("cat=[");
8059            for (int i=0; i<mCategories.size(); i++) {
8060                if (i > 0) b.append(',');
8061                b.append(mCategories.valueAt(i));
8062            }
8063            b.append("]");
8064        }
8065        if (mData != null) {
8066            if (!first) {
8067                b.append(' ');
8068            }
8069            first = false;
8070            b.append("dat=");
8071            if (secure) {
8072                b.append(mData.toSafeString());
8073            } else {
8074                b.append(mData);
8075            }
8076        }
8077        if (mType != null) {
8078            if (!first) {
8079                b.append(' ');
8080            }
8081            first = false;
8082            b.append("typ=").append(mType);
8083        }
8084        if (mFlags != 0) {
8085            if (!first) {
8086                b.append(' ');
8087            }
8088            first = false;
8089            b.append("flg=0x").append(Integer.toHexString(mFlags));
8090        }
8091        if (mPackage != null) {
8092            if (!first) {
8093                b.append(' ');
8094            }
8095            first = false;
8096            b.append("pkg=").append(mPackage);
8097        }
8098        if (comp && mComponent != null) {
8099            if (!first) {
8100                b.append(' ');
8101            }
8102            first = false;
8103            b.append("cmp=").append(mComponent.flattenToShortString());
8104        }
8105        if (mSourceBounds != null) {
8106            if (!first) {
8107                b.append(' ');
8108            }
8109            first = false;
8110            b.append("bnds=").append(mSourceBounds.toShortString());
8111        }
8112        if (mClipData != null) {
8113            if (!first) {
8114                b.append(' ');
8115            }
8116            b.append("clip={");
8117            if (clip) {
8118                mClipData.toShortString(b);
8119            } else {
8120                if (mClipData.getDescription() != null) {
8121                    first = !mClipData.getDescription().toShortStringTypesOnly(b);
8122                } else {
8123                    first = true;
8124                }
8125                mClipData.toShortStringShortItems(b, first);
8126            }
8127            first = false;
8128            b.append('}');
8129        }
8130        if (extras && mExtras != null) {
8131            if (!first) {
8132                b.append(' ');
8133            }
8134            first = false;
8135            b.append("(has extras)");
8136        }
8137        if (mContentUserHint != UserHandle.USER_CURRENT) {
8138            if (!first) {
8139                b.append(' ');
8140            }
8141            first = false;
8142            b.append("u=").append(mContentUserHint);
8143        }
8144        if (mSelector != null) {
8145            b.append(" sel=");
8146            mSelector.toShortString(b, secure, comp, extras, clip);
8147            b.append("}");
8148        }
8149    }
8150
8151    /**
8152     * Call {@link #toUri} with 0 flags.
8153     * @deprecated Use {@link #toUri} instead.
8154     */
8155    @Deprecated
8156    public String toURI() {
8157        return toUri(0);
8158    }
8159
8160    /**
8161     * Convert this Intent into a String holding a URI representation of it.
8162     * The returned URI string has been properly URI encoded, so it can be
8163     * used with {@link Uri#parse Uri.parse(String)}.  The URI contains the
8164     * Intent's data as the base URI, with an additional fragment describing
8165     * the action, categories, type, flags, package, component, and extras.
8166     *
8167     * <p>You can convert the returned string back to an Intent with
8168     * {@link #getIntent}.
8169     *
8170     * @param flags Additional operating flags.  Either 0,
8171     * {@link #URI_INTENT_SCHEME}, or {@link #URI_ANDROID_APP_SCHEME}.
8172     *
8173     * @return Returns a URI encoding URI string describing the entire contents
8174     * of the Intent.
8175     */
8176    public String toUri(int flags) {
8177        StringBuilder uri = new StringBuilder(128);
8178        if ((flags&URI_ANDROID_APP_SCHEME) != 0) {
8179            if (mPackage == null) {
8180                throw new IllegalArgumentException(
8181                        "Intent must include an explicit package name to build an android-app: "
8182                        + this);
8183            }
8184            uri.append("android-app://");
8185            uri.append(mPackage);
8186            String scheme = null;
8187            if (mData != null) {
8188                scheme = mData.getScheme();
8189                if (scheme != null) {
8190                    uri.append('/');
8191                    uri.append(scheme);
8192                    String authority = mData.getEncodedAuthority();
8193                    if (authority != null) {
8194                        uri.append('/');
8195                        uri.append(authority);
8196                        String path = mData.getEncodedPath();
8197                        if (path != null) {
8198                            uri.append(path);
8199                        }
8200                        String queryParams = mData.getEncodedQuery();
8201                        if (queryParams != null) {
8202                            uri.append('?');
8203                            uri.append(queryParams);
8204                        }
8205                        String fragment = mData.getEncodedFragment();
8206                        if (fragment != null) {
8207                            uri.append('#');
8208                            uri.append(fragment);
8209                        }
8210                    }
8211                }
8212            }
8213            toUriFragment(uri, null, scheme == null ? Intent.ACTION_MAIN : Intent.ACTION_VIEW,
8214                    mPackage, flags);
8215            return uri.toString();
8216        }
8217        String scheme = null;
8218        if (mData != null) {
8219            String data = mData.toString();
8220            if ((flags&URI_INTENT_SCHEME) != 0) {
8221                final int N = data.length();
8222                for (int i=0; i<N; i++) {
8223                    char c = data.charAt(i);
8224                    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
8225                            || c == '.' || c == '-') {
8226                        continue;
8227                    }
8228                    if (c == ':' && i > 0) {
8229                        // Valid scheme.
8230                        scheme = data.substring(0, i);
8231                        uri.append("intent:");
8232                        data = data.substring(i+1);
8233                        break;
8234                    }
8235
8236                    // No scheme.
8237                    break;
8238                }
8239            }
8240            uri.append(data);
8241
8242        } else if ((flags&URI_INTENT_SCHEME) != 0) {
8243            uri.append("intent:");
8244        }
8245
8246        toUriFragment(uri, scheme, Intent.ACTION_VIEW, null, flags);
8247
8248        return uri.toString();
8249    }
8250
8251    private void toUriFragment(StringBuilder uri, String scheme, String defAction,
8252            String defPackage, int flags) {
8253        StringBuilder frag = new StringBuilder(128);
8254
8255        toUriInner(frag, scheme, defAction, defPackage, flags);
8256        if (mSelector != null) {
8257            frag.append("SEL;");
8258            // Note that for now we are not going to try to handle the
8259            // data part; not clear how to represent this as a URI, and
8260            // not much utility in it.
8261            mSelector.toUriInner(frag, mSelector.mData != null ? mSelector.mData.getScheme() : null,
8262                    null, null, flags);
8263        }
8264
8265        if (frag.length() > 0) {
8266            uri.append("#Intent;");
8267            uri.append(frag);
8268            uri.append("end");
8269        }
8270    }
8271
8272    private void toUriInner(StringBuilder uri, String scheme, String defAction,
8273            String defPackage, int flags) {
8274        if (scheme != null) {
8275            uri.append("scheme=").append(scheme).append(';');
8276        }
8277        if (mAction != null && !mAction.equals(defAction)) {
8278            uri.append("action=").append(Uri.encode(mAction)).append(';');
8279        }
8280        if (mCategories != null) {
8281            for (int i=0; i<mCategories.size(); i++) {
8282                uri.append("category=").append(Uri.encode(mCategories.valueAt(i))).append(';');
8283            }
8284        }
8285        if (mType != null) {
8286            uri.append("type=").append(Uri.encode(mType, "/")).append(';');
8287        }
8288        if (mFlags != 0) {
8289            uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
8290        }
8291        if (mPackage != null && !mPackage.equals(defPackage)) {
8292            uri.append("package=").append(Uri.encode(mPackage)).append(';');
8293        }
8294        if (mComponent != null) {
8295            uri.append("component=").append(Uri.encode(
8296                    mComponent.flattenToShortString(), "/")).append(';');
8297        }
8298        if (mSourceBounds != null) {
8299            uri.append("sourceBounds=")
8300                    .append(Uri.encode(mSourceBounds.flattenToString()))
8301                    .append(';');
8302        }
8303        if (mExtras != null) {
8304            for (String key : mExtras.keySet()) {
8305                final Object value = mExtras.get(key);
8306                char entryType =
8307                        value instanceof String    ? 'S' :
8308                        value instanceof Boolean   ? 'B' :
8309                        value instanceof Byte      ? 'b' :
8310                        value instanceof Character ? 'c' :
8311                        value instanceof Double    ? 'd' :
8312                        value instanceof Float     ? 'f' :
8313                        value instanceof Integer   ? 'i' :
8314                        value instanceof Long      ? 'l' :
8315                        value instanceof Short     ? 's' :
8316                        '\0';
8317
8318                if (entryType != '\0') {
8319                    uri.append(entryType);
8320                    uri.append('.');
8321                    uri.append(Uri.encode(key));
8322                    uri.append('=');
8323                    uri.append(Uri.encode(value.toString()));
8324                    uri.append(';');
8325                }
8326            }
8327        }
8328    }
8329
8330    public int describeContents() {
8331        return (mExtras != null) ? mExtras.describeContents() : 0;
8332    }
8333
8334    public void writeToParcel(Parcel out, int flags) {
8335        out.writeString(mAction);
8336        Uri.writeToParcel(out, mData);
8337        out.writeString(mType);
8338        out.writeInt(mFlags);
8339        out.writeString(mPackage);
8340        ComponentName.writeToParcel(mComponent, out);
8341
8342        if (mSourceBounds != null) {
8343            out.writeInt(1);
8344            mSourceBounds.writeToParcel(out, flags);
8345        } else {
8346            out.writeInt(0);
8347        }
8348
8349        if (mCategories != null) {
8350            final int N = mCategories.size();
8351            out.writeInt(N);
8352            for (int i=0; i<N; i++) {
8353                out.writeString(mCategories.valueAt(i));
8354            }
8355        } else {
8356            out.writeInt(0);
8357        }
8358
8359        if (mSelector != null) {
8360            out.writeInt(1);
8361            mSelector.writeToParcel(out, flags);
8362        } else {
8363            out.writeInt(0);
8364        }
8365
8366        if (mClipData != null) {
8367            out.writeInt(1);
8368            mClipData.writeToParcel(out, flags);
8369        } else {
8370            out.writeInt(0);
8371        }
8372        out.writeInt(mContentUserHint);
8373        out.writeBundle(mExtras);
8374    }
8375
8376    public static final Parcelable.Creator<Intent> CREATOR
8377            = new Parcelable.Creator<Intent>() {
8378        public Intent createFromParcel(Parcel in) {
8379            return new Intent(in);
8380        }
8381        public Intent[] newArray(int size) {
8382            return new Intent[size];
8383        }
8384    };
8385
8386    /** @hide */
8387    protected Intent(Parcel in) {
8388        readFromParcel(in);
8389    }
8390
8391    public void readFromParcel(Parcel in) {
8392        setAction(in.readString());
8393        mData = Uri.CREATOR.createFromParcel(in);
8394        mType = in.readString();
8395        mFlags = in.readInt();
8396        mPackage = in.readString();
8397        mComponent = ComponentName.readFromParcel(in);
8398
8399        if (in.readInt() != 0) {
8400            mSourceBounds = Rect.CREATOR.createFromParcel(in);
8401        }
8402
8403        int N = in.readInt();
8404        if (N > 0) {
8405            mCategories = new ArraySet<String>();
8406            int i;
8407            for (i=0; i<N; i++) {
8408                mCategories.add(in.readString().intern());
8409            }
8410        } else {
8411            mCategories = null;
8412        }
8413
8414        if (in.readInt() != 0) {
8415            mSelector = new Intent(in);
8416        }
8417
8418        if (in.readInt() != 0) {
8419            mClipData = new ClipData(in);
8420        }
8421        mContentUserHint = in.readInt();
8422        mExtras = in.readBundle();
8423    }
8424
8425    /**
8426     * Parses the "intent" element (and its children) from XML and instantiates
8427     * an Intent object.  The given XML parser should be located at the tag
8428     * where parsing should start (often named "intent"), from which the
8429     * basic action, data, type, and package and class name will be
8430     * retrieved.  The function will then parse in to any child elements,
8431     * looking for <category android:name="xxx"> tags to add categories and
8432     * <extra android:name="xxx" android:value="yyy"> to attach extra data
8433     * to the intent.
8434     *
8435     * @param resources The Resources to use when inflating resources.
8436     * @param parser The XML parser pointing at an "intent" tag.
8437     * @param attrs The AttributeSet interface for retrieving extended
8438     * attribute data at the current <var>parser</var> location.
8439     * @return An Intent object matching the XML data.
8440     * @throws XmlPullParserException If there was an XML parsing error.
8441     * @throws IOException If there was an I/O error.
8442     */
8443    public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
8444            throws XmlPullParserException, IOException {
8445        Intent intent = new Intent();
8446
8447        TypedArray sa = resources.obtainAttributes(attrs,
8448                com.android.internal.R.styleable.Intent);
8449
8450        intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action));
8451
8452        String data = sa.getString(com.android.internal.R.styleable.Intent_data);
8453        String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType);
8454        intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType);
8455
8456        String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage);
8457        String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass);
8458        if (packageName != null && className != null) {
8459            intent.setComponent(new ComponentName(packageName, className));
8460        }
8461
8462        sa.recycle();
8463
8464        int outerDepth = parser.getDepth();
8465        int type;
8466        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
8467               && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
8468            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
8469                continue;
8470            }
8471
8472            String nodeName = parser.getName();
8473            if (nodeName.equals(TAG_CATEGORIES)) {
8474                sa = resources.obtainAttributes(attrs,
8475                        com.android.internal.R.styleable.IntentCategory);
8476                String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name);
8477                sa.recycle();
8478
8479                if (cat != null) {
8480                    intent.addCategory(cat);
8481                }
8482                XmlUtils.skipCurrentTag(parser);
8483
8484            } else if (nodeName.equals(TAG_EXTRA)) {
8485                if (intent.mExtras == null) {
8486                    intent.mExtras = new Bundle();
8487                }
8488                resources.parseBundleExtra(TAG_EXTRA, attrs, intent.mExtras);
8489                XmlUtils.skipCurrentTag(parser);
8490
8491            } else {
8492                XmlUtils.skipCurrentTag(parser);
8493            }
8494        }
8495
8496        return intent;
8497    }
8498
8499    /** @hide */
8500    public void saveToXml(XmlSerializer out) throws IOException {
8501        if (mAction != null) {
8502            out.attribute(null, ATTR_ACTION, mAction);
8503        }
8504        if (mData != null) {
8505            out.attribute(null, ATTR_DATA, mData.toString());
8506        }
8507        if (mType != null) {
8508            out.attribute(null, ATTR_TYPE, mType);
8509        }
8510        if (mComponent != null) {
8511            out.attribute(null, ATTR_COMPONENT, mComponent.flattenToShortString());
8512        }
8513        out.attribute(null, ATTR_FLAGS, Integer.toHexString(getFlags()));
8514
8515        if (mCategories != null) {
8516            out.startTag(null, TAG_CATEGORIES);
8517            for (int categoryNdx = mCategories.size() - 1; categoryNdx >= 0; --categoryNdx) {
8518                out.attribute(null, ATTR_CATEGORY, mCategories.valueAt(categoryNdx));
8519            }
8520            out.endTag(null, TAG_CATEGORIES);
8521        }
8522    }
8523
8524    /** @hide */
8525    public static Intent restoreFromXml(XmlPullParser in) throws IOException,
8526            XmlPullParserException {
8527        Intent intent = new Intent();
8528        final int outerDepth = in.getDepth();
8529
8530        int attrCount = in.getAttributeCount();
8531        for (int attrNdx = attrCount - 1; attrNdx >= 0; --attrNdx) {
8532            final String attrName = in.getAttributeName(attrNdx);
8533            final String attrValue = in.getAttributeValue(attrNdx);
8534            if (ATTR_ACTION.equals(attrName)) {
8535                intent.setAction(attrValue);
8536            } else if (ATTR_DATA.equals(attrName)) {
8537                intent.setData(Uri.parse(attrValue));
8538            } else if (ATTR_TYPE.equals(attrName)) {
8539                intent.setType(attrValue);
8540            } else if (ATTR_COMPONENT.equals(attrName)) {
8541                intent.setComponent(ComponentName.unflattenFromString(attrValue));
8542            } else if (ATTR_FLAGS.equals(attrName)) {
8543                intent.setFlags(Integer.valueOf(attrValue, 16));
8544            } else {
8545                Log.e("Intent", "restoreFromXml: unknown attribute=" + attrName);
8546            }
8547        }
8548
8549        int event;
8550        String name;
8551        while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
8552                (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) {
8553            if (event == XmlPullParser.START_TAG) {
8554                name = in.getName();
8555                if (TAG_CATEGORIES.equals(name)) {
8556                    attrCount = in.getAttributeCount();
8557                    for (int attrNdx = attrCount - 1; attrNdx >= 0; --attrNdx) {
8558                        intent.addCategory(in.getAttributeValue(attrNdx));
8559                    }
8560                } else {
8561                    Log.w("Intent", "restoreFromXml: unknown name=" + name);
8562                    XmlUtils.skipCurrentTag(in);
8563                }
8564            }
8565        }
8566
8567        return intent;
8568    }
8569
8570    /**
8571     * Normalize a MIME data type.
8572     *
8573     * <p>A normalized MIME type has white-space trimmed,
8574     * content-type parameters removed, and is lower-case.
8575     * This aligns the type with Android best practices for
8576     * intent filtering.
8577     *
8578     * <p>For example, "text/plain; charset=utf-8" becomes "text/plain".
8579     * "text/x-vCard" becomes "text/x-vcard".
8580     *
8581     * <p>All MIME types received from outside Android (such as user input,
8582     * or external sources like Bluetooth, NFC, or the Internet) should
8583     * be normalized before they are used to create an Intent.
8584     *
8585     * @param type MIME data type to normalize
8586     * @return normalized MIME data type, or null if the input was null
8587     * @see #setType
8588     * @see #setTypeAndNormalize
8589     */
8590    public static String normalizeMimeType(String type) {
8591        if (type == null) {
8592            return null;
8593        }
8594
8595        type = type.trim().toLowerCase(Locale.ROOT);
8596
8597        final int semicolonIndex = type.indexOf(';');
8598        if (semicolonIndex != -1) {
8599            type = type.substring(0, semicolonIndex);
8600        }
8601        return type;
8602    }
8603
8604    /**
8605     * Prepare this {@link Intent} to leave an app process.
8606     *
8607     * @hide
8608     */
8609    public void prepareToLeaveProcess() {
8610        setAllowFds(false);
8611
8612        if (mSelector != null) {
8613            mSelector.prepareToLeaveProcess();
8614        }
8615        if (mClipData != null) {
8616            mClipData.prepareToLeaveProcess();
8617        }
8618
8619        if (mData != null && StrictMode.vmFileUriExposureEnabled()) {
8620            // There are several ACTION_MEDIA_* broadcasts that send file://
8621            // Uris, so only check common actions.
8622            if (ACTION_VIEW.equals(mAction) ||
8623                    ACTION_EDIT.equals(mAction) ||
8624                    ACTION_ATTACH_DATA.equals(mAction)) {
8625                mData.checkFileUriExposed("Intent.getData()");
8626            }
8627        }
8628    }
8629
8630    /**
8631     * @hide
8632     */
8633    public void prepareToEnterProcess() {
8634        if (mContentUserHint != UserHandle.USER_CURRENT) {
8635            if (UserHandle.getAppId(Process.myUid()) != Process.SYSTEM_UID) {
8636                fixUris(mContentUserHint);
8637                mContentUserHint = UserHandle.USER_CURRENT;
8638            }
8639        }
8640    }
8641
8642    /**
8643     * @hide
8644     */
8645     public void fixUris(int contentUserHint) {
8646        Uri data = getData();
8647        if (data != null) {
8648            mData = maybeAddUserId(data, contentUserHint);
8649        }
8650        if (mClipData != null) {
8651            mClipData.fixUris(contentUserHint);
8652        }
8653        String action = getAction();
8654        if (ACTION_SEND.equals(action)) {
8655            final Uri stream = getParcelableExtra(EXTRA_STREAM);
8656            if (stream != null) {
8657                putExtra(EXTRA_STREAM, maybeAddUserId(stream, contentUserHint));
8658            }
8659        } else if (ACTION_SEND_MULTIPLE.equals(action)) {
8660            final ArrayList<Uri> streams = getParcelableArrayListExtra(EXTRA_STREAM);
8661            if (streams != null) {
8662                ArrayList<Uri> newStreams = new ArrayList<Uri>();
8663                for (int i = 0; i < streams.size(); i++) {
8664                    newStreams.add(maybeAddUserId(streams.get(i), contentUserHint));
8665                }
8666                putParcelableArrayListExtra(EXTRA_STREAM, newStreams);
8667            }
8668        } else if (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)
8669                || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(action)
8670                || MediaStore.ACTION_VIDEO_CAPTURE.equals(action)) {
8671            final Uri output = getParcelableExtra(MediaStore.EXTRA_OUTPUT);
8672            if (output != null) {
8673                putExtra(MediaStore.EXTRA_OUTPUT, maybeAddUserId(output, contentUserHint));
8674            }
8675        }
8676     }
8677
8678    /**
8679     * Migrate any {@link #EXTRA_STREAM} in {@link #ACTION_SEND} and
8680     * {@link #ACTION_SEND_MULTIPLE} to {@link ClipData}. Also inspects nested
8681     * intents in {@link #ACTION_CHOOSER}.
8682     *
8683     * @return Whether any contents were migrated.
8684     * @hide
8685     */
8686    public boolean migrateExtraStreamToClipData() {
8687        // Refuse to touch if extras already parcelled
8688        if (mExtras != null && mExtras.isParcelled()) return false;
8689
8690        // Bail when someone already gave us ClipData
8691        if (getClipData() != null) return false;
8692
8693        final String action = getAction();
8694        if (ACTION_CHOOSER.equals(action)) {
8695            // Inspect contained intents to see if we need to migrate extras. We
8696            // don't promote ClipData to the parent, since ChooserActivity will
8697            // already start the picked item as the caller, and we can't combine
8698            // the flags in a safe way.
8699
8700            boolean migrated = false;
8701            try {
8702                final Intent intent = getParcelableExtra(EXTRA_INTENT);
8703                if (intent != null) {
8704                    migrated |= intent.migrateExtraStreamToClipData();
8705                }
8706            } catch (ClassCastException e) {
8707            }
8708            try {
8709                final Parcelable[] intents = getParcelableArrayExtra(EXTRA_INITIAL_INTENTS);
8710                if (intents != null) {
8711                    for (int i = 0; i < intents.length; i++) {
8712                        final Intent intent = (Intent) intents[i];
8713                        if (intent != null) {
8714                            migrated |= intent.migrateExtraStreamToClipData();
8715                        }
8716                    }
8717                }
8718            } catch (ClassCastException e) {
8719            }
8720            return migrated;
8721
8722        } else if (ACTION_SEND.equals(action)) {
8723            try {
8724                final Uri stream = getParcelableExtra(EXTRA_STREAM);
8725                final CharSequence text = getCharSequenceExtra(EXTRA_TEXT);
8726                final String htmlText = getStringExtra(EXTRA_HTML_TEXT);
8727                if (stream != null || text != null || htmlText != null) {
8728                    final ClipData clipData = new ClipData(
8729                            null, new String[] { getType() },
8730                            new ClipData.Item(text, htmlText, null, stream));
8731                    setClipData(clipData);
8732                    addFlags(FLAG_GRANT_READ_URI_PERMISSION);
8733                    return true;
8734                }
8735            } catch (ClassCastException e) {
8736            }
8737
8738        } else if (ACTION_SEND_MULTIPLE.equals(action)) {
8739            try {
8740                final ArrayList<Uri> streams = getParcelableArrayListExtra(EXTRA_STREAM);
8741                final ArrayList<CharSequence> texts = getCharSequenceArrayListExtra(EXTRA_TEXT);
8742                final ArrayList<String> htmlTexts = getStringArrayListExtra(EXTRA_HTML_TEXT);
8743                int num = -1;
8744                if (streams != null) {
8745                    num = streams.size();
8746                }
8747                if (texts != null) {
8748                    if (num >= 0 && num != texts.size()) {
8749                        // Wha...!  F- you.
8750                        return false;
8751                    }
8752                    num = texts.size();
8753                }
8754                if (htmlTexts != null) {
8755                    if (num >= 0 && num != htmlTexts.size()) {
8756                        // Wha...!  F- you.
8757                        return false;
8758                    }
8759                    num = htmlTexts.size();
8760                }
8761                if (num > 0) {
8762                    final ClipData clipData = new ClipData(
8763                            null, new String[] { getType() },
8764                            makeClipItem(streams, texts, htmlTexts, 0));
8765
8766                    for (int i = 1; i < num; i++) {
8767                        clipData.addItem(makeClipItem(streams, texts, htmlTexts, i));
8768                    }
8769
8770                    setClipData(clipData);
8771                    addFlags(FLAG_GRANT_READ_URI_PERMISSION);
8772                    return true;
8773                }
8774            } catch (ClassCastException e) {
8775            }
8776        } else if (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)
8777                || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(action)
8778                || MediaStore.ACTION_VIDEO_CAPTURE.equals(action)) {
8779            final Uri output;
8780            try {
8781                output = getParcelableExtra(MediaStore.EXTRA_OUTPUT);
8782            } catch (ClassCastException e) {
8783                return false;
8784            }
8785            if (output != null) {
8786                setClipData(ClipData.newRawUri("", output));
8787                addFlags(FLAG_GRANT_WRITE_URI_PERMISSION|FLAG_GRANT_READ_URI_PERMISSION);
8788                return true;
8789            }
8790        }
8791
8792        return false;
8793    }
8794
8795    private static ClipData.Item makeClipItem(ArrayList<Uri> streams, ArrayList<CharSequence> texts,
8796            ArrayList<String> htmlTexts, int which) {
8797        Uri uri = streams != null ? streams.get(which) : null;
8798        CharSequence text = texts != null ? texts.get(which) : null;
8799        String htmlText = htmlTexts != null ? htmlTexts.get(which) : null;
8800        return new ClipData.Item(text, htmlText, null, uri);
8801    }
8802
8803    /** @hide */
8804    public boolean isDocument() {
8805        return (mFlags & FLAG_ACTIVITY_NEW_DOCUMENT) == FLAG_ACTIVITY_NEW_DOCUMENT;
8806    }
8807}
8808