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