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