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