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