• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.content;
18 
19 import org.xmlpull.v1.XmlPullParser;
20 import org.xmlpull.v1.XmlPullParserException;
21 
22 import android.annotation.SdkConstant;
23 import android.annotation.SdkConstant.SdkConstantType;
24 import android.content.pm.ActivityInfo;
25 import android.content.pm.PackageManager;
26 import android.content.pm.ResolveInfo;
27 import android.content.res.Resources;
28 import android.content.res.TypedArray;
29 import android.net.Uri;
30 import android.os.Bundle;
31 import android.os.IBinder;
32 import android.os.Parcel;
33 import android.os.Parcelable;
34 import android.util.AttributeSet;
35 import android.util.Log;
36 import com.android.internal.util.XmlUtils;
37 
38 import java.io.IOException;
39 import java.io.Serializable;
40 import java.net.URISyntaxException;
41 import java.util.ArrayList;
42 import java.util.HashSet;
43 import java.util.Iterator;
44 import java.util.Set;
45 
46 /**
47  * An intent is an abstract description of an operation to be performed.  It
48  * can be used with {@link Context#startActivity(Intent) startActivity} to
49  * launch an {@link android.app.Activity},
50  * {@link android.content.Context#sendBroadcast(Intent) broadcastIntent} to
51  * send it to any interested {@link BroadcastReceiver BroadcastReceiver} components,
52  * and {@link android.content.Context#startService} or
53  * {@link android.content.Context#bindService} to communicate with a
54  * background {@link android.app.Service}.
55  *
56  * <p>An Intent provides a facility for performing late runtime binding between
57  * the code in different applications.  Its most significant use is in the
58  * launching of activities, where it can be thought of as the glue between
59  * activities. It is
60  * basically a passive data structure holding an abstract description of an
61  * action to be performed. The primary pieces of information in an intent
62  * are:</p>
63  *
64  * <ul>
65  *   <li> <p><b>action</b> -- The general action to be performed, such as
66  *     {@link #ACTION_VIEW}, {@link #ACTION_EDIT}, {@link #ACTION_MAIN},
67  *     etc.</p>
68  *   </li>
69  *   <li> <p><b>data</b> -- The data to operate on, such as a person record
70  *     in the contacts database, expressed as a {@link android.net.Uri}.</p>
71  *   </li>
72  * </ul>
73  *
74  *
75  * <p>Some examples of action/data pairs are:</p>
76  *
77  * <ul>
78  *   <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/1</i></b> -- Display
79  *     information about the person whose identifier is "1".</p>
80  *   </li>
81  *   <li> <p><b>{@link #ACTION_DIAL} <i>content://contacts/people/1</i></b> -- Display
82  *     the phone dialer with the person filled in.</p>
83  *   </li>
84  *   <li> <p><b>{@link #ACTION_VIEW} <i>tel:123</i></b> -- Display
85  *     the phone dialer with the given number filled in.  Note how the
86  *     VIEW action does what what is considered the most reasonable thing for
87  *     a particular URI.</p>
88  *   </li>
89  *   <li> <p><b>{@link #ACTION_DIAL} <i>tel:123</i></b> -- Display
90  *     the phone dialer with the given number filled in.</p>
91  *   </li>
92  *   <li> <p><b>{@link #ACTION_EDIT} <i>content://contacts/people/1</i></b> -- Edit
93  *     information about the person whose identifier is "1".</p>
94  *   </li>
95  *   <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/</i></b> -- Display
96  *     a list of people, which the user can browse through.  This example is a
97  *     typical top-level entry into the Contacts application, showing you the
98  *     list of people. Selecting a particular person to view would result in a
99  *     new intent { <b>{@link #ACTION_VIEW} <i>content://contacts/N</i></b> }
100  *     being used to start an activity to display that person.</p>
101  *   </li>
102  * </ul>
103  *
104  * <p>In addition to these primary attributes, there are a number of secondary
105  * attributes that you can also include with an intent:</p>
106  *
107  * <ul>
108  *     <li> <p><b>category</b> -- Gives additional information about the action
109  *         to execute.  For example, {@link #CATEGORY_LAUNCHER} means it should
110  *         appear in the Launcher as a top-level application, while
111  *         {@link #CATEGORY_ALTERNATIVE} means it should be included in a list
112  *         of alternative actions the user can perform on a piece of data.</p>
113  *     <li> <p><b>type</b> -- Specifies an explicit type (a MIME type) of the
114  *         intent data.  Normally the type is inferred from the data itself.
115  *         By setting this attribute, you disable that evaluation and force
116  *         an explicit type.</p>
117  *     <li> <p><b>component</b> -- Specifies an explicit name of a component
118  *         class to use for the intent.  Normally this is determined by looking
119  *         at the other information in the intent (the action, data/type, and
120  *         categories) and matching that with a component that can handle it.
121  *         If this attribute is set then none of the evaluation is performed,
122  *         and this component is used exactly as is.  By specifying this attribute,
123  *         all of the other Intent attributes become optional.</p>
124  *     <li> <p><b>extras</b> -- This is a {@link Bundle} of any additional information.
125  *         This can be used to provide extended information to the component.
126  *         For example, if we have a action to send an e-mail message, we could
127  *         also include extra pieces of data here to supply a subject, body,
128  *         etc.</p>
129  * </ul>
130  *
131  * <p>Here are some examples of other operations you can specify as intents
132  * using these additional parameters:</p>
133  *
134  * <ul>
135  *   <li> <p><b>{@link #ACTION_MAIN} with category {@link #CATEGORY_HOME}</b> --
136  *     Launch the home screen.</p>
137  *   </li>
138  *   <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
139  *     <i>{@link android.provider.Contacts.Phones#CONTENT_URI
140  *     vnd.android.cursor.item/phone}</i></b>
141  *     -- Display the list of people's phone numbers, allowing the user to
142  *     browse through them and pick one and return it to the parent activity.</p>
143  *   </li>
144  *   <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
145  *     <i>*{@literal /}*</i> and category {@link #CATEGORY_OPENABLE}</b>
146  *     -- Display all pickers for data that can be opened with
147  *     {@link ContentResolver#openInputStream(Uri) ContentResolver.openInputStream()},
148  *     allowing the user to pick one of them and then some data inside of it
149  *     and returning the resulting URI to the caller.  This can be used,
150  *     for example, in an e-mail application to allow the user to pick some
151  *     data to include as an attachment.</p>
152  *   </li>
153  * </ul>
154  *
155  * <p>There are a variety of standard Intent action and category constants
156  * defined in the Intent class, but applications can also define their own.
157  * These strings use java style scoping, to ensure they are unique -- for
158  * example, the standard {@link #ACTION_VIEW} is called
159  * "android.intent.action.VIEW".</p>
160  *
161  * <p>Put together, the set of actions, data types, categories, and extra data
162  * defines a language for the system allowing for the expression of phrases
163  * such as "call john smith's cell".  As applications are added to the system,
164  * they can extend this language by adding new actions, types, and categories, or
165  * they can modify the behavior of existing phrases by supplying their own
166  * activities that handle them.</p>
167  *
168  * <a name="IntentResolution"></a>
169  * <h3>Intent Resolution</h3>
170  *
171  * <p>There are two primary forms of intents you will use.
172  *
173  * <ul>
174  *     <li> <p><b>Explicit Intents</b> have specified a component (via
175  *     {@link #setComponent} or {@link #setClass}), which provides the exact
176  *     class to be run.  Often these will not include any other information,
177  *     simply being a way for an application to launch various internal
178  *     activities it has as the user interacts with the application.
179  *
180  *     <li> <p><b>Implicit Intents</b> have not specified a component;
181  *     instead, they must include enough information for the system to
182  *     determine which of the available components is best to run for that
183  *     intent.
184  * </ul>
185  *
186  * <p>When using implicit intents, given such an arbitrary intent we need to
187  * know what to do with it. This is handled by the process of <em>Intent
188  * resolution</em>, which maps an Intent to an {@link android.app.Activity},
189  * {@link BroadcastReceiver}, or {@link android.app.Service} (or sometimes two or
190  * more activities/receivers) that can handle it.</p>
191  *
192  * <p>The intent resolution mechanism basically revolves around matching an
193  * Intent against all of the &lt;intent-filter&gt; descriptions in the
194  * installed application packages.  (Plus, in the case of broadcasts, any {@link BroadcastReceiver}
195  * objects explicitly registered with {@link Context#registerReceiver}.)  More
196  * details on this can be found in the documentation on the {@link
197  * IntentFilter} class.</p>
198  *
199  * <p>There are three pieces of information in the Intent that are used for
200  * resolution: the action, type, and category.  Using this information, a query
201  * is done on the {@link PackageManager} for a component that can handle the
202  * intent. The appropriate component is determined based on the intent
203  * information supplied in the <code>AndroidManifest.xml</code> file as
204  * follows:</p>
205  *
206  * <ul>
207  *     <li> <p>The <b>action</b>, if given, must be listed by the component as
208  *         one it handles.</p>
209  *     <li> <p>The <b>type</b> is retrieved from the Intent's data, if not
210  *         already supplied in the Intent.  Like the action, if a type is
211  *         included in the intent (either explicitly or implicitly in its
212  *         data), then this must be listed by the component as one it handles.</p>
213  *     <li> For data that is not a <code>content:</code> URI and where no explicit
214  *         type is included in the Intent, instead the <b>scheme</b> of the
215  *         intent data (such as <code>http:</code> or <code>mailto:</code>) is
216  *         considered. Again like the action, if we are matching a scheme it
217  *         must be listed by the component as one it can handle.
218  *     <li> <p>The <b>categories</b>, if supplied, must <em>all</em> be listed
219  *         by the activity as categories it handles.  That is, if you include
220  *         the categories {@link #CATEGORY_LAUNCHER} and
221  *         {@link #CATEGORY_ALTERNATIVE}, then you will only resolve to components
222  *         with an intent that lists <em>both</em> of those categories.
223  *         Activities will very often need to support the
224  *         {@link #CATEGORY_DEFAULT} so that they can be found by
225  *         {@link Context#startActivity Context.startActivity()}.</p>
226  * </ul>
227  *
228  * <p>For example, consider the Note Pad sample application that
229  * allows user to browse through a list of notes data and view details about
230  * individual items.  Text in italics indicate places were you would replace a
231  * name with one specific to your own package.</p>
232  *
233  * <pre> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
234  *       package="<i>com.android.notepad</i>"&gt;
235  *     &lt;application android:icon="@drawable/app_notes"
236  *             android:label="@string/app_name"&gt;
237  *
238  *         &lt;provider class=".NotePadProvider"
239  *                 android:authorities="<i>com.google.provider.NotePad</i>" /&gt;
240  *
241  *         &lt;activity class=".NotesList" android:label="@string/title_notes_list"&gt;
242  *             &lt;intent-filter&gt;
243  *                 &lt;action android:name="android.intent.action.MAIN" /&gt;
244  *                 &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
245  *             &lt;/intent-filter&gt;
246  *             &lt;intent-filter&gt;
247  *                 &lt;action android:name="android.intent.action.VIEW" /&gt;
248  *                 &lt;action android:name="android.intent.action.EDIT" /&gt;
249  *                 &lt;action android:name="android.intent.action.PICK" /&gt;
250  *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
251  *                 &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
252  *             &lt;/intent-filter&gt;
253  *             &lt;intent-filter&gt;
254  *                 &lt;action android:name="android.intent.action.GET_CONTENT" /&gt;
255  *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
256  *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
257  *             &lt;/intent-filter&gt;
258  *         &lt;/activity&gt;
259  *
260  *         &lt;activity class=".NoteEditor" android:label="@string/title_note"&gt;
261  *             &lt;intent-filter android:label="@string/resolve_edit"&gt;
262  *                 &lt;action android:name="android.intent.action.VIEW" /&gt;
263  *                 &lt;action android:name="android.intent.action.EDIT" /&gt;
264  *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
265  *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
266  *             &lt;/intent-filter&gt;
267  *
268  *             &lt;intent-filter&gt;
269  *                 &lt;action android:name="android.intent.action.INSERT" /&gt;
270  *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
271  *                 &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
272  *             &lt;/intent-filter&gt;
273  *
274  *         &lt;/activity&gt;
275  *
276  *         &lt;activity class=".TitleEditor" android:label="@string/title_edit_title"
277  *                 android:theme="@android:style/Theme.Dialog"&gt;
278  *             &lt;intent-filter android:label="@string/resolve_title"&gt;
279  *                 &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
280  *                 &lt;category android:name="android.intent.category.DEFAULT" /&gt;
281  *                 &lt;category android:name="android.intent.category.ALTERNATIVE" /&gt;
282  *                 &lt;category android:name="android.intent.category.SELECTED_ALTERNATIVE" /&gt;
283  *                 &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
284  *             &lt;/intent-filter&gt;
285  *         &lt;/activity&gt;
286  *
287  *     &lt;/application&gt;
288  * &lt;/manifest&gt;</pre>
289  *
290  * <p>The first activity,
291  * <code>com.android.notepad.NotesList</code>, serves as our main
292  * entry into the app.  It can do three things as described by its three intent
293  * templates:
294  * <ol>
295  * <li><pre>
296  * &lt;intent-filter&gt;
297  *     &lt;action android:name="{@link #ACTION_MAIN android.intent.action.MAIN}" /&gt;
298  *     &lt;category android:name="{@link #CATEGORY_LAUNCHER android.intent.category.LAUNCHER}" /&gt;
299  * &lt;/intent-filter&gt;</pre>
300  * <p>This provides a top-level entry into the NotePad application: the standard
301  * MAIN action is a main entry point (not requiring any other information in
302  * the Intent), and the LAUNCHER category says that this entry point should be
303  * listed in the application launcher.</p>
304  * <li><pre>
305  * &lt;intent-filter&gt;
306  *     &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
307  *     &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
308  *     &lt;action android:name="{@link #ACTION_PICK android.intent.action.PICK}" /&gt;
309  *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
310  *     &lt;data mimeType:name="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
311  * &lt;/intent-filter&gt;</pre>
312  * <p>This declares the things that the activity can do on a directory of
313  * notes.  The type being supported is given with the &lt;type&gt; tag, where
314  * <code>vnd.android.cursor.dir/vnd.google.note</code> is a URI from which
315  * a Cursor of zero or more items (<code>vnd.android.cursor.dir</code>) can
316  * be retrieved which holds our note pad data (<code>vnd.google.note</code>).
317  * The activity allows the user to view or edit the directory of data (via
318  * the VIEW and EDIT actions), or to pick a particular note and return it
319  * to the caller (via the PICK action).  Note also the DEFAULT category
320  * supplied here: this is <em>required</em> for the
321  * {@link Context#startActivity Context.startActivity} method to resolve your
322  * activity when its component name is not explicitly specified.</p>
323  * <li><pre>
324  * &lt;intent-filter&gt;
325  *     &lt;action android:name="{@link #ACTION_GET_CONTENT android.intent.action.GET_CONTENT}" /&gt;
326  *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
327  *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
328  * &lt;/intent-filter&gt;</pre>
329  * <p>This filter describes the ability return to the caller a note selected by
330  * the user without needing to know where it came from.  The data type
331  * <code>vnd.android.cursor.item/vnd.google.note</code> is a URI from which
332  * a Cursor of exactly one (<code>vnd.android.cursor.item</code>) item can
333  * be retrieved which contains our note pad data (<code>vnd.google.note</code>).
334  * The GET_CONTENT action is similar to the PICK action, where the activity
335  * will return to its caller a piece of data selected by the user.  Here,
336  * however, the caller specifies the type of data they desire instead of
337  * the type of data the user will be picking from.</p>
338  * </ol>
339  *
340  * <p>Given these capabilities, the following intents will resolve to the
341  * NotesList activity:</p>
342  *
343  * <ul>
344  *     <li> <p><b>{ action=android.app.action.MAIN }</b> matches all of the
345  *         activities that can be used as top-level entry points into an
346  *         application.</p>
347  *     <li> <p><b>{ action=android.app.action.MAIN,
348  *         category=android.app.category.LAUNCHER }</b> is the actual intent
349  *         used by the Launcher to populate its top-level list.</p>
350  *     <li> <p><b>{ action=android.intent.action.VIEW
351  *          data=content://com.google.provider.NotePad/notes }</b>
352  *         displays a list of all the notes under
353  *         "content://com.google.provider.NotePad/notes", which
354  *         the user can browse through and see the details on.</p>
355  *     <li> <p><b>{ action=android.app.action.PICK
356  *          data=content://com.google.provider.NotePad/notes }</b>
357  *         provides a list of the notes under
358  *         "content://com.google.provider.NotePad/notes", from which
359  *         the user can pick a note whose data URL is returned back to the caller.</p>
360  *     <li> <p><b>{ action=android.app.action.GET_CONTENT
361  *          type=vnd.android.cursor.item/vnd.google.note }</b>
362  *         is similar to the pick action, but allows the caller to specify the
363  *         kind of data they want back so that the system can find the appropriate
364  *         activity to pick something of that data type.</p>
365  * </ul>
366  *
367  * <p>The second activity,
368  * <code>com.android.notepad.NoteEditor</code>, shows the user a single
369  * note entry and allows them to edit it.  It can do two things as described
370  * by its two intent templates:
371  * <ol>
372  * <li><pre>
373  * &lt;intent-filter android:label="@string/resolve_edit"&gt;
374  *     &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
375  *     &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
376  *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
377  *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
378  * &lt;/intent-filter&gt;</pre>
379  * <p>The first, primary, purpose of this activity is to let the user interact
380  * with a single note, as decribed by the MIME type
381  * <code>vnd.android.cursor.item/vnd.google.note</code>.  The activity can
382  * either VIEW a note or allow the user to EDIT it.  Again we support the
383  * DEFAULT category to allow the activity to be launched without explicitly
384  * specifying its component.</p>
385  * <li><pre>
386  * &lt;intent-filter&gt;
387  *     &lt;action android:name="{@link #ACTION_INSERT android.intent.action.INSERT}" /&gt;
388  *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
389  *     &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
390  * &lt;/intent-filter&gt;</pre>
391  * <p>The secondary use of this activity is to insert a new note entry into
392  * an existing directory of notes.  This is used when the user creates a new
393  * note: the INSERT action is executed on the directory of notes, causing
394  * this activity to run and have the user create the new note data which
395  * it then adds to the content provider.</p>
396  * </ol>
397  *
398  * <p>Given these capabilities, the following intents will resolve to the
399  * NoteEditor activity:</p>
400  *
401  * <ul>
402  *     <li> <p><b>{ action=android.intent.action.VIEW
403  *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
404  *         shows the user the content of note <var>{ID}</var>.</p>
405  *     <li> <p><b>{ action=android.app.action.EDIT
406  *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
407  *         allows the user to edit the content of note <var>{ID}</var>.</p>
408  *     <li> <p><b>{ action=android.app.action.INSERT
409  *          data=content://com.google.provider.NotePad/notes }</b>
410  *         creates a new, empty note in the notes list at
411  *         "content://com.google.provider.NotePad/notes"
412  *         and allows the user to edit it.  If they keep their changes, the URI
413  *         of the newly created note is returned to the caller.</p>
414  * </ul>
415  *
416  * <p>The last activity,
417  * <code>com.android.notepad.TitleEditor</code>, allows the user to
418  * edit the title of a note.  This could be implemented as a class that the
419  * application directly invokes (by explicitly setting its component in
420  * the Intent), but here we show a way you can publish alternative
421  * operations on existing data:</p>
422  *
423  * <pre>
424  * &lt;intent-filter android:label="@string/resolve_title"&gt;
425  *     &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
426  *     &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
427  *     &lt;category android:name="{@link #CATEGORY_ALTERNATIVE android.intent.category.ALTERNATIVE}" /&gt;
428  *     &lt;category android:name="{@link #CATEGORY_SELECTED_ALTERNATIVE android.intent.category.SELECTED_ALTERNATIVE}" /&gt;
429  *     &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
430  * &lt;/intent-filter&gt;</pre>
431  *
432  * <p>In the single intent template here, we
433  * have created our own private action called
434  * <code>com.android.notepad.action.EDIT_TITLE</code> which means to
435  * edit the title of a note.  It must be invoked on a specific note
436  * (data type <code>vnd.android.cursor.item/vnd.google.note</code>) like the previous
437  * view and edit actions, but here displays and edits the title contained
438  * in the note data.
439  *
440  * <p>In addition to supporting the default category as usual, our title editor
441  * also supports two other standard categories: ALTERNATIVE and
442  * SELECTED_ALTERNATIVE.  Implementing
443  * these categories allows others to find the special action it provides
444  * without directly knowing about it, through the
445  * {@link android.content.pm.PackageManager#queryIntentActivityOptions} method, or
446  * more often to build dynamic menu items with
447  * {@link android.view.Menu#addIntentOptions}.  Note that in the intent
448  * template here was also supply an explicit name for the template
449  * (via <code>android:label="@string/resolve_title"</code>) to better control
450  * what the user sees when presented with this activity as an alternative
451  * action to the data they are viewing.
452  *
453  * <p>Given these capabilities, the following intent will resolve to the
454  * TitleEditor activity:</p>
455  *
456  * <ul>
457  *     <li> <p><b>{ action=com.android.notepad.action.EDIT_TITLE
458  *          data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
459  *         displays and allows the user to edit the title associated
460  *         with note <var>{ID}</var>.</p>
461  * </ul>
462  *
463  * <h3>Standard Activity Actions</h3>
464  *
465  * <p>These are the current standard actions that Intent defines for launching
466  * activities (usually through {@link Context#startActivity}.  The most
467  * important, and by far most frequently used, are {@link #ACTION_MAIN} and
468  * {@link #ACTION_EDIT}.
469  *
470  * <ul>
471  *     <li> {@link #ACTION_MAIN}
472  *     <li> {@link #ACTION_VIEW}
473  *     <li> {@link #ACTION_ATTACH_DATA}
474  *     <li> {@link #ACTION_EDIT}
475  *     <li> {@link #ACTION_PICK}
476  *     <li> {@link #ACTION_CHOOSER}
477  *     <li> {@link #ACTION_GET_CONTENT}
478  *     <li> {@link #ACTION_DIAL}
479  *     <li> {@link #ACTION_CALL}
480  *     <li> {@link #ACTION_SEND}
481  *     <li> {@link #ACTION_SENDTO}
482  *     <li> {@link #ACTION_ANSWER}
483  *     <li> {@link #ACTION_INSERT}
484  *     <li> {@link #ACTION_DELETE}
485  *     <li> {@link #ACTION_RUN}
486  *     <li> {@link #ACTION_SYNC}
487  *     <li> {@link #ACTION_PICK_ACTIVITY}
488  *     <li> {@link #ACTION_SEARCH}
489  *     <li> {@link #ACTION_WEB_SEARCH}
490  *     <li> {@link #ACTION_FACTORY_TEST}
491  * </ul>
492  *
493  * <h3>Standard Broadcast Actions</h3>
494  *
495  * <p>These are the current standard actions that Intent defines for receiving
496  * broadcasts (usually through {@link Context#registerReceiver} or a
497  * &lt;receiver&gt; tag in a manifest).
498  *
499  * <ul>
500  *     <li> {@link #ACTION_TIME_TICK}
501  *     <li> {@link #ACTION_TIME_CHANGED}
502  *     <li> {@link #ACTION_TIMEZONE_CHANGED}
503  *     <li> {@link #ACTION_BOOT_COMPLETED}
504  *     <li> {@link #ACTION_PACKAGE_ADDED}
505  *     <li> {@link #ACTION_PACKAGE_CHANGED}
506  *     <li> {@link #ACTION_PACKAGE_REMOVED}
507  *     <li> {@link #ACTION_PACKAGE_RESTARTED}
508  *     <li> {@link #ACTION_PACKAGE_DATA_CLEARED}
509  *     <li> {@link #ACTION_UID_REMOVED}
510  *     <li> {@link #ACTION_BATTERY_CHANGED}
511  *     <li> {@link #ACTION_POWER_CONNECTED}
512  *     <li> {@link #ACTION_POWER_DISCONNECTED}
513  *     <li> {@link #ACTION_SHUTDOWN}
514  * </ul>
515  *
516  * <h3>Standard Categories</h3>
517  *
518  * <p>These are the current standard categories that can be used to further
519  * clarify an Intent via {@link #addCategory}.
520  *
521  * <ul>
522  *     <li> {@link #CATEGORY_DEFAULT}
523  *     <li> {@link #CATEGORY_BROWSABLE}
524  *     <li> {@link #CATEGORY_TAB}
525  *     <li> {@link #CATEGORY_ALTERNATIVE}
526  *     <li> {@link #CATEGORY_SELECTED_ALTERNATIVE}
527  *     <li> {@link #CATEGORY_LAUNCHER}
528  *     <li> {@link #CATEGORY_INFO}
529  *     <li> {@link #CATEGORY_HOME}
530  *     <li> {@link #CATEGORY_PREFERENCE}
531  *     <li> {@link #CATEGORY_TEST}
532  *     <li> {@link #CATEGORY_CAR_DOCK}
533  *     <li> {@link #CATEGORY_DESK_DOCK}
534  * </ul>
535  *
536  * <h3>Standard Extra Data</h3>
537  *
538  * <p>These are the current standard fields that can be used as extra data via
539  * {@link #putExtra}.
540  *
541  * <ul>
542  *     <li> {@link #EXTRA_TEMPLATE}
543  *     <li> {@link #EXTRA_INTENT}
544  *     <li> {@link #EXTRA_STREAM}
545  *     <li> {@link #EXTRA_TEXT}
546  * </ul>
547  *
548  * <h3>Flags</h3>
549  *
550  * <p>These are the possible flags that can be used in the Intent via
551  * {@link #setFlags} and {@link #addFlags}.  See {@link #setFlags} for a list
552  * of all possible flags.
553  */
554 public class Intent implements Parcelable {
555     // ---------------------------------------------------------------------
556     // ---------------------------------------------------------------------
557     // Standard intent activity actions (see action variable).
558 
559     /**
560      *  Activity Action: Start as a main entry point, does not expect to
561      *  receive data.
562      *  <p>Input: nothing
563      *  <p>Output: nothing
564      */
565     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
566     public static final String ACTION_MAIN = "android.intent.action.MAIN";
567 
568     /**
569      * Activity Action: Display the data to the user.  This is the most common
570      * action performed on data -- it is the generic action you can use on
571      * a piece of data to get the most reasonable thing to occur.  For example,
572      * when used on a contacts entry it will view the entry; when used on a
573      * mailto: URI it will bring up a compose window filled with the information
574      * supplied by the URI; when used with a tel: URI it will invoke the
575      * dialer.
576      * <p>Input: {@link #getData} is URI from which to retrieve data.
577      * <p>Output: nothing.
578      */
579     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
580     public static final String ACTION_VIEW = "android.intent.action.VIEW";
581 
582     /**
583      * A synonym for {@link #ACTION_VIEW}, the "standard" action that is
584      * performed on a piece of data.
585      */
586     public static final String ACTION_DEFAULT = ACTION_VIEW;
587 
588     /**
589      * Used to indicate that some piece of data should be attached to some other
590      * place.  For example, image data could be attached to a contact.  It is up
591      * to the recipient to decide where the data should be attached; the intent
592      * does not specify the ultimate destination.
593      * <p>Input: {@link #getData} is URI of data to be attached.
594      * <p>Output: nothing.
595      */
596     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
597     public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
598 
599     /**
600      * Activity Action: Provide explicit editable access to the given data.
601      * <p>Input: {@link #getData} is URI of data to be edited.
602      * <p>Output: nothing.
603      */
604     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
605     public static final String ACTION_EDIT = "android.intent.action.EDIT";
606 
607     /**
608      * Activity Action: Pick an existing item, or insert a new item, and then edit it.
609      * <p>Input: {@link #getType} is the desired MIME type of the item to create or edit.
610      * The extras can contain type specific data to pass through to the editing/creating
611      * activity.
612      * <p>Output: The URI of the item that was picked.  This must be a content:
613      * URI so that any receiver can access it.
614      */
615     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
616     public static final String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
617 
618     /**
619      * Activity Action: Pick an item from the data, returning what was selected.
620      * <p>Input: {@link #getData} is URI containing a directory of data
621      * (vnd.android.cursor.dir/*) from which to pick an item.
622      * <p>Output: The URI of the item that was picked.
623      */
624     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
625     public static final String ACTION_PICK = "android.intent.action.PICK";
626 
627     /**
628      * Activity Action: Creates a shortcut.
629      * <p>Input: Nothing.</p>
630      * <p>Output: An Intent representing the shortcut. The intent must contain three
631      * extras: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String),
632      * and SHORTCUT_ICON (value: Bitmap) or SHORTCUT_ICON_RESOURCE
633      * (value: ShortcutIconResource).</p>
634      *
635      * @see #EXTRA_SHORTCUT_INTENT
636      * @see #EXTRA_SHORTCUT_NAME
637      * @see #EXTRA_SHORTCUT_ICON
638      * @see #EXTRA_SHORTCUT_ICON_RESOURCE
639      * @see android.content.Intent.ShortcutIconResource
640      */
641     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
642     public static final String ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
643 
644     /**
645      * The name of the extra used to define the Intent of a shortcut.
646      *
647      * @see #ACTION_CREATE_SHORTCUT
648      */
649     public static final String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
650     /**
651      * The name of the extra used to define the name of a shortcut.
652      *
653      * @see #ACTION_CREATE_SHORTCUT
654      */
655     public static final String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
656     /**
657      * The name of the extra used to define the icon, as a Bitmap, of a shortcut.
658      *
659      * @see #ACTION_CREATE_SHORTCUT
660      */
661     public static final String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
662     /**
663      * The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.
664      *
665      * @see #ACTION_CREATE_SHORTCUT
666      * @see android.content.Intent.ShortcutIconResource
667      */
668     public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
669             "android.intent.extra.shortcut.ICON_RESOURCE";
670 
671     /**
672      * Represents a shortcut/live folder icon resource.
673      *
674      * @see Intent#ACTION_CREATE_SHORTCUT
675      * @see Intent#EXTRA_SHORTCUT_ICON_RESOURCE
676      * @see android.provider.LiveFolders#ACTION_CREATE_LIVE_FOLDER
677      * @see android.provider.LiveFolders#EXTRA_LIVE_FOLDER_ICON
678      */
679     public static class ShortcutIconResource implements Parcelable {
680         /**
681          * The package name of the application containing the icon.
682          */
683         public String packageName;
684 
685         /**
686          * The resource name of the icon, including package, name and type.
687          */
688         public String resourceName;
689 
690         /**
691          * Creates a new ShortcutIconResource for the specified context and resource
692          * identifier.
693          *
694          * @param context The context of the application.
695          * @param resourceId The resource idenfitier for the icon.
696          * @return A new ShortcutIconResource with the specified's context package name
697          *         and icon resource idenfitier.
698          */
fromContext(Context context, int resourceId)699         public static ShortcutIconResource fromContext(Context context, int resourceId) {
700             ShortcutIconResource icon = new ShortcutIconResource();
701             icon.packageName = context.getPackageName();
702             icon.resourceName = context.getResources().getResourceName(resourceId);
703             return icon;
704         }
705 
706         /**
707          * Used to read a ShortcutIconResource from a Parcel.
708          */
709         public static final Parcelable.Creator<ShortcutIconResource> CREATOR =
710             new Parcelable.Creator<ShortcutIconResource>() {
711 
712                 public ShortcutIconResource createFromParcel(Parcel source) {
713                     ShortcutIconResource icon = new ShortcutIconResource();
714                     icon.packageName = source.readString();
715                     icon.resourceName = source.readString();
716                     return icon;
717                 }
718 
719                 public ShortcutIconResource[] newArray(int size) {
720                     return new ShortcutIconResource[size];
721                 }
722             };
723 
724         /**
725          * No special parcel contents.
726          */
describeContents()727         public int describeContents() {
728             return 0;
729         }
730 
writeToParcel(Parcel dest, int flags)731         public void writeToParcel(Parcel dest, int flags) {
732             dest.writeString(packageName);
733             dest.writeString(resourceName);
734         }
735 
736         @Override
toString()737         public String toString() {
738             return resourceName;
739         }
740     }
741 
742     /**
743      * Activity Action: Display an activity chooser, allowing the user to pick
744      * what they want to before proceeding.  This can be used as an alternative
745      * to the standard activity picker that is displayed by the system when
746      * you try to start an activity with multiple possible matches, with these
747      * differences in behavior:
748      * <ul>
749      * <li>You can specify the title that will appear in the activity chooser.
750      * <li>The user does not have the option to make one of the matching
751      * activities a preferred activity, and all possible activities will
752      * always be shown even if one of them is currently marked as the
753      * preferred activity.
754      * </ul>
755      * <p>
756      * This action should be used when the user will naturally expect to
757      * select an activity in order to proceed.  An example if when not to use
758      * it is when the user clicks on a "mailto:" link.  They would naturally
759      * expect to go directly to their mail app, so startActivity() should be
760      * called directly: it will
761      * either launch the current preferred app, or put up a dialog allowing the
762      * user to pick an app to use and optionally marking that as preferred.
763      * <p>
764      * In contrast, if the user is selecting a menu item to send a picture
765      * they are viewing to someone else, there are many different things they
766      * may want to do at this point: send it through e-mail, upload it to a
767      * web service, etc.  In this case the CHOOSER action should be used, to
768      * always present to the user a list of the things they can do, with a
769      * nice title given by the caller such as "Send this photo with:".
770      * <p>
771      * As a convenience, an Intent of this form can be created with the
772      * {@link #createChooser} function.
773      * <p>Input: No data should be specified.  get*Extra must have
774      * a {@link #EXTRA_INTENT} field containing the Intent being executed,
775      * and can optionally have a {@link #EXTRA_TITLE} field containing the
776      * title text to display in the chooser.
777      * <p>Output: Depends on the protocol of {@link #EXTRA_INTENT}.
778      */
779     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
780     public static final String ACTION_CHOOSER = "android.intent.action.CHOOSER";
781 
782     /**
783      * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
784      *
785      * @param target The Intent that the user will be selecting an activity
786      * to perform.
787      * @param title Optional title that will be displayed in the chooser.
788      * @return Return a new Intent object that you can hand to
789      * {@link Context#startActivity(Intent) Context.startActivity()} and
790      * related methods.
791      */
createChooser(Intent target, CharSequence title)792     public static Intent createChooser(Intent target, CharSequence title) {
793         Intent intent = new Intent(ACTION_CHOOSER);
794         intent.putExtra(EXTRA_INTENT, target);
795         if (title != null) {
796             intent.putExtra(EXTRA_TITLE, title);
797         }
798         return intent;
799     }
800     /**
801      * Activity Action: Allow the user to select a particular kind of data and
802      * return it.  This is different than {@link #ACTION_PICK} in that here we
803      * just say what kind of data is desired, not a URI of existing data from
804      * which the user can pick.  A ACTION_GET_CONTENT could allow the user to
805      * create the data as it runs (for example taking a picture or recording a
806      * sound), let them browser over the web and download the desired data,
807      * etc.
808      * <p>
809      * There are two main ways to use this action: if you want an specific kind
810      * of data, such as a person contact, you set the MIME type to the kind of
811      * data you want and launch it with {@link Context#startActivity(Intent)}.
812      * The system will then launch the best application to select that kind
813      * of data for you.
814      * <p>
815      * You may also be interested in any of a set of types of content the user
816      * can pick.  For example, an e-mail application that wants to allow the
817      * user to add an attachment to an e-mail message can use this action to
818      * bring up a list of all of the types of content the user can attach.
819      * <p>
820      * In this case, you should wrap the GET_CONTENT intent with a chooser
821      * (through {@link #createChooser}), which will give the proper interface
822      * for the user to pick how to send your data and allow you to specify
823      * a prompt indicating what they are doing.  You will usually specify a
824      * broad MIME type (such as image/* or {@literal *}/*), resulting in a
825      * broad range of content types the user can select from.
826      * <p>
827      * When using such a broad GET_CONTENT action, it is often desireable to
828      * only pick from data that can be represented as a stream.  This is
829      * accomplished by requiring the {@link #CATEGORY_OPENABLE} in the Intent.
830      * <p>
831      * Input: {@link #getType} is the desired MIME type to retrieve.  Note
832      * that no URI is supplied in the intent, as there are no constraints on
833      * where the returned data originally comes from.  You may also include the
834      * {@link #CATEGORY_OPENABLE} if you can only accept data that can be
835      * opened as a stream.
836      * <p>
837      * Output: The URI of the item that was picked.  This must be a content:
838      * URI so that any receiver can access it.
839      */
840     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
841     public static final String ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
842     /**
843      * Activity Action: Dial a number as specified by the data.  This shows a
844      * UI with the number being dialed, allowing the user to explicitly
845      * initiate the call.
846      * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
847      * is URI of a phone number to be dialed or a tel: URI of an explicit phone
848      * number.
849      * <p>Output: nothing.
850      */
851     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
852     public static final String ACTION_DIAL = "android.intent.action.DIAL";
853     /**
854      * Activity Action: Perform a call to someone specified by the data.
855      * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
856      * is URI of a phone number to be dialed or a tel: URI of an explicit phone
857      * number.
858      * <p>Output: nothing.
859      *
860      * <p>Note: there will be restrictions on which applications can initiate a
861      * call; most applications should use the {@link #ACTION_DIAL}.
862      * <p>Note: this Intent <strong>cannot</strong> be used to call emergency
863      * numbers.  Applications can <strong>dial</strong> emergency numbers using
864      * {@link #ACTION_DIAL}, however.
865      */
866     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
867     public static final String ACTION_CALL = "android.intent.action.CALL";
868     /**
869      * Activity Action: Perform a call to an emergency number specified by the
870      * data.
871      * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
872      * tel: URI of an explicit phone number.
873      * <p>Output: nothing.
874      * @hide
875      */
876     public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
877     /**
878      * Activity action: Perform a call to any number (emergency or not)
879      * specified by the data.
880      * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
881      * tel: URI of an explicit phone number.
882      * <p>Output: nothing.
883      * @hide
884      */
885     public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
886     /**
887      * Activity Action: Send a message to someone specified by the data.
888      * <p>Input: {@link #getData} is URI describing the target.
889      * <p>Output: nothing.
890      */
891     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
892     public static final String ACTION_SENDTO = "android.intent.action.SENDTO";
893     /**
894      * Activity Action: Deliver some data to someone else.  Who the data is
895      * being delivered to is not specified; it is up to the receiver of this
896      * action to ask the user where the data should be sent.
897      * <p>
898      * When launching a SEND intent, you should usually wrap it in a chooser
899      * (through {@link #createChooser}), which will give the proper interface
900      * for the user to pick how to send your data and allow you to specify
901      * a prompt indicating what they are doing.
902      * <p>
903      * Input: {@link #getType} is the MIME type of the data being sent.
904      * get*Extra can have either a {@link #EXTRA_TEXT}
905      * or {@link #EXTRA_STREAM} field, containing the data to be sent.  If
906      * using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it
907      * should be the MIME type of the data in EXTRA_STREAM.  Use {@literal *}/*
908      * if the MIME type is unknown (this will only allow senders that can
909      * handle generic data streams).
910      * <p>
911      * Optional standard extras, which may be interpreted by some recipients as
912      * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
913      * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
914      * <p>
915      * Output: nothing.
916      */
917     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
918     public static final String ACTION_SEND = "android.intent.action.SEND";
919     /**
920      * Activity Action: Deliver multiple data to someone else.
921      * <p>
922      * Like ACTION_SEND, except the data is multiple.
923      * <p>
924      * Input: {@link #getType} is the MIME type of the data being sent.
925      * get*ArrayListExtra can have either a {@link #EXTRA_TEXT} or {@link
926      * #EXTRA_STREAM} field, containing the data to be sent.
927      * <p>
928      * Multiple types are supported, and receivers should handle mixed types
929      * whenever possible. The right way for the receiver to check them is to
930      * use the content resolver on each URI. The intent sender should try to
931      * put the most concrete mime type in the intent type, but it can fall
932      * back to {@literal <type>/*} or {@literal *}/* as needed.
933      * <p>
934      * e.g. if you are sending image/jpg and image/jpg, the intent's type can
935      * be image/jpg, but if you are sending image/jpg and image/png, then the
936      * intent's type should be image/*.
937      * <p>
938      * Optional standard extras, which may be interpreted by some recipients as
939      * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
940      * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
941      * <p>
942      * Output: nothing.
943      */
944     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
945     public static final String ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE";
946     /**
947      * Activity Action: Handle an incoming phone call.
948      * <p>Input: nothing.
949      * <p>Output: nothing.
950      */
951     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
952     public static final String ACTION_ANSWER = "android.intent.action.ANSWER";
953     /**
954      * Activity Action: Insert an empty item into the given container.
955      * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
956      * in which to place the data.
957      * <p>Output: URI of the new data that was created.
958      */
959     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
960     public static final String ACTION_INSERT = "android.intent.action.INSERT";
961     /**
962      * Activity Action: Delete the given data from its container.
963      * <p>Input: {@link #getData} is URI of data to be deleted.
964      * <p>Output: nothing.
965      */
966     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
967     public static final String ACTION_DELETE = "android.intent.action.DELETE";
968     /**
969      * Activity Action: Run the data, whatever that means.
970      * <p>Input: ?  (Note: this is currently specific to the test harness.)
971      * <p>Output: nothing.
972      */
973     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
974     public static final String ACTION_RUN = "android.intent.action.RUN";
975     /**
976      * Activity Action: Perform a data synchronization.
977      * <p>Input: ?
978      * <p>Output: ?
979      */
980     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
981     public static final String ACTION_SYNC = "android.intent.action.SYNC";
982     /**
983      * Activity Action: Pick an activity given an intent, returning the class
984      * selected.
985      * <p>Input: get*Extra field {@link #EXTRA_INTENT} is an Intent
986      * used with {@link PackageManager#queryIntentActivities} to determine the
987      * set of activities from which to pick.
988      * <p>Output: Class name of the activity that was selected.
989      */
990     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
991     public static final String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
992     /**
993      * Activity Action: Perform a search.
994      * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
995      * is the text to search for.  If empty, simply
996      * enter your search results Activity with the search UI activated.
997      * <p>Output: nothing.
998      */
999     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1000     public static final String ACTION_SEARCH = "android.intent.action.SEARCH";
1001     /**
1002      * Activity Action: Start the platform-defined tutorial
1003      * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
1004      * is the text to search for.  If empty, simply
1005      * enter your search results Activity with the search UI activated.
1006      * <p>Output: nothing.
1007      */
1008     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1009     public static final String ACTION_SYSTEM_TUTORIAL = "android.intent.action.SYSTEM_TUTORIAL";
1010     /**
1011      * Activity Action: Perform a web search.
1012      * <p>
1013      * Input: {@link android.app.SearchManager#QUERY
1014      * getStringExtra(SearchManager.QUERY)} is the text to search for. If it is
1015      * a url starts with http or https, the site will be opened. If it is plain
1016      * text, Google search will be applied.
1017      * <p>
1018      * Output: nothing.
1019      */
1020     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1021     public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
1022     /**
1023      * Activity Action: List all available applications
1024      * <p>Input: Nothing.
1025      * <p>Output: nothing.
1026      */
1027     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1028     public static final String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
1029     /**
1030      * Activity Action: Show settings for choosing wallpaper
1031      * <p>Input: Nothing.
1032      * <p>Output: Nothing.
1033      */
1034     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1035     public static final String ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
1036 
1037     /**
1038      * Activity Action: Show activity for reporting a bug.
1039      * <p>Input: Nothing.
1040      * <p>Output: Nothing.
1041      */
1042     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1043     public static final String ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
1044 
1045     /**
1046      *  Activity Action: Main entry point for factory tests.  Only used when
1047      *  the device is booting in factory test node.  The implementing package
1048      *  must be installed in the system image.
1049      *  <p>Input: nothing
1050      *  <p>Output: nothing
1051      */
1052     public static final String ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
1053 
1054     /**
1055      * Activity Action: The user pressed the "call" button to go to the dialer
1056      * or other appropriate UI for placing a call.
1057      * <p>Input: Nothing.
1058      * <p>Output: Nothing.
1059      */
1060     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1061     public static final String ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
1062 
1063     /**
1064      * Activity Action: Start Voice Command.
1065      * <p>Input: Nothing.
1066      * <p>Output: Nothing.
1067      */
1068     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1069     public static final String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
1070 
1071     /**
1072      * Activity Action: Start action associated with long pressing on the
1073      * search key.
1074      * <p>Input: Nothing.
1075      * <p>Output: Nothing.
1076      */
1077     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1078     public static final String ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";
1079 
1080     /**
1081      * Activity Action: The user pressed the "Report" button in the crash/ANR dialog.
1082      * This intent is delivered to the package which installed the application, usually
1083      * the Market.
1084      * <p>Input: No data is specified. The bug report is passed in using
1085      * an {@link #EXTRA_BUG_REPORT} field.
1086      * <p>Output: Nothing.
1087      * @hide
1088      */
1089     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1090     public static final String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
1091 
1092     /**
1093      * Activity Action: Show power usage information to the user.
1094      * <p>Input: Nothing.
1095      * <p>Output: Nothing.
1096      */
1097     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1098     public static final String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
1099 
1100     /**
1101      * Activity Action: Setup wizard to launch after a platform update.  This
1102      * activity should have a string meta-data field associated with it,
1103      * {@link #METADATA_SETUP_VERSION}, which defines the current version of
1104      * the platform for setup.  The activity will be launched only if
1105      * {@link android.provider.Settings.Secure#LAST_SETUP_SHOWN} is not the
1106      * same value.
1107      * <p>Input: Nothing.
1108      * <p>Output: Nothing.
1109      * @hide
1110      */
1111     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1112     public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
1113 
1114     /**
1115      * A string associated with a {@link #ACTION_UPGRADE_SETUP} activity
1116      * describing the last run version of the platform that was setup.
1117      * @hide
1118      */
1119     public static final String METADATA_SETUP_VERSION = "android.SETUP_VERSION";
1120 
1121     // ---------------------------------------------------------------------
1122     // ---------------------------------------------------------------------
1123     // Standard intent broadcast actions (see action variable).
1124 
1125     /**
1126      * Broadcast Action: Sent after the screen turns off.
1127      *
1128      * <p class="note">This is a protected intent that can only be sent
1129      * by the system.
1130      */
1131     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1132     public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
1133     /**
1134      * Broadcast Action: Sent after the screen turns on.
1135      *
1136      * <p class="note">This is a protected intent that can only be sent
1137      * by the system.
1138      */
1139     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1140     public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
1141 
1142     /**
1143      * Broadcast Action: Sent when the user is present after device wakes up (e.g when the
1144      * keyguard is gone).
1145      *
1146      * <p class="note">This is a protected intent that can only be sent
1147      * by the system.
1148      */
1149     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1150     public static final String ACTION_USER_PRESENT= "android.intent.action.USER_PRESENT";
1151 
1152     /**
1153      * Broadcast Action: The current time has changed.  Sent every
1154      * minute.  You can <em>not</em> receive this through components declared
1155      * in manifests, only by exlicitly registering for it with
1156      * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1157      * Context.registerReceiver()}.
1158      *
1159      * <p class="note">This is a protected intent that can only be sent
1160      * by the system.
1161      */
1162     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1163     public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
1164     /**
1165      * Broadcast Action: The time was set.
1166      */
1167     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1168     public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
1169     /**
1170      * Broadcast Action: The date has changed.
1171      */
1172     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1173     public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
1174     /**
1175      * Broadcast Action: The timezone has changed. The intent will have the following extra values:</p>
1176      * <ul>
1177      *   <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time zone.</li>
1178      * </ul>
1179      *
1180      * <p class="note">This is a protected intent that can only be sent
1181      * by the system.
1182      */
1183     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1184     public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
1185     /**
1186      * Alarm Changed Action: This is broadcast when the AlarmClock
1187      * application's alarm is set or unset.  It is used by the
1188      * AlarmClock application and the StatusBar service.
1189      * @hide
1190      */
1191     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1192     public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
1193     /**
1194      * Sync State Changed Action: This is broadcast when the sync starts or stops or when one has
1195      * been failing for a long time.  It is used by the SyncManager and the StatusBar service.
1196      * @hide
1197      */
1198     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1199     public static final String ACTION_SYNC_STATE_CHANGED
1200             = "android.intent.action.SYNC_STATE_CHANGED";
1201     /**
1202      * Broadcast Action: This is broadcast once, after the system has finished
1203      * booting.  It can be used to perform application-specific initialization,
1204      * such as installing alarms.  You must hold the
1205      * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
1206      * in order to receive this broadcast.
1207      *
1208      * <p class="note">This is a protected intent that can only be sent
1209      * by the system.
1210      */
1211     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1212     public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
1213     /**
1214      * Broadcast Action: This is broadcast when a user action should request a
1215      * temporary system dialog to dismiss.  Some examples of temporary system
1216      * dialogs are the notification window-shade and the recent tasks dialog.
1217      */
1218     public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
1219     /**
1220      * Broadcast Action: Trigger the download and eventual installation
1221      * of a package.
1222      * <p>Input: {@link #getData} is the URI of the package file to download.
1223      *
1224      * <p class="note">This is a protected intent that can only be sent
1225      * by the system.
1226      */
1227     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1228     public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
1229     /**
1230      * Broadcast Action: A new application package has been installed on the
1231      * device. The data contains the name of the package.  Note that the
1232      * newly installed package does <em>not</em> receive this broadcast.
1233      * <p>My include the following extras:
1234      * <ul>
1235      * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1236      * <li> {@link #EXTRA_REPLACING} is set to true if this is following
1237      * an {@link #ACTION_PACKAGE_REMOVED} broadcast for the same package.
1238      * </ul>
1239      *
1240      * <p class="note">This is a protected intent that can only be sent
1241      * by the system.
1242      */
1243     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1244     public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
1245     /**
1246      * Broadcast Action: A new version of an application package has been
1247      * installed, replacing an existing version that was previously installed.
1248      * The data contains the name of the package.
1249      * <p>My include the following extras:
1250      * <ul>
1251      * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1252      * </ul>
1253      *
1254      * <p class="note">This is a protected intent that can only be sent
1255      * by the system.
1256      */
1257     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1258     public static final String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
1259     /**
1260      * Broadcast Action: An existing application package has been removed from
1261      * the device.  The data contains the name of the package.  The package
1262      * that is being installed does <em>not</em> receive this Intent.
1263      * <ul>
1264      * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1265      * to the package.
1266      * <li> {@link #EXTRA_DATA_REMOVED} is set to true if the entire
1267      * application -- data and code -- is being removed.
1268      * <li> {@link #EXTRA_REPLACING} is set to true if this will be followed
1269      * by an {@link #ACTION_PACKAGE_ADDED} broadcast for the same package.
1270      * </ul>
1271      *
1272      * <p class="note">This is a protected intent that can only be sent
1273      * by the system.
1274      */
1275     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1276     public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
1277     /**
1278      * Broadcast Action: An existing application package has been changed (e.g.
1279      * a component has been enabled or disabled).  The data contains the name of
1280      * the package.
1281      * <ul>
1282      * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1283      * <li> {@link #EXTRA_CHANGED_COMPONENT_NAME} containing the class name of the
1284      * changed component.
1285      * <li> {@link #EXTRA_DONT_KILL_APP} containing boolean field to override the
1286      * default action of restarting the application.
1287      * </ul>
1288      *
1289      * <p class="note">This is a protected intent that can only be sent
1290      * by the system.
1291      */
1292     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1293     public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
1294     /**
1295      * Broadcast Action: The user has restarted a package, and all of its
1296      * processes have been killed.  All runtime state
1297      * associated with it (processes, alarms, notifications, etc) should
1298      * be removed.  Note that the restarted package does <em>not</em>
1299      * receive this broadcast.
1300      * The data contains the name of the package.
1301      * <ul>
1302      * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1303      * </ul>
1304      *
1305      * <p class="note">This is a protected intent that can only be sent
1306      * by the system.
1307      */
1308     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1309     public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
1310     /**
1311      * Broadcast Action: The user has cleared the data of a package.  This should
1312      * be preceded by {@link #ACTION_PACKAGE_RESTARTED}, after which all of
1313      * its persistent data is erased and this broadcast sent.
1314      * Note that the cleared package does <em>not</em>
1315      * receive this broadcast. The data contains the name of the package.
1316      * <ul>
1317      * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1318      * </ul>
1319      *
1320      * <p class="note">This is a protected intent that can only be sent
1321      * by the system.
1322      */
1323     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1324     public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
1325     /**
1326      * Broadcast Action: A user ID has been removed from the system.  The user
1327      * ID number is stored in the extra data under {@link #EXTRA_UID}.
1328      *
1329      * <p class="note">This is a protected intent that can only be sent
1330      * by the system.
1331      */
1332     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1333     public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
1334     /**
1335      * Broadcast Action:  The current system wallpaper has changed.  See
1336      * {@link android.app.WallpaperManager} for retrieving the new wallpaper.
1337      */
1338     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1339     public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
1340     /**
1341      * Broadcast Action: The current device {@link android.content.res.Configuration}
1342      * (orientation, locale, etc) has changed.  When such a change happens, the
1343      * UIs (view hierarchy) will need to be rebuilt based on this new
1344      * information; for the most part, applications don't need to worry about
1345      * this, because the system will take care of stopping and restarting the
1346      * application to make sure it sees the new changes.  Some system code that
1347      * can not be restarted will need to watch for this action and handle it
1348      * appropriately.
1349      *
1350      * <p class="note">
1351      * You can <em>not</em> receive this through components declared
1352      * in manifests, only by explicitly registering for it with
1353      * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1354      * Context.registerReceiver()}.
1355      *
1356      * <p class="note">This is a protected intent that can only be sent
1357      * by the system.
1358      *
1359      * @see android.content.res.Configuration
1360      */
1361     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1362     public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
1363     /**
1364      * Broadcast Action: The current device's locale has changed.
1365      *
1366      * <p class="note">This is a protected intent that can only be sent
1367      * by the system.
1368      * @hide
1369      */
1370     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1371     public static final String ACTION_LOCALE_CHANGED = "android.intent.action.LOCALE_CHANGED";
1372     /**
1373      * Broadcast Action:  This is a <em>sticky broadcast</em> containing the
1374      * charging state, level, and other information about the battery.
1375      * See {@link android.os.BatteryManager} for documentation on the
1376      * contents of the Intent.
1377      *
1378      * <p class="note">
1379      * You can <em>not</em> receive this through components declared
1380      * in manifests, only by explicitly registering for it with
1381      * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1382      * Context.registerReceiver()}.  See {@link #ACTION_BATTERY_LOW},
1383      * {@link #ACTION_BATTERY_OKAY}, {@link #ACTION_POWER_CONNECTED},
1384      * and {@link #ACTION_POWER_DISCONNECTED} for distinct battery-related
1385      * broadcasts that are sent and can be received through manifest
1386      * receivers.
1387      *
1388      * <p class="note">This is a protected intent that can only be sent
1389      * by the system.
1390      */
1391     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1392     public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
1393     /**
1394      * Broadcast Action:  Indicates low battery condition on the device.
1395      * This broadcast corresponds to the "Low battery warning" system dialog.
1396      *
1397      * <p class="note">This is a protected intent that can only be sent
1398      * by the system.
1399      */
1400     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1401     public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
1402     /**
1403      * Broadcast Action:  Indicates the battery is now okay after being low.
1404      * This will be sent after {@link #ACTION_BATTERY_LOW} once the battery has
1405      * gone back up to an okay state.
1406      *
1407      * <p class="note">This is a protected intent that can only be sent
1408      * by the system.
1409      */
1410     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1411     public static final String ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";
1412     /**
1413      * Broadcast Action:  External power has been connected to the device.
1414      * This is intended for applications that wish to register specifically to this notification.
1415      * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1416      * stay active to receive this notification.  This action can be used to implement actions
1417      * that wait until power is available to trigger.
1418      *
1419      * <p class="note">This is a protected intent that can only be sent
1420      * by the system.
1421      */
1422     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1423     public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
1424     /**
1425      * Broadcast Action:  External power has been removed from the device.
1426      * This is intended for applications that wish to register specifically to this notification.
1427      * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1428      * stay active to receive this notification.  This action can be used to implement actions
1429      * that wait until power is available to trigger.
1430      *
1431      * <p class="note">This is a protected intent that can only be sent
1432      * by the system.
1433      */
1434     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1435     public static final String ACTION_POWER_DISCONNECTED =
1436             "android.intent.action.ACTION_POWER_DISCONNECTED";
1437     /**
1438      * Broadcast Action:  Device is shutting down.
1439      * This is broadcast when the device is being shut down (completely turned
1440      * off, not sleeping).  Once the broadcast is complete, the final shutdown
1441      * will proceed and all unsaved data lost.  Apps will not normally need
1442      * to handle this, since the foreground activity will be paused as well.
1443      *
1444      * <p class="note">This is a protected intent that can only be sent
1445      * by the system.
1446      */
1447     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1448     public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
1449     /**
1450      * Activity Action:  Start this activity to request system shutdown.
1451      * The optional boolean extra field {@link #EXTRA_KEY_CONFIRM} can be set to true
1452      * to request confirmation from the user before shutting down.
1453      *
1454      * <p class="note">This is a protected intent that can only be sent
1455      * by the system.
1456      *
1457      * {@hide}
1458      */
1459     public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
1460     /**
1461      * Broadcast Action:  A sticky broadcast that indicates low memory
1462      * condition on the device
1463      *
1464      * <p class="note">This is a protected intent that can only be sent
1465      * by the system.
1466      */
1467     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1468     public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
1469     /**
1470      * Broadcast Action:  Indicates low memory condition on the device no longer exists
1471      *
1472      * <p class="note">This is a protected intent that can only be sent
1473      * by the system.
1474      */
1475     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1476     public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
1477     /**
1478      * Broadcast Action:  Indicates low memory condition notification acknowledged by user
1479      * and package management should be started.
1480      * This is triggered by the user from the ACTION_DEVICE_STORAGE_LOW
1481      * notification.
1482      */
1483     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1484     public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
1485     /**
1486      * Broadcast Action:  The device has entered USB Mass Storage mode.
1487      * This is used mainly for the USB Settings panel.
1488      * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1489      * when the SD card file system is mounted or unmounted
1490      */
1491     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1492     public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
1493 
1494     /**
1495      * Broadcast Action:  The device has exited USB Mass Storage mode.
1496      * This is used mainly for the USB Settings panel.
1497      * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1498      * when the SD card file system is mounted or unmounted
1499      */
1500     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1501     public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
1502 
1503     /**
1504      * Broadcast Action:  External media has been removed.
1505      * The path to the mount point for the removed media is contained in the Intent.mData field.
1506      */
1507     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1508     public static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
1509 
1510     /**
1511      * Broadcast Action:  External media is present, but not mounted at its mount point.
1512      * The path to the mount point for the removed media is contained in the Intent.mData field.
1513      */
1514     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1515     public static final String ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
1516 
1517     /**
1518      * Broadcast Action:  External media is present, and being disk-checked
1519      * The path to the mount point for the checking media is contained in the Intent.mData field.
1520      */
1521     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1522     public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
1523 
1524     /**
1525      * Broadcast Action:  External media is present, but is using an incompatible fs (or is blank)
1526      * The path to the mount point for the checking media is contained in the Intent.mData field.
1527      */
1528     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1529     public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
1530 
1531     /**
1532      * Broadcast Action:  External media is present and mounted at its mount point.
1533      * The path to the mount point for the removed media is contained in the Intent.mData field.
1534      * The Intent contains an extra with name "read-only" and Boolean value to indicate if the
1535      * media was mounted read only.
1536      */
1537     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1538     public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
1539 
1540     /**
1541      * Broadcast Action:  External media is unmounted because it is being shared via USB mass storage.
1542      * The path to the mount point for the removed media is contained in the Intent.mData field.
1543      */
1544     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1545     public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
1546 
1547     /**
1548      * Broadcast Action:  External media was removed from SD card slot, but mount point was not unmounted.
1549      * The path to the mount point for the removed media is contained in the Intent.mData field.
1550      */
1551     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1552     public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
1553 
1554     /**
1555      * Broadcast Action:  External media is present but cannot be mounted.
1556      * The path to the mount point for the removed media is contained in the Intent.mData field.
1557      */
1558     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1559     public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
1560 
1561    /**
1562      * Broadcast Action:  User has expressed the desire to remove the external storage media.
1563      * Applications should close all files they have open within the mount point when they receive this intent.
1564      * The path to the mount point for the media to be ejected is contained in the Intent.mData field.
1565      */
1566     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1567     public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
1568 
1569     /**
1570      * Broadcast Action:  The media scanner has started scanning a directory.
1571      * The path to the directory being scanned is contained in the Intent.mData field.
1572      */
1573     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1574     public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
1575 
1576    /**
1577      * Broadcast Action:  The media scanner has finished scanning a directory.
1578      * The path to the scanned directory is contained in the Intent.mData field.
1579      */
1580     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1581     public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
1582 
1583    /**
1584      * Broadcast Action:  Request the media scanner to scan a file and add it to the media database.
1585      * The path to the file is contained in the Intent.mData field.
1586      */
1587     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1588     public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
1589 
1590    /**
1591      * Broadcast Action:  The "Media Button" was pressed.  Includes a single
1592      * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1593      * caused the broadcast.
1594      */
1595     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1596     public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
1597 
1598     /**
1599      * Broadcast Action:  The "Camera Button" was pressed.  Includes a single
1600      * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1601      * caused the broadcast.
1602      */
1603     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1604     public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
1605 
1606     // *** NOTE: @todo(*) The following really should go into a more domain-specific
1607     // location; they are not general-purpose actions.
1608 
1609     /**
1610      * Broadcast Action: An GTalk connection has been established.
1611      */
1612     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1613     public static final String ACTION_GTALK_SERVICE_CONNECTED =
1614             "android.intent.action.GTALK_CONNECTED";
1615 
1616     /**
1617      * Broadcast Action: An GTalk connection has been disconnected.
1618      */
1619     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1620     public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
1621             "android.intent.action.GTALK_DISCONNECTED";
1622 
1623     /**
1624      * Broadcast Action: An input method has been changed.
1625      */
1626     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1627     public static final String ACTION_INPUT_METHOD_CHANGED =
1628             "android.intent.action.INPUT_METHOD_CHANGED";
1629 
1630     /**
1631      * <p>Broadcast Action: The user has switched the phone into or out of Airplane Mode. One or
1632      * more radios have been turned off or on. The intent will have the following extra value:</p>
1633      * <ul>
1634      *   <li><em>state</em> - A boolean value indicating whether Airplane Mode is on. If true,
1635      *   then cell radio and possibly other radios such as bluetooth or WiFi may have also been
1636      *   turned off</li>
1637      * </ul>
1638      *
1639      * <p class="note">This is a protected intent that can only be sent
1640      * by the system.
1641      */
1642     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1643     public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
1644 
1645     /**
1646      * Broadcast Action: Some content providers have parts of their namespace
1647      * where they publish new events or items that the user may be especially
1648      * interested in. For these things, they may broadcast this action when the
1649      * set of interesting items change.
1650      *
1651      * For example, GmailProvider sends this notification when the set of unread
1652      * mail in the inbox changes.
1653      *
1654      * <p>The data of the intent identifies which part of which provider
1655      * changed. When queried through the content resolver, the data URI will
1656      * return the data set in question.
1657      *
1658      * <p>The intent will have the following extra values:
1659      * <ul>
1660      *   <li><em>count</em> - The number of items in the data set. This is the
1661      *       same as the number of items in the cursor returned by querying the
1662      *       data URI. </li>
1663      * </ul>
1664      *
1665      * This intent will be sent at boot (if the count is non-zero) and when the
1666      * data set changes. It is possible for the data set to change without the
1667      * count changing (for example, if a new unread message arrives in the same
1668      * sync operation in which a message is archived). The phone should still
1669      * ring/vibrate/etc as normal in this case.
1670      */
1671     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1672     public static final String ACTION_PROVIDER_CHANGED =
1673             "android.intent.action.PROVIDER_CHANGED";
1674 
1675     /**
1676      * Broadcast Action: Wired Headset plugged in or unplugged.
1677      *
1678      * <p>The intent will have the following extra values:
1679      * <ul>
1680      *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
1681      *   <li><em>name</em> - Headset type, human readable string </li>
1682      *   <li><em>microphone</em> - 1 if headset has a microphone, 0 otherwise </li>
1683      * </ul>
1684      * </ul>
1685      */
1686     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1687     public static final String ACTION_HEADSET_PLUG =
1688             "android.intent.action.HEADSET_PLUG";
1689 
1690     /**
1691      * Broadcast Action: An outgoing call is about to be placed.
1692      *
1693      * <p>The Intent will have the following extra value:
1694      * <ul>
1695      *   <li><em>{@link android.content.Intent#EXTRA_PHONE_NUMBER}</em> -
1696      *       the phone number originally intended to be dialed.</li>
1697      * </ul>
1698      * <p>Once the broadcast is finished, the resultData is used as the actual
1699      * number to call.  If  <code>null</code>, no call will be placed.</p>
1700      * <p>It is perfectly acceptable for multiple receivers to process the
1701      * outgoing call in turn: for example, a parental control application
1702      * might verify that the user is authorized to place the call at that
1703      * time, then a number-rewriting application might add an area code if
1704      * one was not specified.</p>
1705      * <p>For consistency, any receiver whose purpose is to prohibit phone
1706      * calls should have a priority of 0, to ensure it will see the final
1707      * phone number to be dialed.
1708      * Any receiver whose purpose is to rewrite phone numbers to be called
1709      * should have a positive priority.
1710      * Negative priorities are reserved for the system for this broadcast;
1711      * using them may cause problems.</p>
1712      * <p>Any BroadcastReceiver receiving this Intent <em>must not</em>
1713      * abort the broadcast.</p>
1714      * <p>Emergency calls cannot be intercepted using this mechanism, and
1715      * other calls cannot be modified to call emergency numbers using this
1716      * mechanism.
1717      * <p>You must hold the
1718      * {@link android.Manifest.permission#PROCESS_OUTGOING_CALLS}
1719      * permission to receive this Intent.</p>
1720      *
1721      * <p class="note">This is a protected intent that can only be sent
1722      * by the system.
1723      */
1724     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1725     public static final String ACTION_NEW_OUTGOING_CALL =
1726             "android.intent.action.NEW_OUTGOING_CALL";
1727 
1728     /**
1729      * Broadcast Action: Have the device reboot.  This is only for use by
1730      * system code.
1731      *
1732      * <p class="note">This is a protected intent that can only be sent
1733      * by the system.
1734      */
1735     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1736     public static final String ACTION_REBOOT =
1737             "android.intent.action.REBOOT";
1738 
1739     /**
1740      * Broadcast Action:  A sticky broadcast indicating the phone was docked
1741      * or undocked.  Includes the extra
1742      * field {@link #EXTRA_DOCK_STATE}, containing the current dock state.
1743      * This is intended for monitoring the current dock state.
1744      * To launch an activity from a dock state change, use {@link #CATEGORY_CAR_DOCK}
1745      * or {@link #CATEGORY_DESK_DOCK} instead.
1746      */
1747     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1748     public static final String ACTION_DOCK_EVENT =
1749             "android.intent.action.DOCK_EVENT";
1750 
1751     /**
1752      * Broadcast Action: a remote intent is to be broadcasted.
1753      *
1754      * A remote intent is used for remote RPC between devices. The remote intent
1755      * is serialized and sent from one device to another device. The receiving
1756      * device parses the remote intent and broadcasts it. Note that anyone can
1757      * broadcast a remote intent. However, if the intent receiver of the remote intent
1758      * does not trust intent broadcasts from arbitrary intent senders, it should require
1759      * the sender to hold certain permissions so only trusted sender's broadcast will be
1760      * let through.
1761      * @hide
1762      */
1763     public static final String ACTION_REMOTE_INTENT =
1764             "android.intent.action.REMOTE_INTENT";
1765 
1766     /**
1767      * Broadcast Action: hook for permforming cleanup after a system update.
1768      *
1769      * The broadcast is sent when the system is booting, before the
1770      * BOOT_COMPLETED broadcast.  It is only sent to receivers in the system
1771      * image.  A receiver for this should do its work and then disable itself
1772      * so that it does not get run again at the next boot.
1773      * @hide
1774      */
1775     public static final String ACTION_PRE_BOOT_COMPLETED =
1776             "android.intent.action.PRE_BOOT_COMPLETED";
1777 
1778     // ---------------------------------------------------------------------
1779     // ---------------------------------------------------------------------
1780     // Standard intent categories (see addCategory()).
1781 
1782     /**
1783      * Set if the activity should be an option for the default action
1784      * (center press) to perform on a piece of data.  Setting this will
1785      * hide from the user any activities without it set when performing an
1786      * action on some data.  Note that this is normal -not- set in the
1787      * Intent when initiating an action -- it is for use in intent filters
1788      * specified in packages.
1789      */
1790     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1791     public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
1792     /**
1793      * Activities that can be safely invoked from a browser must support this
1794      * category.  For example, if the user is viewing a web page or an e-mail
1795      * and clicks on a link in the text, the Intent generated execute that
1796      * link will require the BROWSABLE category, so that only activities
1797      * supporting this category will be considered as possible actions.  By
1798      * supporting this category, you are promising that there is nothing
1799      * damaging (without user intervention) that can happen by invoking any
1800      * matching Intent.
1801      */
1802     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1803     public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
1804     /**
1805      * Set if the activity should be considered as an alternative action to
1806      * the data the user is currently viewing.  See also
1807      * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
1808      * applies to the selection in a list of items.
1809      *
1810      * <p>Supporting this category means that you would like your activity to be
1811      * displayed in the set of alternative things the user can do, usually as
1812      * part of the current activity's options menu.  You will usually want to
1813      * include a specific label in the &lt;intent-filter&gt; of this action
1814      * describing to the user what it does.
1815      *
1816      * <p>The action of IntentFilter with this category is important in that it
1817      * describes the specific action the target will perform.  This generally
1818      * should not be a generic action (such as {@link #ACTION_VIEW}, but rather
1819      * a specific name such as "com.android.camera.action.CROP.  Only one
1820      * alternative of any particular action will be shown to the user, so using
1821      * a specific action like this makes sure that your alternative will be
1822      * displayed while also allowing other applications to provide their own
1823      * overrides of that particular action.
1824      */
1825     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1826     public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
1827     /**
1828      * Set if the activity should be considered as an alternative selection
1829      * action to the data the user has currently selected.  This is like
1830      * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list
1831      * of items from which the user can select, giving them alternatives to the
1832      * default action that will be performed on it.
1833      */
1834     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1835     public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
1836     /**
1837      * Intended to be used as a tab inside of an containing TabActivity.
1838      */
1839     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1840     public static final String CATEGORY_TAB = "android.intent.category.TAB";
1841     /**
1842      * Should be displayed in the top-level launcher.
1843      */
1844     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1845     public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
1846     /**
1847      * Provides information about the package it is in; typically used if
1848      * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
1849      * a front-door to the user without having to be shown in the all apps list.
1850      */
1851     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1852     public static final String CATEGORY_INFO = "android.intent.category.INFO";
1853     /**
1854      * This is the home activity, that is the first activity that is displayed
1855      * when the device boots.
1856      */
1857     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1858     public static final String CATEGORY_HOME = "android.intent.category.HOME";
1859     /**
1860      * This activity is a preference panel.
1861      */
1862     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1863     public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
1864     /**
1865      * This activity is a development preference panel.
1866      */
1867     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1868     public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
1869     /**
1870      * Capable of running inside a parent activity container.
1871      */
1872     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1873     public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
1874     /**
1875      * This activity may be exercised by the monkey or other automated test tools.
1876      */
1877     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1878     public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
1879     /**
1880      * To be used as a test (not part of the normal user experience).
1881      */
1882     public static final String CATEGORY_TEST = "android.intent.category.TEST";
1883     /**
1884      * To be used as a unit test (run through the Test Harness).
1885      */
1886     public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
1887     /**
1888      * To be used as an sample code example (not part of the normal user
1889      * experience).
1890      */
1891     public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
1892     /**
1893      * Used to indicate that a GET_CONTENT intent only wants URIs that can be opened with
1894      * ContentResolver.openInputStream. Openable URIs must support the columns in OpenableColumns
1895      * when queried, though it is allowable for those columns to be blank.
1896      */
1897     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1898     public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
1899 
1900     /**
1901      * To be used as code under test for framework instrumentation tests.
1902      */
1903     public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
1904             "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
1905     /**
1906      * An activity to run when device is inserted into a car dock.
1907      * Used with {@link #ACTION_MAIN} to launch an activity.
1908      * To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
1909      */
1910     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1911     public static final String CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
1912     /**
1913      * An activity to run when device is inserted into a car dock.
1914      * Used with {@link #ACTION_MAIN} to launch an activity.
1915      * To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
1916      */
1917     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1918     public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
1919 
1920     // ---------------------------------------------------------------------
1921     // ---------------------------------------------------------------------
1922     // Standard extra data keys.
1923 
1924     /**
1925      * The initial data to place in a newly created record.  Use with
1926      * {@link #ACTION_INSERT}.  The data here is a Map containing the same
1927      * fields as would be given to the underlying ContentProvider.insert()
1928      * call.
1929      */
1930     public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
1931 
1932     /**
1933      * A constant CharSequence that is associated with the Intent, used with
1934      * {@link #ACTION_SEND} to supply the literal data to be sent.  Note that
1935      * this may be a styled CharSequence, so you must use
1936      * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to
1937      * retrieve it.
1938      */
1939     public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
1940 
1941     /**
1942      * A content: URI holding a stream of data associated with the Intent,
1943      * used with {@link #ACTION_SEND} to supply the data being sent.
1944      */
1945     public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
1946 
1947     /**
1948      * A String[] holding e-mail addresses that should be delivered to.
1949      */
1950     public static final String EXTRA_EMAIL       = "android.intent.extra.EMAIL";
1951 
1952     /**
1953      * A String[] holding e-mail addresses that should be carbon copied.
1954      */
1955     public static final String EXTRA_CC       = "android.intent.extra.CC";
1956 
1957     /**
1958      * A String[] holding e-mail addresses that should be blind carbon copied.
1959      */
1960     public static final String EXTRA_BCC      = "android.intent.extra.BCC";
1961 
1962     /**
1963      * A constant string holding the desired subject line of a message.
1964      */
1965     public static final String EXTRA_SUBJECT  = "android.intent.extra.SUBJECT";
1966 
1967     /**
1968      * An Intent describing the choices you would like shown with
1969      * {@link #ACTION_PICK_ACTIVITY}.
1970      */
1971     public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
1972 
1973     /**
1974      * A CharSequence dialog title to provide to the user when used with a
1975      * {@link #ACTION_CHOOSER}.
1976      */
1977     public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
1978 
1979     /**
1980      * A Parcelable[] of {@link Intent} or
1981      * {@link android.content.pm.LabeledIntent} objects as set with
1982      * {@link #putExtra(String, Parcelable[])} of additional activities to place
1983      * a the front of the list of choices, when shown to the user with a
1984      * {@link #ACTION_CHOOSER}.
1985      */
1986     public static final String EXTRA_INITIAL_INTENTS = "android.intent.extra.INITIAL_INTENTS";
1987 
1988     /**
1989      * A {@link android.view.KeyEvent} object containing the event that
1990      * triggered the creation of the Intent it is in.
1991      */
1992     public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
1993 
1994     /**
1995      * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to request confirmation from the user
1996      * before shutting down.
1997      *
1998      * {@hide}
1999      */
2000     public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";
2001 
2002     /**
2003      * Used as an boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
2004      * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
2005      * of restarting the application.
2006      */
2007     public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
2008 
2009     /**
2010      * A String holding the phone number originally entered in
2011      * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual
2012      * number to call in a {@link android.content.Intent#ACTION_CALL}.
2013      */
2014     public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
2015     /**
2016      * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED}
2017      * intents to supply the uid the package had been assigned.  Also an optional
2018      * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
2019      * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same
2020      * purpose.
2021      */
2022     public static final String EXTRA_UID = "android.intent.extra.UID";
2023 
2024     /**
2025      * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
2026      * intents to indicate whether this represents a full uninstall (removing
2027      * both the code and its data) or a partial uninstall (leaving its data,
2028      * implying that this is an update).
2029      */
2030     public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
2031 
2032     /**
2033      * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
2034      * intents to indicate that this is a replacement of the package, so this
2035      * broadcast will immediately be followed by an add broadcast for a
2036      * different version of the same package.
2037      */
2038     public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
2039 
2040     /**
2041      * Used as an int extra field in {@link android.app.AlarmManager} intents
2042      * to tell the application being invoked how many pending alarms are being
2043      * delievered with the intent.  For one-shot alarms this will always be 1.
2044      * For recurring alarms, this might be greater than 1 if the device was
2045      * asleep or powered off at the time an earlier alarm would have been
2046      * delivered.
2047      */
2048     public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
2049 
2050     /**
2051      * Used as an int extra field in {@link android.content.Intent#ACTION_DOCK_EVENT}
2052      * intents to request the dock state.  Possible values are
2053      * {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
2054      * {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
2055      * {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}.
2056      */
2057     public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
2058 
2059     /**
2060      * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2061      * to represent that the phone is not in any dock.
2062      */
2063     public static final int EXTRA_DOCK_STATE_UNDOCKED = 0;
2064 
2065     /**
2066      * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2067      * to represent that the phone is in a desk dock.
2068      */
2069     public static final int EXTRA_DOCK_STATE_DESK = 1;
2070 
2071     /**
2072      * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2073      * to represent that the phone is in a car dock.
2074      */
2075     public static final int EXTRA_DOCK_STATE_CAR = 2;
2076 
2077     /**
2078      * Boolean that can be supplied as meta-data with a dock activity, to
2079      * indicate that the dock should take over the home key when it is active.
2080      */
2081     public static final String METADATA_DOCK_HOME = "android.dock_home";
2082 
2083     /**
2084      * Used as a parcelable extra field in {@link #ACTION_APP_ERROR}, containing
2085      * the bug report.
2086      *
2087      * @hide
2088      */
2089     public static final String EXTRA_BUG_REPORT = "android.intent.extra.BUG_REPORT";
2090 
2091     /**
2092      * Used as a string extra field when sending an intent to PackageInstaller to install a
2093      * package. Specifies the installer package name; this package will receive the
2094      * {@link #ACTION_APP_ERROR} intent.
2095      *
2096      * @hide
2097      */
2098     public static final String EXTRA_INSTALLER_PACKAGE_NAME
2099             = "android.intent.extra.INSTALLER_PACKAGE_NAME";
2100 
2101     /**
2102      * Used in the extra field in the remote intent. It's astring token passed with the
2103      * remote intent.
2104      */
2105     public static final String EXTRA_REMOTE_INTENT_TOKEN =
2106             "android.intent.extra.remote_intent_token";
2107 
2108     /**
2109      * @Deprecated See {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST}; this field
2110      * will contain only the first name in the list.
2111      */
2112     public static final String EXTRA_CHANGED_COMPONENT_NAME =
2113             "android.intent.extra.changed_component_name";
2114 
2115     /**
2116      * This field is part of {@link android.content.Intent#ACTION_PACKAGE_CHANGED}
2117      * and contains a string array of all of the components that have changed.
2118      * @hide
2119      */
2120     public static final String EXTRA_CHANGED_COMPONENT_NAME_LIST =
2121             "android.intent.extra.changed_component_name_list";
2122 
2123     /**
2124      * @hide
2125      * Magic extra system code can use when binding, to give a label for
2126      * who it is that has bound to a service.  This is an integer giving
2127      * a framework string resource that can be displayed to the user.
2128      */
2129     public static final String EXTRA_CLIENT_LABEL =
2130             "android.intent.extra.client_label";
2131 
2132     /**
2133      * @hide
2134      * Magic extra system code can use when binding, to give a PendingIntent object
2135      * that can be launched for the user to disable the system's use of this
2136      * service.
2137      */
2138     public static final String EXTRA_CLIENT_INTENT =
2139             "android.intent.extra.client_intent";
2140 
2141     // ---------------------------------------------------------------------
2142     // ---------------------------------------------------------------------
2143     // Intent flags (see mFlags variable).
2144 
2145     /**
2146      * If set, the recipient of this Intent will be granted permission to
2147      * perform read operations on the Uri in the Intent's data.
2148      */
2149     public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
2150     /**
2151      * If set, the recipient of this Intent will be granted permission to
2152      * perform write operations on the Uri in the Intent's data.
2153      */
2154     public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
2155     /**
2156      * Can be set by the caller to indicate that this Intent is coming from
2157      * a background operation, not from direct user interaction.
2158      */
2159     public static final int FLAG_FROM_BACKGROUND = 0x00000004;
2160     /**
2161      * A flag you can enable for debugging: when set, log messages will be
2162      * printed during the resolution of this intent to show you what has
2163      * been found to create the final resolved list.
2164      */
2165     public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
2166 
2167     /**
2168      * If set, the new activity is not kept in the history stack.  As soon as
2169      * the user navigates away from it, the activity is finished.  This may also
2170      * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
2171      * noHistory} attribute.
2172      */
2173     public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
2174     /**
2175      * If set, the activity will not be launched if it is already running
2176      * at the top of the history stack.
2177      */
2178     public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
2179     /**
2180      * If set, this activity will become the start of a new task on this
2181      * history stack.  A task (from the activity that started it to the
2182      * next task activity) defines an atomic group of activities that the
2183      * user can move to.  Tasks can be moved to the foreground and background;
2184      * all of the activities inside of a particular task always remain in
2185      * the same order.  See
2186      * <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2187      * Activities and Tasks</a> for more details on tasks.
2188      *
2189      * <p>This flag is generally used by activities that want
2190      * to present a "launcher" style behavior: they give the user a list of
2191      * separate things that can be done, which otherwise run completely
2192      * independently of the activity launching them.
2193      *
2194      * <p>When using this flag, if a task is already running for the activity
2195      * you are now starting, then a new activity will not be started; instead,
2196      * the current task will simply be brought to the front of the screen with
2197      * the state it was last in.  See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
2198      * to disable this behavior.
2199      *
2200      * <p>This flag can not be used when the caller is requesting a result from
2201      * the activity being launched.
2202      */
2203     public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
2204     /**
2205      * <strong>Do not use this flag unless you are implementing your own
2206      * top-level application launcher.</strong>  Used in conjunction with
2207      * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the
2208      * behavior of bringing an existing task to the foreground.  When set,
2209      * a new task is <em>always</em> started to host the Activity for the
2210      * Intent, regardless of whether there is already an existing task running
2211      * the same thing.
2212      *
2213      * <p><strong>Because the default system does not include graphical task management,
2214      * you should not use this flag unless you provide some way for a user to
2215      * return back to the tasks you have launched.</strong>
2216      *
2217      * <p>This flag is ignored if
2218      * {@link #FLAG_ACTIVITY_NEW_TASK} is not set.
2219      *
2220      * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2221      * Activities and Tasks</a> for more details on tasks.
2222      */
2223     public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
2224     /**
2225      * If set, and the activity being launched is already running in the
2226      * current task, then instead of launching a new instance of that activity,
2227      * all of the other activities on top of it will be closed and this Intent
2228      * will be delivered to the (now on top) old activity as a new Intent.
2229      *
2230      * <p>For example, consider a task consisting of the activities: A, B, C, D.
2231      * If D calls startActivity() with an Intent that resolves to the component
2232      * of activity B, then C and D will be finished and B receive the given
2233      * Intent, resulting in the stack now being: A, B.
2234      *
2235      * <p>The currently running instance of activity B in the above example will
2236      * either receive the new intent you are starting here in its
2237      * onNewIntent() method, or be itself finished and restarted with the
2238      * new intent.  If it has declared its launch mode to be "multiple" (the
2239      * default) and you have not set {@link #FLAG_ACTIVITY_SINGLE_TOP} in
2240      * the same intent, then it will be finished and re-created; for all other
2241      * launch modes or if {@link #FLAG_ACTIVITY_SINGLE_TOP} is set then this
2242      * Intent will be delivered to the current instance's onNewIntent().
2243      *
2244      * <p>This launch mode can also be used to good effect in conjunction with
2245      * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity
2246      * of a task, it will bring any currently running instance of that task
2247      * to the foreground, and then clear it to its root state.  This is
2248      * especially useful, for example, when launching an activity from the
2249      * notification manager.
2250      *
2251      * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2252      * Activities and Tasks</a> for more details on tasks.
2253      */
2254     public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
2255     /**
2256      * If set and this intent is being used to launch a new activity from an
2257      * existing one, then the reply target of the existing activity will be
2258      * transfered to the new activity.  This way the new activity can call
2259      * {@link android.app.Activity#setResult} and have that result sent back to
2260      * the reply target of the original activity.
2261      */
2262     public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
2263     /**
2264      * If set and this intent is being used to launch a new activity from an
2265      * existing one, the current activity will not be counted as the top
2266      * activity for deciding whether the new intent should be delivered to
2267      * the top instead of starting a new one.  The previous activity will
2268      * be used as the top, with the assumption being that the current activity
2269      * will finish itself immediately.
2270      */
2271     public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
2272     /**
2273      * If set, the new activity is not kept in the list of recently launched
2274      * activities.
2275      */
2276     public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
2277     /**
2278      * This flag is not normally set by application code, but set for you by
2279      * the system as described in the
2280      * {@link android.R.styleable#AndroidManifestActivity_launchMode
2281      * launchMode} documentation for the singleTask mode.
2282      */
2283     public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
2284     /**
2285      * If set, and this activity is either being started in a new task or
2286      * bringing to the top an existing task, then it will be launched as
2287      * the front door of the task.  This will result in the application of
2288      * any affinities needed to have that task in the proper state (either
2289      * moving activities to or from it), or simply resetting that task to
2290      * its initial state if needed.
2291      */
2292     public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
2293     /**
2294      * This flag is not normally set by application code, but set for you by
2295      * the system if this activity is being launched from history
2296      * (longpress home key).
2297      */
2298     public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
2299     /**
2300      * If set, this marks a point in the task's activity stack that should
2301      * be cleared when the task is reset.  That is, the next time the task
2302      * is brought to the foreground with
2303      * {@link #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED} (typically as a result of
2304      * the user re-launching it from home), this activity and all on top of
2305      * it will be finished so that the user does not return to them, but
2306      * instead returns to whatever activity preceeded it.
2307      *
2308      * <p>This is useful for cases where you have a logical break in your
2309      * application.  For example, an e-mail application may have a command
2310      * to view an attachment, which launches an image view activity to
2311      * display it.  This activity should be part of the e-mail application's
2312      * task, since it is a part of the task the user is involved in.  However,
2313      * if the user leaves that task, and later selects the e-mail app from
2314      * home, we may like them to return to the conversation they were
2315      * viewing, not the picture attachment, since that is confusing.  By
2316      * setting this flag when launching the image viewer, that viewer and
2317      * any activities it starts will be removed the next time the user returns
2318      * to mail.
2319      */
2320     public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
2321     /**
2322      * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint}
2323      * callback from occurring on the current frontmost activity before it is
2324      * paused as the newly-started activity is brought to the front.
2325      *
2326      * <p>Typically, an activity can rely on that callback to indicate that an
2327      * explicit user action has caused their activity to be moved out of the
2328      * foreground. The callback marks an appropriate point in the activity's
2329      * lifecycle for it to dismiss any notifications that it intends to display
2330      * "until the user has seen them," such as a blinking LED.
2331      *
2332      * <p>If an activity is ever started via any non-user-driven events such as
2333      * phone-call receipt or an alarm handler, this flag should be passed to {@link
2334      * Context#startActivity Context.startActivity}, ensuring that the pausing
2335      * activity does not think the user has acknowledged its notification.
2336      */
2337     public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
2338     /**
2339      * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
2340      * this flag will cause the launched activity to be brought to the front of its
2341      * task's history stack if it is already running.
2342      *
2343      * <p>For example, consider a task consisting of four activities: A, B, C, D.
2344      * If D calls startActivity() with an Intent that resolves to the component
2345      * of activity B, then B will be brought to the front of the history stack,
2346      * with this resulting order:  A, C, D, B.
2347      *
2348      * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also
2349      * specified.
2350      */
2351     public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
2352     /**
2353      * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
2354      * this flag will prevent the system from applying an activity transition
2355      * animation to go to the next activity state.  This doesn't mean an
2356      * animation will never run -- if another activity change happens that doesn't
2357      * specify this flag before the activity started here is displayed, then
2358      * that transition will be used.  This this flag can be put to good use
2359      * when you are going to do a series of activity operations but the
2360      * animation seen by the user shouldn't be driven by the first activity
2361      * change but rather a later one.
2362      */
2363     public static final int FLAG_ACTIVITY_NO_ANIMATION = 0X00010000;
2364     /**
2365      * If set, when sending a broadcast only registered receivers will be
2366      * called -- no BroadcastReceiver components will be launched.
2367      */
2368     public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
2369     /**
2370      * If set, when sending a broadcast <i>before boot has completed</i> only
2371      * registered receivers will be called -- no BroadcastReceiver components
2372      * will be launched.  Sticky intent state will be recorded properly even
2373      * if no receivers wind up being called.  If {@link #FLAG_RECEIVER_REGISTERED_ONLY}
2374      * is specified in the broadcast intent, this flag is unnecessary.
2375      *
2376      * <p>This flag is only for use by system sevices as a convenience to
2377      * avoid having to implement a more complex mechanism around detection
2378      * of boot completion.
2379      *
2380      * @hide
2381      */
2382     public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x20000000;
2383     /**
2384      * Set when this broadcast is for a boot upgrade, a special mode that
2385      * allows the broadcast to be sent before the system is ready and launches
2386      * the app process with no providers running in it.
2387      * @hide
2388      */
2389     public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x10000000;
2390 
2391     /**
2392      * @hide Flags that can't be changed with PendingIntent.
2393      */
2394     public static final int IMMUTABLE_FLAGS =
2395             FLAG_GRANT_READ_URI_PERMISSION
2396             | FLAG_GRANT_WRITE_URI_PERMISSION;
2397 
2398     // ---------------------------------------------------------------------
2399     // ---------------------------------------------------------------------
2400     // toUri() and parseUri() options.
2401 
2402     /**
2403      * Flag for use with {@link #toUri} and {@link #parseUri}: the URI string
2404      * always has the "intent:" scheme.  This syntax can be used when you want
2405      * to later disambiguate between URIs that are intended to describe an
2406      * Intent vs. all others that should be treated as raw URIs.  When used
2407      * with {@link #parseUri}, any other scheme will result in a generic
2408      * VIEW action for that raw URI.
2409      */
2410     public static final int URI_INTENT_SCHEME = 1<<0;
2411 
2412     // ---------------------------------------------------------------------
2413 
2414     private String mAction;
2415     private Uri mData;
2416     private String mType;
2417     private String mPackage;
2418     private ComponentName mComponent;
2419     private int mFlags;
2420     private HashSet<String> mCategories;
2421     private Bundle mExtras;
2422 
2423     // ---------------------------------------------------------------------
2424 
2425     /**
2426      * Create an empty intent.
2427      */
Intent()2428     public Intent() {
2429     }
2430 
2431     /**
2432      * Copy constructor.
2433      */
Intent(Intent o)2434     public Intent(Intent o) {
2435         this.mAction = o.mAction;
2436         this.mData = o.mData;
2437         this.mType = o.mType;
2438         this.mPackage = o.mPackage;
2439         this.mComponent = o.mComponent;
2440         this.mFlags = o.mFlags;
2441         if (o.mCategories != null) {
2442             this.mCategories = new HashSet<String>(o.mCategories);
2443         }
2444         if (o.mExtras != null) {
2445             this.mExtras = new Bundle(o.mExtras);
2446         }
2447     }
2448 
2449     @Override
clone()2450     public Object clone() {
2451         return new Intent(this);
2452     }
2453 
Intent(Intent o, boolean all)2454     private Intent(Intent o, boolean all) {
2455         this.mAction = o.mAction;
2456         this.mData = o.mData;
2457         this.mType = o.mType;
2458         this.mPackage = o.mPackage;
2459         this.mComponent = o.mComponent;
2460         if (o.mCategories != null) {
2461             this.mCategories = new HashSet<String>(o.mCategories);
2462         }
2463     }
2464 
2465     /**
2466      * Make a clone of only the parts of the Intent that are relevant for
2467      * filter matching: the action, data, type, component, and categories.
2468      */
cloneFilter()2469     public Intent cloneFilter() {
2470         return new Intent(this, false);
2471     }
2472 
2473     /**
2474      * Create an intent with a given action.  All other fields (data, type,
2475      * class) are null.  Note that the action <em>must</em> be in a
2476      * namespace because Intents are used globally in the system -- for
2477      * example the system VIEW action is android.intent.action.VIEW; an
2478      * application's custom action would be something like
2479      * com.google.app.myapp.CUSTOM_ACTION.
2480      *
2481      * @param action The Intent action, such as ACTION_VIEW.
2482      */
Intent(String action)2483     public Intent(String action) {
2484         mAction = action;
2485     }
2486 
2487     /**
2488      * Create an intent with a given action and for a given data url.  Note
2489      * that the action <em>must</em> be in a namespace because Intents are
2490      * used globally in the system -- for example the system VIEW action is
2491      * android.intent.action.VIEW; an application's custom action would be
2492      * something like com.google.app.myapp.CUSTOM_ACTION.
2493      *
2494      * <p><em>Note: scheme and host name matching in the Android framework is
2495      * case-sensitive, unlike the formal RFC.  As a result,
2496      * you should always ensure that you write your Uri with these elements
2497      * using lower case letters, and normalize any Uris you receive from
2498      * outside of Android to ensure the scheme and host is lower case.</em></p>
2499      *
2500      * @param action The Intent action, such as ACTION_VIEW.
2501      * @param uri The Intent data URI.
2502      */
Intent(String action, Uri uri)2503     public Intent(String action, Uri uri) {
2504         mAction = action;
2505         mData = uri;
2506     }
2507 
2508     /**
2509      * Create an intent for a specific component.  All other fields (action, data,
2510      * type, class) are null, though they can be modified later with explicit
2511      * calls.  This provides a convenient way to create an intent that is
2512      * intended to execute a hard-coded class name, rather than relying on the
2513      * system to find an appropriate class for you; see {@link #setComponent}
2514      * for more information on the repercussions of this.
2515      *
2516      * @param packageContext A Context of the application package implementing
2517      * this class.
2518      * @param cls The component class that is to be used for the intent.
2519      *
2520      * @see #setClass
2521      * @see #setComponent
2522      * @see #Intent(String, android.net.Uri , Context, Class)
2523      */
Intent(Context packageContext, Class<?> cls)2524     public Intent(Context packageContext, Class<?> cls) {
2525         mComponent = new ComponentName(packageContext, cls);
2526     }
2527 
2528     /**
2529      * Create an intent for a specific component with a specified action and data.
2530      * This is equivalent using {@link #Intent(String, android.net.Uri)} to
2531      * construct the Intent and then calling {@link #setClass} to set its
2532      * class.
2533      *
2534      * <p><em>Note: scheme and host name matching in the Android framework is
2535      * case-sensitive, unlike the formal RFC.  As a result,
2536      * you should always ensure that you write your Uri with these elements
2537      * using lower case letters, and normalize any Uris you receive from
2538      * outside of Android to ensure the scheme and host is lower case.</em></p>
2539      *
2540      * @param action The Intent action, such as ACTION_VIEW.
2541      * @param uri The Intent data URI.
2542      * @param packageContext A Context of the application package implementing
2543      * this class.
2544      * @param cls The component class that is to be used for the intent.
2545      *
2546      * @see #Intent(String, android.net.Uri)
2547      * @see #Intent(Context, Class)
2548      * @see #setClass
2549      * @see #setComponent
2550      */
Intent(String action, Uri uri, Context packageContext, Class<?> cls)2551     public Intent(String action, Uri uri,
2552             Context packageContext, Class<?> cls) {
2553         mAction = action;
2554         mData = uri;
2555         mComponent = new ComponentName(packageContext, cls);
2556     }
2557 
2558     /**
2559      * Call {@link #parseUri} with 0 flags.
2560      * @deprecated Use {@link #parseUri} instead.
2561      */
2562     @Deprecated
getIntent(String uri)2563     public static Intent getIntent(String uri) throws URISyntaxException {
2564         return parseUri(uri, 0);
2565     }
2566 
2567     /**
2568      * Create an intent from a URI.  This URI may encode the action,
2569      * category, and other intent fields, if it was returned by
2570      * {@link #toUri}.  If the Intent was not generate by toUri(), its data
2571      * will be the entire URI and its action will be ACTION_VIEW.
2572      *
2573      * <p>The URI given here must not be relative -- that is, it must include
2574      * the scheme and full path.
2575      *
2576      * @param uri The URI to turn into an Intent.
2577      * @param flags Additional processing flags.  Either 0 or
2578      * {@link #URI_INTENT_SCHEME}.
2579      *
2580      * @return Intent The newly created Intent object.
2581      *
2582      * @throws URISyntaxException Throws URISyntaxError if the basic URI syntax
2583      * it bad (as parsed by the Uri class) or the Intent data within the
2584      * URI is invalid.
2585      *
2586      * @see #toUri
2587      */
parseUri(String uri, int flags)2588     public static Intent parseUri(String uri, int flags) throws URISyntaxException {
2589         int i = 0;
2590         try {
2591             // Validate intent scheme for if requested.
2592             if ((flags&URI_INTENT_SCHEME) != 0) {
2593                 if (!uri.startsWith("intent:")) {
2594                     Intent intent = new Intent(ACTION_VIEW);
2595                     try {
2596                         intent.setData(Uri.parse(uri));
2597                     } catch (IllegalArgumentException e) {
2598                         throw new URISyntaxException(uri, e.getMessage());
2599                     }
2600                     return intent;
2601                 }
2602             }
2603 
2604             // simple case
2605             i = uri.lastIndexOf("#");
2606             if (i == -1) return new Intent(ACTION_VIEW, Uri.parse(uri));
2607 
2608             // old format Intent URI
2609             if (!uri.startsWith("#Intent;", i)) return getIntentOld(uri);
2610 
2611             // new format
2612             Intent intent = new Intent(ACTION_VIEW);
2613 
2614             // fetch data part, if present
2615             String data = i >= 0 ? uri.substring(0, i) : null;
2616             String scheme = null;
2617             i += "#Intent;".length();
2618 
2619             // loop over contents of Intent, all name=value;
2620             while (!uri.startsWith("end", i)) {
2621                 int eq = uri.indexOf('=', i);
2622                 int semi = uri.indexOf(';', eq);
2623                 String value = Uri.decode(uri.substring(eq + 1, semi));
2624 
2625                 // action
2626                 if (uri.startsWith("action=", i)) {
2627                     intent.mAction = value;
2628                 }
2629 
2630                 // categories
2631                 else if (uri.startsWith("category=", i)) {
2632                     intent.addCategory(value);
2633                 }
2634 
2635                 // type
2636                 else if (uri.startsWith("type=", i)) {
2637                     intent.mType = value;
2638                 }
2639 
2640                 // launch  flags
2641                 else if (uri.startsWith("launchFlags=", i)) {
2642                     intent.mFlags = Integer.decode(value).intValue();
2643                 }
2644 
2645                 // package
2646                 else if (uri.startsWith("package=", i)) {
2647                     intent.mPackage = value;
2648                 }
2649 
2650                 // component
2651                 else if (uri.startsWith("component=", i)) {
2652                     intent.mComponent = ComponentName.unflattenFromString(value);
2653                 }
2654 
2655                 // scheme
2656                 else if (uri.startsWith("scheme=", i)) {
2657                     scheme = value;
2658                 }
2659 
2660                 // extra
2661                 else {
2662                     String key = Uri.decode(uri.substring(i + 2, eq));
2663                     // create Bundle if it doesn't already exist
2664                     if (intent.mExtras == null) intent.mExtras = new Bundle();
2665                     Bundle b = intent.mExtras;
2666                     // add EXTRA
2667                     if      (uri.startsWith("S.", i)) b.putString(key, value);
2668                     else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
2669                     else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
2670                     else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
2671                     else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
2672                     else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
2673                     else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
2674                     else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
2675                     else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
2676                     else throw new URISyntaxException(uri, "unknown EXTRA type", i);
2677                 }
2678 
2679                 // move to the next item
2680                 i = semi + 1;
2681             }
2682 
2683             if (data != null) {
2684                 if (data.startsWith("intent:")) {
2685                     data = data.substring(7);
2686                     if (scheme != null) {
2687                         data = scheme + ':' + data;
2688                     }
2689                 }
2690 
2691                 if (data.length() > 0) {
2692                     try {
2693                         intent.mData = Uri.parse(data);
2694                     } catch (IllegalArgumentException e) {
2695                         throw new URISyntaxException(uri, e.getMessage());
2696                     }
2697                 }
2698             }
2699 
2700             return intent;
2701 
2702         } catch (IndexOutOfBoundsException e) {
2703             throw new URISyntaxException(uri, "illegal Intent URI format", i);
2704         }
2705     }
2706 
getIntentOld(String uri)2707     public static Intent getIntentOld(String uri) throws URISyntaxException {
2708         Intent intent;
2709 
2710         int i = uri.lastIndexOf('#');
2711         if (i >= 0) {
2712             String action = null;
2713             final int intentFragmentStart = i;
2714             boolean isIntentFragment = false;
2715 
2716             i++;
2717 
2718             if (uri.regionMatches(i, "action(", 0, 7)) {
2719                 isIntentFragment = true;
2720                 i += 7;
2721                 int j = uri.indexOf(')', i);
2722                 action = uri.substring(i, j);
2723                 i = j + 1;
2724             }
2725 
2726             intent = new Intent(action);
2727 
2728             if (uri.regionMatches(i, "categories(", 0, 11)) {
2729                 isIntentFragment = true;
2730                 i += 11;
2731                 int j = uri.indexOf(')', i);
2732                 while (i < j) {
2733                     int sep = uri.indexOf('!', i);
2734                     if (sep < 0) sep = j;
2735                     if (i < sep) {
2736                         intent.addCategory(uri.substring(i, sep));
2737                     }
2738                     i = sep + 1;
2739                 }
2740                 i = j + 1;
2741             }
2742 
2743             if (uri.regionMatches(i, "type(", 0, 5)) {
2744                 isIntentFragment = true;
2745                 i += 5;
2746                 int j = uri.indexOf(')', i);
2747                 intent.mType = uri.substring(i, j);
2748                 i = j + 1;
2749             }
2750 
2751             if (uri.regionMatches(i, "launchFlags(", 0, 12)) {
2752                 isIntentFragment = true;
2753                 i += 12;
2754                 int j = uri.indexOf(')', i);
2755                 intent.mFlags = Integer.decode(uri.substring(i, j)).intValue();
2756                 i = j + 1;
2757             }
2758 
2759             if (uri.regionMatches(i, "component(", 0, 10)) {
2760                 isIntentFragment = true;
2761                 i += 10;
2762                 int j = uri.indexOf(')', i);
2763                 int sep = uri.indexOf('!', i);
2764                 if (sep >= 0 && sep < j) {
2765                     String pkg = uri.substring(i, sep);
2766                     String cls = uri.substring(sep + 1, j);
2767                     intent.mComponent = new ComponentName(pkg, cls);
2768                 }
2769                 i = j + 1;
2770             }
2771 
2772             if (uri.regionMatches(i, "extras(", 0, 7)) {
2773                 isIntentFragment = true;
2774                 i += 7;
2775 
2776                 final int closeParen = uri.indexOf(')', i);
2777                 if (closeParen == -1) throw new URISyntaxException(uri,
2778                         "EXTRA missing trailing ')'", i);
2779 
2780                 while (i < closeParen) {
2781                     // fetch the key value
2782                     int j = uri.indexOf('=', i);
2783                     if (j <= i + 1 || i >= closeParen) {
2784                         throw new URISyntaxException(uri, "EXTRA missing '='", i);
2785                     }
2786                     char type = uri.charAt(i);
2787                     i++;
2788                     String key = uri.substring(i, j);
2789                     i = j + 1;
2790 
2791                     // get type-value
2792                     j = uri.indexOf('!', i);
2793                     if (j == -1 || j >= closeParen) j = closeParen;
2794                     if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2795                     String value = uri.substring(i, j);
2796                     i = j;
2797 
2798                     // create Bundle if it doesn't already exist
2799                     if (intent.mExtras == null) intent.mExtras = new Bundle();
2800 
2801                     // add item to bundle
2802                     try {
2803                         switch (type) {
2804                             case 'S':
2805                                 intent.mExtras.putString(key, Uri.decode(value));
2806                                 break;
2807                             case 'B':
2808                                 intent.mExtras.putBoolean(key, Boolean.parseBoolean(value));
2809                                 break;
2810                             case 'b':
2811                                 intent.mExtras.putByte(key, Byte.parseByte(value));
2812                                 break;
2813                             case 'c':
2814                                 intent.mExtras.putChar(key, Uri.decode(value).charAt(0));
2815                                 break;
2816                             case 'd':
2817                                 intent.mExtras.putDouble(key, Double.parseDouble(value));
2818                                 break;
2819                             case 'f':
2820                                 intent.mExtras.putFloat(key, Float.parseFloat(value));
2821                                 break;
2822                             case 'i':
2823                                 intent.mExtras.putInt(key, Integer.parseInt(value));
2824                                 break;
2825                             case 'l':
2826                                 intent.mExtras.putLong(key, Long.parseLong(value));
2827                                 break;
2828                             case 's':
2829                                 intent.mExtras.putShort(key, Short.parseShort(value));
2830                                 break;
2831                             default:
2832                                 throw new URISyntaxException(uri, "EXTRA has unknown type", i);
2833                         }
2834                     } catch (NumberFormatException e) {
2835                         throw new URISyntaxException(uri, "EXTRA value can't be parsed", i);
2836                     }
2837 
2838                     char ch = uri.charAt(i);
2839                     if (ch == ')') break;
2840                     if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2841                     i++;
2842                 }
2843             }
2844 
2845             if (isIntentFragment) {
2846                 intent.mData = Uri.parse(uri.substring(0, intentFragmentStart));
2847             } else {
2848                 intent.mData = Uri.parse(uri);
2849             }
2850 
2851             if (intent.mAction == null) {
2852                 // By default, if no action is specified, then use VIEW.
2853                 intent.mAction = ACTION_VIEW;
2854             }
2855 
2856         } else {
2857             intent = new Intent(ACTION_VIEW, Uri.parse(uri));
2858         }
2859 
2860         return intent;
2861     }
2862 
2863     /**
2864      * Retrieve the general action to be performed, such as
2865      * {@link #ACTION_VIEW}.  The action describes the general way the rest of
2866      * the information in the intent should be interpreted -- most importantly,
2867      * what to do with the data returned by {@link #getData}.
2868      *
2869      * @return The action of this intent or null if none is specified.
2870      *
2871      * @see #setAction
2872      */
getAction()2873     public String getAction() {
2874         return mAction;
2875     }
2876 
2877     /**
2878      * Retrieve data this intent is operating on.  This URI specifies the name
2879      * of the data; often it uses the content: scheme, specifying data in a
2880      * content provider.  Other schemes may be handled by specific activities,
2881      * such as http: by the web browser.
2882      *
2883      * @return The URI of the data this intent is targeting or null.
2884      *
2885      * @see #getScheme
2886      * @see #setData
2887      */
getData()2888     public Uri getData() {
2889         return mData;
2890     }
2891 
2892     /**
2893      * The same as {@link #getData()}, but returns the URI as an encoded
2894      * String.
2895      */
getDataString()2896     public String getDataString() {
2897         return mData != null ? mData.toString() : null;
2898     }
2899 
2900     /**
2901      * Return the scheme portion of the intent's data.  If the data is null or
2902      * does not include a scheme, null is returned.  Otherwise, the scheme
2903      * prefix without the final ':' is returned, i.e. "http".
2904      *
2905      * <p>This is the same as calling getData().getScheme() (and checking for
2906      * null data).
2907      *
2908      * @return The scheme of this intent.
2909      *
2910      * @see #getData
2911      */
getScheme()2912     public String getScheme() {
2913         return mData != null ? mData.getScheme() : null;
2914     }
2915 
2916     /**
2917      * Retrieve any explicit MIME type included in the intent.  This is usually
2918      * null, as the type is determined by the intent data.
2919      *
2920      * @return If a type was manually set, it is returned; else null is
2921      *         returned.
2922      *
2923      * @see #resolveType(ContentResolver)
2924      * @see #setType
2925      */
getType()2926     public String getType() {
2927         return mType;
2928     }
2929 
2930     /**
2931      * Return the MIME data type of this intent.  If the type field is
2932      * explicitly set, that is simply returned.  Otherwise, if the data is set,
2933      * the type of that data is returned.  If neither fields are set, a null is
2934      * returned.
2935      *
2936      * @return The MIME type of this intent.
2937      *
2938      * @see #getType
2939      * @see #resolveType(ContentResolver)
2940      */
resolveType(Context context)2941     public String resolveType(Context context) {
2942         return resolveType(context.getContentResolver());
2943     }
2944 
2945     /**
2946      * Return the MIME data type of this intent.  If the type field is
2947      * explicitly set, that is simply returned.  Otherwise, if the data is set,
2948      * the type of that data is returned.  If neither fields are set, a null is
2949      * returned.
2950      *
2951      * @param resolver A ContentResolver that can be used to determine the MIME
2952      *                 type of the intent's data.
2953      *
2954      * @return The MIME type of this intent.
2955      *
2956      * @see #getType
2957      * @see #resolveType(Context)
2958      */
resolveType(ContentResolver resolver)2959     public String resolveType(ContentResolver resolver) {
2960         if (mType != null) {
2961             return mType;
2962         }
2963         if (mData != null) {
2964             if ("content".equals(mData.getScheme())) {
2965                 return resolver.getType(mData);
2966             }
2967         }
2968         return null;
2969     }
2970 
2971     /**
2972      * Return the MIME data type of this intent, only if it will be needed for
2973      * intent resolution.  This is not generally useful for application code;
2974      * it is used by the frameworks for communicating with back-end system
2975      * services.
2976      *
2977      * @param resolver A ContentResolver that can be used to determine the MIME
2978      *                 type of the intent's data.
2979      *
2980      * @return The MIME type of this intent, or null if it is unknown or not
2981      *         needed.
2982      */
resolveTypeIfNeeded(ContentResolver resolver)2983     public String resolveTypeIfNeeded(ContentResolver resolver) {
2984         if (mComponent != null) {
2985             return mType;
2986         }
2987         return resolveType(resolver);
2988     }
2989 
2990     /**
2991      * Check if an category exists in the intent.
2992      *
2993      * @param category The category to check.
2994      *
2995      * @return boolean True if the intent contains the category, else false.
2996      *
2997      * @see #getCategories
2998      * @see #addCategory
2999      */
hasCategory(String category)3000     public boolean hasCategory(String category) {
3001         return mCategories != null && mCategories.contains(category);
3002     }
3003 
3004     /**
3005      * Return the set of all categories in the intent.  If there are no categories,
3006      * returns NULL.
3007      *
3008      * @return Set The set of categories you can examine.  Do not modify!
3009      *
3010      * @see #hasCategory
3011      * @see #addCategory
3012      */
getCategories()3013     public Set<String> getCategories() {
3014         return mCategories;
3015     }
3016 
3017     /**
3018      * Sets the ClassLoader that will be used when unmarshalling
3019      * any Parcelable values from the extras of this Intent.
3020      *
3021      * @param loader a ClassLoader, or null to use the default loader
3022      * at the time of unmarshalling.
3023      */
setExtrasClassLoader(ClassLoader loader)3024     public void setExtrasClassLoader(ClassLoader loader) {
3025         if (mExtras != null) {
3026             mExtras.setClassLoader(loader);
3027         }
3028     }
3029 
3030     /**
3031      * Returns true if an extra value is associated with the given name.
3032      * @param name the extra's name
3033      * @return true if the given extra is present.
3034      */
hasExtra(String name)3035     public boolean hasExtra(String name) {
3036         return mExtras != null && mExtras.containsKey(name);
3037     }
3038 
3039     /**
3040      * Returns true if the Intent's extras contain a parcelled file descriptor.
3041      * @return true if the Intent contains a parcelled file descriptor.
3042      */
hasFileDescriptors()3043     public boolean hasFileDescriptors() {
3044         return mExtras != null && mExtras.hasFileDescriptors();
3045     }
3046 
3047     /**
3048      * Retrieve extended data from the intent.
3049      *
3050      * @param name The name of the desired item.
3051      *
3052      * @return the value of an item that previously added with putExtra()
3053      * or null if none was found.
3054      *
3055      * @deprecated
3056      * @hide
3057      */
3058     @Deprecated
getExtra(String name)3059     public Object getExtra(String name) {
3060         return getExtra(name, null);
3061     }
3062 
3063     /**
3064      * Retrieve extended data from the intent.
3065      *
3066      * @param name The name of the desired item.
3067      * @param defaultValue the value to be returned if no value of the desired
3068      * type is stored with the given name.
3069      *
3070      * @return the value of an item that previously added with putExtra()
3071      * or the default value if none was found.
3072      *
3073      * @see #putExtra(String, boolean)
3074      */
getBooleanExtra(String name, boolean defaultValue)3075     public boolean getBooleanExtra(String name, boolean defaultValue) {
3076         return mExtras == null ? defaultValue :
3077             mExtras.getBoolean(name, defaultValue);
3078     }
3079 
3080     /**
3081      * Retrieve extended data from the intent.
3082      *
3083      * @param name The name of the desired item.
3084      * @param defaultValue the value to be returned if no value of the desired
3085      * type is stored with the given name.
3086      *
3087      * @return the value of an item that previously added with putExtra()
3088      * or the default value if none was found.
3089      *
3090      * @see #putExtra(String, byte)
3091      */
getByteExtra(String name, byte defaultValue)3092     public byte getByteExtra(String name, byte defaultValue) {
3093         return mExtras == null ? defaultValue :
3094             mExtras.getByte(name, defaultValue);
3095     }
3096 
3097     /**
3098      * Retrieve extended data from the intent.
3099      *
3100      * @param name The name of the desired item.
3101      * @param defaultValue the value to be returned if no value of the desired
3102      * type is stored with the given name.
3103      *
3104      * @return the value of an item that previously added with putExtra()
3105      * or the default value if none was found.
3106      *
3107      * @see #putExtra(String, short)
3108      */
getShortExtra(String name, short defaultValue)3109     public short getShortExtra(String name, short defaultValue) {
3110         return mExtras == null ? defaultValue :
3111             mExtras.getShort(name, defaultValue);
3112     }
3113 
3114     /**
3115      * Retrieve extended data from the intent.
3116      *
3117      * @param name The name of the desired item.
3118      * @param defaultValue the value to be returned if no value of the desired
3119      * type is stored with the given name.
3120      *
3121      * @return the value of an item that previously added with putExtra()
3122      * or the default value if none was found.
3123      *
3124      * @see #putExtra(String, char)
3125      */
getCharExtra(String name, char defaultValue)3126     public char getCharExtra(String name, char defaultValue) {
3127         return mExtras == null ? defaultValue :
3128             mExtras.getChar(name, defaultValue);
3129     }
3130 
3131     /**
3132      * Retrieve extended data from the intent.
3133      *
3134      * @param name The name of the desired item.
3135      * @param defaultValue the value to be returned if no value of the desired
3136      * type is stored with the given name.
3137      *
3138      * @return the value of an item that previously added with putExtra()
3139      * or the default value if none was found.
3140      *
3141      * @see #putExtra(String, int)
3142      */
getIntExtra(String name, int defaultValue)3143     public int getIntExtra(String name, int defaultValue) {
3144         return mExtras == null ? defaultValue :
3145             mExtras.getInt(name, defaultValue);
3146     }
3147 
3148     /**
3149      * Retrieve extended data from the intent.
3150      *
3151      * @param name The name of the desired item.
3152      * @param defaultValue the value to be returned if no value of the desired
3153      * type is stored with the given name.
3154      *
3155      * @return the value of an item that previously added with putExtra()
3156      * or the default value if none was found.
3157      *
3158      * @see #putExtra(String, long)
3159      */
getLongExtra(String name, long defaultValue)3160     public long getLongExtra(String name, long defaultValue) {
3161         return mExtras == null ? defaultValue :
3162             mExtras.getLong(name, defaultValue);
3163     }
3164 
3165     /**
3166      * Retrieve extended data from the intent.
3167      *
3168      * @param name The name of the desired item.
3169      * @param defaultValue the value to be returned if no value of the desired
3170      * type is stored with the given name.
3171      *
3172      * @return the value of an item that previously added with putExtra(),
3173      * or the default value if no such item is present
3174      *
3175      * @see #putExtra(String, float)
3176      */
getFloatExtra(String name, float defaultValue)3177     public float getFloatExtra(String name, float defaultValue) {
3178         return mExtras == null ? defaultValue :
3179             mExtras.getFloat(name, defaultValue);
3180     }
3181 
3182     /**
3183      * Retrieve extended data from the intent.
3184      *
3185      * @param name The name of the desired item.
3186      * @param defaultValue the value to be returned if no value of the desired
3187      * type is stored with the given name.
3188      *
3189      * @return the value of an item that previously added with putExtra()
3190      * or the default value if none was found.
3191      *
3192      * @see #putExtra(String, double)
3193      */
getDoubleExtra(String name, double defaultValue)3194     public double getDoubleExtra(String name, double defaultValue) {
3195         return mExtras == null ? defaultValue :
3196             mExtras.getDouble(name, defaultValue);
3197     }
3198 
3199     /**
3200      * Retrieve extended data from the intent.
3201      *
3202      * @param name The name of the desired item.
3203      *
3204      * @return the value of an item that previously added with putExtra()
3205      * or null if no String value was found.
3206      *
3207      * @see #putExtra(String, String)
3208      */
getStringExtra(String name)3209     public String getStringExtra(String name) {
3210         return mExtras == null ? null : mExtras.getString(name);
3211     }
3212 
3213     /**
3214      * Retrieve extended data from the intent.
3215      *
3216      * @param name The name of the desired item.
3217      *
3218      * @return the value of an item that previously added with putExtra()
3219      * or null if no CharSequence value was found.
3220      *
3221      * @see #putExtra(String, CharSequence)
3222      */
getCharSequenceExtra(String name)3223     public CharSequence getCharSequenceExtra(String name) {
3224         return mExtras == null ? null : mExtras.getCharSequence(name);
3225     }
3226 
3227     /**
3228      * Retrieve extended data from the intent.
3229      *
3230      * @param name The name of the desired item.
3231      *
3232      * @return the value of an item that previously added with putExtra()
3233      * or null if no Parcelable value was found.
3234      *
3235      * @see #putExtra(String, Parcelable)
3236      */
getParcelableExtra(String name)3237     public <T extends Parcelable> T getParcelableExtra(String name) {
3238         return mExtras == null ? null : mExtras.<T>getParcelable(name);
3239     }
3240 
3241     /**
3242      * Retrieve extended data from the intent.
3243      *
3244      * @param name The name of the desired item.
3245      *
3246      * @return the value of an item that previously added with putExtra()
3247      * or null if no Parcelable[] value was found.
3248      *
3249      * @see #putExtra(String, Parcelable[])
3250      */
getParcelableArrayExtra(String name)3251     public Parcelable[] getParcelableArrayExtra(String name) {
3252         return mExtras == null ? null : mExtras.getParcelableArray(name);
3253     }
3254 
3255     /**
3256      * Retrieve extended data from the intent.
3257      *
3258      * @param name The name of the desired item.
3259      *
3260      * @return the value of an item that previously added with putExtra()
3261      * or null if no ArrayList<Parcelable> value was found.
3262      *
3263      * @see #putParcelableArrayListExtra(String, ArrayList)
3264      */
getParcelableArrayListExtra(String name)3265     public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
3266         return mExtras == null ? null : mExtras.<T>getParcelableArrayList(name);
3267     }
3268 
3269     /**
3270      * Retrieve extended data from the intent.
3271      *
3272      * @param name The name of the desired item.
3273      *
3274      * @return the value of an item that previously added with putExtra()
3275      * or null if no Serializable value was found.
3276      *
3277      * @see #putExtra(String, Serializable)
3278      */
getSerializableExtra(String name)3279     public Serializable getSerializableExtra(String name) {
3280         return mExtras == null ? null : mExtras.getSerializable(name);
3281     }
3282 
3283     /**
3284      * Retrieve extended data from the intent.
3285      *
3286      * @param name The name of the desired item.
3287      *
3288      * @return the value of an item that previously added with putExtra()
3289      * or null if no ArrayList<Integer> value was found.
3290      *
3291      * @see #putIntegerArrayListExtra(String, ArrayList)
3292      */
getIntegerArrayListExtra(String name)3293     public ArrayList<Integer> getIntegerArrayListExtra(String name) {
3294         return mExtras == null ? null : mExtras.getIntegerArrayList(name);
3295     }
3296 
3297     /**
3298      * Retrieve extended data from the intent.
3299      *
3300      * @param name The name of the desired item.
3301      *
3302      * @return the value of an item that previously added with putExtra()
3303      * or null if no ArrayList<String> value was found.
3304      *
3305      * @see #putStringArrayListExtra(String, ArrayList)
3306      */
getStringArrayListExtra(String name)3307     public ArrayList<String> getStringArrayListExtra(String name) {
3308         return mExtras == null ? null : mExtras.getStringArrayList(name);
3309     }
3310 
3311     /**
3312      * Retrieve extended data from the intent.
3313      *
3314      * @param name The name of the desired item.
3315      *
3316      * @return the value of an item that previously added with putExtra()
3317      * or null if no boolean array value was found.
3318      *
3319      * @see #putExtra(String, boolean[])
3320      */
getBooleanArrayExtra(String name)3321     public boolean[] getBooleanArrayExtra(String name) {
3322         return mExtras == null ? null : mExtras.getBooleanArray(name);
3323     }
3324 
3325     /**
3326      * Retrieve extended data from the intent.
3327      *
3328      * @param name The name of the desired item.
3329      *
3330      * @return the value of an item that previously added with putExtra()
3331      * or null if no byte array value was found.
3332      *
3333      * @see #putExtra(String, byte[])
3334      */
getByteArrayExtra(String name)3335     public byte[] getByteArrayExtra(String name) {
3336         return mExtras == null ? null : mExtras.getByteArray(name);
3337     }
3338 
3339     /**
3340      * Retrieve extended data from the intent.
3341      *
3342      * @param name The name of the desired item.
3343      *
3344      * @return the value of an item that previously added with putExtra()
3345      * or null if no short array value was found.
3346      *
3347      * @see #putExtra(String, short[])
3348      */
getShortArrayExtra(String name)3349     public short[] getShortArrayExtra(String name) {
3350         return mExtras == null ? null : mExtras.getShortArray(name);
3351     }
3352 
3353     /**
3354      * Retrieve extended data from the intent.
3355      *
3356      * @param name The name of the desired item.
3357      *
3358      * @return the value of an item that previously added with putExtra()
3359      * or null if no char array value was found.
3360      *
3361      * @see #putExtra(String, char[])
3362      */
getCharArrayExtra(String name)3363     public char[] getCharArrayExtra(String name) {
3364         return mExtras == null ? null : mExtras.getCharArray(name);
3365     }
3366 
3367     /**
3368      * Retrieve extended data from the intent.
3369      *
3370      * @param name The name of the desired item.
3371      *
3372      * @return the value of an item that previously added with putExtra()
3373      * or null if no int array value was found.
3374      *
3375      * @see #putExtra(String, int[])
3376      */
getIntArrayExtra(String name)3377     public int[] getIntArrayExtra(String name) {
3378         return mExtras == null ? null : mExtras.getIntArray(name);
3379     }
3380 
3381     /**
3382      * Retrieve extended data from the intent.
3383      *
3384      * @param name The name of the desired item.
3385      *
3386      * @return the value of an item that previously added with putExtra()
3387      * or null if no long array value was found.
3388      *
3389      * @see #putExtra(String, long[])
3390      */
getLongArrayExtra(String name)3391     public long[] getLongArrayExtra(String name) {
3392         return mExtras == null ? null : mExtras.getLongArray(name);
3393     }
3394 
3395     /**
3396      * Retrieve extended data from the intent.
3397      *
3398      * @param name The name of the desired item.
3399      *
3400      * @return the value of an item that previously added with putExtra()
3401      * or null if no float array value was found.
3402      *
3403      * @see #putExtra(String, float[])
3404      */
getFloatArrayExtra(String name)3405     public float[] getFloatArrayExtra(String name) {
3406         return mExtras == null ? null : mExtras.getFloatArray(name);
3407     }
3408 
3409     /**
3410      * Retrieve extended data from the intent.
3411      *
3412      * @param name The name of the desired item.
3413      *
3414      * @return the value of an item that previously added with putExtra()
3415      * or null if no double array value was found.
3416      *
3417      * @see #putExtra(String, double[])
3418      */
getDoubleArrayExtra(String name)3419     public double[] getDoubleArrayExtra(String name) {
3420         return mExtras == null ? null : mExtras.getDoubleArray(name);
3421     }
3422 
3423     /**
3424      * Retrieve extended data from the intent.
3425      *
3426      * @param name The name of the desired item.
3427      *
3428      * @return the value of an item that previously added with putExtra()
3429      * or null if no String array value was found.
3430      *
3431      * @see #putExtra(String, String[])
3432      */
getStringArrayExtra(String name)3433     public String[] getStringArrayExtra(String name) {
3434         return mExtras == null ? null : mExtras.getStringArray(name);
3435     }
3436 
3437     /**
3438      * Retrieve extended data from the intent.
3439      *
3440      * @param name The name of the desired item.
3441      *
3442      * @return the value of an item that previously added with putExtra()
3443      * or null if no Bundle value was found.
3444      *
3445      * @see #putExtra(String, Bundle)
3446      */
getBundleExtra(String name)3447     public Bundle getBundleExtra(String name) {
3448         return mExtras == null ? null : mExtras.getBundle(name);
3449     }
3450 
3451     /**
3452      * Retrieve extended data from the intent.
3453      *
3454      * @param name The name of the desired item.
3455      *
3456      * @return the value of an item that previously added with putExtra()
3457      * or null if no IBinder value was found.
3458      *
3459      * @see #putExtra(String, IBinder)
3460      *
3461      * @deprecated
3462      * @hide
3463      */
3464     @Deprecated
getIBinderExtra(String name)3465     public IBinder getIBinderExtra(String name) {
3466         return mExtras == null ? null : mExtras.getIBinder(name);
3467     }
3468 
3469     /**
3470      * Retrieve extended data from the intent.
3471      *
3472      * @param name The name of the desired item.
3473      * @param defaultValue The default value to return in case no item is
3474      * associated with the key 'name'
3475      *
3476      * @return the value of an item that previously added with putExtra()
3477      * or defaultValue if none was found.
3478      *
3479      * @see #putExtra
3480      *
3481      * @deprecated
3482      * @hide
3483      */
3484     @Deprecated
getExtra(String name, Object defaultValue)3485     public Object getExtra(String name, Object defaultValue) {
3486         Object result = defaultValue;
3487         if (mExtras != null) {
3488             Object result2 = mExtras.get(name);
3489             if (result2 != null) {
3490                 result = result2;
3491             }
3492         }
3493 
3494         return result;
3495     }
3496 
3497     /**
3498      * Retrieves a map of extended data from the intent.
3499      *
3500      * @return the map of all extras previously added with putExtra(),
3501      * or null if none have been added.
3502      */
getExtras()3503     public Bundle getExtras() {
3504         return (mExtras != null)
3505                 ? new Bundle(mExtras)
3506                 : null;
3507     }
3508 
3509     /**
3510      * Retrieve any special flags associated with this intent.  You will
3511      * normally just set them with {@link #setFlags} and let the system
3512      * take the appropriate action with them.
3513      *
3514      * @return int The currently set flags.
3515      *
3516      * @see #setFlags
3517      */
getFlags()3518     public int getFlags() {
3519         return mFlags;
3520     }
3521 
3522     /**
3523      * Retrieve the application package name this Intent is limited to.  When
3524      * resolving an Intent, if non-null this limits the resolution to only
3525      * components in the given application package.
3526      *
3527      * @return The name of the application package for the Intent.
3528      *
3529      * @see #resolveActivity
3530      * @see #setPackage
3531      */
getPackage()3532     public String getPackage() {
3533         return mPackage;
3534     }
3535 
3536     /**
3537      * Retrieve the concrete component associated with the intent.  When receiving
3538      * an intent, this is the component that was found to best handle it (that is,
3539      * yourself) and will always be non-null; in all other cases it will be
3540      * null unless explicitly set.
3541      *
3542      * @return The name of the application component to handle the intent.
3543      *
3544      * @see #resolveActivity
3545      * @see #setComponent
3546      */
getComponent()3547     public ComponentName getComponent() {
3548         return mComponent;
3549     }
3550 
3551     /**
3552      * Return the Activity component that should be used to handle this intent.
3553      * The appropriate component is determined based on the information in the
3554      * intent, evaluated as follows:
3555      *
3556      * <p>If {@link #getComponent} returns an explicit class, that is returned
3557      * without any further consideration.
3558      *
3559      * <p>The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent
3560      * category to be considered.
3561      *
3562      * <p>If {@link #getAction} is non-NULL, the activity must handle this
3563      * action.
3564      *
3565      * <p>If {@link #resolveType} returns non-NULL, the activity must handle
3566      * this type.
3567      *
3568      * <p>If {@link #addCategory} has added any categories, the activity must
3569      * handle ALL of the categories specified.
3570      *
3571      * <p>If {@link #getPackage} is non-NULL, only activity components in
3572      * that application package will be considered.
3573      *
3574      * <p>If there are no activities that satisfy all of these conditions, a
3575      * null string is returned.
3576      *
3577      * <p>If multiple activities are found to satisfy the intent, the one with
3578      * the highest priority will be used.  If there are multiple activities
3579      * with the same priority, the system will either pick the best activity
3580      * based on user preference, or resolve to a system class that will allow
3581      * the user to pick an activity and forward from there.
3582      *
3583      * <p>This method is implemented simply by calling
3584      * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter
3585      * true.</p>
3586      * <p> This API is called for you as part of starting an activity from an
3587      * intent.  You do not normally need to call it yourself.</p>
3588      *
3589      * @param pm The package manager with which to resolve the Intent.
3590      *
3591      * @return Name of the component implementing an activity that can
3592      *         display the intent.
3593      *
3594      * @see #setComponent
3595      * @see #getComponent
3596      * @see #resolveActivityInfo
3597      */
resolveActivity(PackageManager pm)3598     public ComponentName resolveActivity(PackageManager pm) {
3599         if (mComponent != null) {
3600             return mComponent;
3601         }
3602 
3603         ResolveInfo info = pm.resolveActivity(
3604             this, PackageManager.MATCH_DEFAULT_ONLY);
3605         if (info != null) {
3606             return new ComponentName(
3607                     info.activityInfo.applicationInfo.packageName,
3608                     info.activityInfo.name);
3609         }
3610 
3611         return null;
3612     }
3613 
3614     /**
3615      * Resolve the Intent into an {@link ActivityInfo}
3616      * describing the activity that should execute the intent.  Resolution
3617      * follows the same rules as described for {@link #resolveActivity}, but
3618      * you get back the completely information about the resolved activity
3619      * instead of just its class name.
3620      *
3621      * @param pm The package manager with which to resolve the Intent.
3622      * @param flags Addition information to retrieve as per
3623      * {@link PackageManager#getActivityInfo(ComponentName, int)
3624      * PackageManager.getActivityInfo()}.
3625      *
3626      * @return PackageManager.ActivityInfo
3627      *
3628      * @see #resolveActivity
3629      */
resolveActivityInfo(PackageManager pm, int flags)3630     public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) {
3631         ActivityInfo ai = null;
3632         if (mComponent != null) {
3633             try {
3634                 ai = pm.getActivityInfo(mComponent, flags);
3635             } catch (PackageManager.NameNotFoundException e) {
3636                 // ignore
3637             }
3638         } else {
3639             ResolveInfo info = pm.resolveActivity(
3640                 this, PackageManager.MATCH_DEFAULT_ONLY | flags);
3641             if (info != null) {
3642                 ai = info.activityInfo;
3643             }
3644         }
3645 
3646         return ai;
3647     }
3648 
3649     /**
3650      * Set the general action to be performed.
3651      *
3652      * @param action An action name, such as ACTION_VIEW.  Application-specific
3653      *               actions should be prefixed with the vendor's package name.
3654      *
3655      * @return Returns the same Intent object, for chaining multiple calls
3656      * into a single statement.
3657      *
3658      * @see #getAction
3659      */
setAction(String action)3660     public Intent setAction(String action) {
3661         mAction = action;
3662         return this;
3663     }
3664 
3665     /**
3666      * Set the data this intent is operating on.  This method automatically
3667      * clears any type that was previously set by {@link #setType}.
3668      *
3669      * <p><em>Note: scheme and host name matching in the Android framework is
3670      * case-sensitive, unlike the formal RFC.  As a result,
3671      * you should always ensure that you write your Uri with these elements
3672      * using lower case letters, and normalize any Uris you receive from
3673      * outside of Android to ensure the scheme and host is lower case.</em></p>
3674      *
3675      * @param data The URI of the data this intent is now targeting.
3676      *
3677      * @return Returns the same Intent object, for chaining multiple calls
3678      * into a single statement.
3679      *
3680      * @see #getData
3681      * @see #setType
3682      * @see #setDataAndType
3683      */
setData(Uri data)3684     public Intent setData(Uri data) {
3685         mData = data;
3686         mType = null;
3687         return this;
3688     }
3689 
3690     /**
3691      * Set an explicit MIME data type.  This is used to create intents that
3692      * only specify a type and not data, for example to indicate the type of
3693      * data to return.  This method automatically clears any data that was
3694      * previously set by {@link #setData}.
3695      *
3696      * <p><em>Note: MIME type matching in the Android framework is
3697      * case-sensitive, unlike formal RFC MIME types.  As a result,
3698      * you should always write your MIME types with lower case letters,
3699      * and any MIME types you receive from outside of Android should be
3700      * converted to lower case before supplying them here.</em></p>
3701      *
3702      * @param type The MIME type of the data being handled by this intent.
3703      *
3704      * @return Returns the same Intent object, for chaining multiple calls
3705      * into a single statement.
3706      *
3707      * @see #getType
3708      * @see #setData
3709      * @see #setDataAndType
3710      */
setType(String type)3711     public Intent setType(String type) {
3712         mData = null;
3713         mType = type;
3714         return this;
3715     }
3716 
3717     /**
3718      * (Usually optional) Set the data for the intent along with an explicit
3719      * MIME data type.  This method should very rarely be used -- it allows you
3720      * to override the MIME type that would ordinarily be inferred from the
3721      * data with your own type given here.
3722      *
3723      * <p><em>Note: MIME type, Uri scheme, and host name matching in the
3724      * Android framework is case-sensitive, unlike the formal RFC definitions.
3725      * As a result, you should always write these elements with lower case letters,
3726      * and normalize any MIME types or Uris you receive from
3727      * outside of Android to ensure these elements are lower case before
3728      * supplying them here.</em></p>
3729      *
3730      * @param data The URI of the data this intent is now targeting.
3731      * @param type The MIME type of the data being handled by this intent.
3732      *
3733      * @return Returns the same Intent object, for chaining multiple calls
3734      * into a single statement.
3735      *
3736      * @see #setData
3737      * @see #setType
3738      */
setDataAndType(Uri data, String type)3739     public Intent setDataAndType(Uri data, String type) {
3740         mData = data;
3741         mType = type;
3742         return this;
3743     }
3744 
3745     /**
3746      * Add a new category to the intent.  Categories provide additional detail
3747      * about the action the intent is perform.  When resolving an intent, only
3748      * activities that provide <em>all</em> of the requested categories will be
3749      * used.
3750      *
3751      * @param category The desired category.  This can be either one of the
3752      *               predefined Intent categories, or a custom category in your own
3753      *               namespace.
3754      *
3755      * @return Returns the same Intent object, for chaining multiple calls
3756      * into a single statement.
3757      *
3758      * @see #hasCategory
3759      * @see #removeCategory
3760      */
addCategory(String category)3761     public Intent addCategory(String category) {
3762         if (mCategories == null) {
3763             mCategories = new HashSet<String>();
3764         }
3765         mCategories.add(category);
3766         return this;
3767     }
3768 
3769     /**
3770      * Remove an category from an intent.
3771      *
3772      * @param category The category to remove.
3773      *
3774      * @see #addCategory
3775      */
removeCategory(String category)3776     public void removeCategory(String category) {
3777         if (mCategories != null) {
3778             mCategories.remove(category);
3779             if (mCategories.size() == 0) {
3780                 mCategories = null;
3781             }
3782         }
3783     }
3784 
3785     /**
3786      * Add extended data to the intent.  The name must include a package
3787      * prefix, for example the app com.android.contacts would use names
3788      * like "com.android.contacts.ShowAll".
3789      *
3790      * @param name The name of the extra data, with package prefix.
3791      * @param value The boolean data value.
3792      *
3793      * @return Returns the same Intent object, for chaining multiple calls
3794      * into a single statement.
3795      *
3796      * @see #putExtras
3797      * @see #removeExtra
3798      * @see #getBooleanExtra(String, boolean)
3799      */
putExtra(String name, boolean value)3800     public Intent putExtra(String name, boolean value) {
3801         if (mExtras == null) {
3802             mExtras = new Bundle();
3803         }
3804         mExtras.putBoolean(name, value);
3805         return this;
3806     }
3807 
3808     /**
3809      * Add extended data to the intent.  The name must include a package
3810      * prefix, for example the app com.android.contacts would use names
3811      * like "com.android.contacts.ShowAll".
3812      *
3813      * @param name The name of the extra data, with package prefix.
3814      * @param value The byte data value.
3815      *
3816      * @return Returns the same Intent object, for chaining multiple calls
3817      * into a single statement.
3818      *
3819      * @see #putExtras
3820      * @see #removeExtra
3821      * @see #getByteExtra(String, byte)
3822      */
putExtra(String name, byte value)3823     public Intent putExtra(String name, byte value) {
3824         if (mExtras == null) {
3825             mExtras = new Bundle();
3826         }
3827         mExtras.putByte(name, value);
3828         return this;
3829     }
3830 
3831     /**
3832      * Add extended data to the intent.  The name must include a package
3833      * prefix, for example the app com.android.contacts would use names
3834      * like "com.android.contacts.ShowAll".
3835      *
3836      * @param name The name of the extra data, with package prefix.
3837      * @param value The char data value.
3838      *
3839      * @return Returns the same Intent object, for chaining multiple calls
3840      * into a single statement.
3841      *
3842      * @see #putExtras
3843      * @see #removeExtra
3844      * @see #getCharExtra(String, char)
3845      */
putExtra(String name, char value)3846     public Intent putExtra(String name, char value) {
3847         if (mExtras == null) {
3848             mExtras = new Bundle();
3849         }
3850         mExtras.putChar(name, value);
3851         return this;
3852     }
3853 
3854     /**
3855      * Add extended data to the intent.  The name must include a package
3856      * prefix, for example the app com.android.contacts would use names
3857      * like "com.android.contacts.ShowAll".
3858      *
3859      * @param name The name of the extra data, with package prefix.
3860      * @param value The short data value.
3861      *
3862      * @return Returns the same Intent object, for chaining multiple calls
3863      * into a single statement.
3864      *
3865      * @see #putExtras
3866      * @see #removeExtra
3867      * @see #getShortExtra(String, short)
3868      */
putExtra(String name, short value)3869     public Intent putExtra(String name, short value) {
3870         if (mExtras == null) {
3871             mExtras = new Bundle();
3872         }
3873         mExtras.putShort(name, value);
3874         return this;
3875     }
3876 
3877     /**
3878      * Add extended data to the intent.  The name must include a package
3879      * prefix, for example the app com.android.contacts would use names
3880      * like "com.android.contacts.ShowAll".
3881      *
3882      * @param name The name of the extra data, with package prefix.
3883      * @param value The integer data value.
3884      *
3885      * @return Returns the same Intent object, for chaining multiple calls
3886      * into a single statement.
3887      *
3888      * @see #putExtras
3889      * @see #removeExtra
3890      * @see #getIntExtra(String, int)
3891      */
putExtra(String name, int value)3892     public Intent putExtra(String name, int value) {
3893         if (mExtras == null) {
3894             mExtras = new Bundle();
3895         }
3896         mExtras.putInt(name, value);
3897         return this;
3898     }
3899 
3900     /**
3901      * Add extended data to the intent.  The name must include a package
3902      * prefix, for example the app com.android.contacts would use names
3903      * like "com.android.contacts.ShowAll".
3904      *
3905      * @param name The name of the extra data, with package prefix.
3906      * @param value The long data value.
3907      *
3908      * @return Returns the same Intent object, for chaining multiple calls
3909      * into a single statement.
3910      *
3911      * @see #putExtras
3912      * @see #removeExtra
3913      * @see #getLongExtra(String, long)
3914      */
putExtra(String name, long value)3915     public Intent putExtra(String name, long value) {
3916         if (mExtras == null) {
3917             mExtras = new Bundle();
3918         }
3919         mExtras.putLong(name, value);
3920         return this;
3921     }
3922 
3923     /**
3924      * Add extended data to the intent.  The name must include a package
3925      * prefix, for example the app com.android.contacts would use names
3926      * like "com.android.contacts.ShowAll".
3927      *
3928      * @param name The name of the extra data, with package prefix.
3929      * @param value The float data value.
3930      *
3931      * @return Returns the same Intent object, for chaining multiple calls
3932      * into a single statement.
3933      *
3934      * @see #putExtras
3935      * @see #removeExtra
3936      * @see #getFloatExtra(String, float)
3937      */
putExtra(String name, float value)3938     public Intent putExtra(String name, float value) {
3939         if (mExtras == null) {
3940             mExtras = new Bundle();
3941         }
3942         mExtras.putFloat(name, value);
3943         return this;
3944     }
3945 
3946     /**
3947      * Add extended data to the intent.  The name must include a package
3948      * prefix, for example the app com.android.contacts would use names
3949      * like "com.android.contacts.ShowAll".
3950      *
3951      * @param name The name of the extra data, with package prefix.
3952      * @param value The double data value.
3953      *
3954      * @return Returns the same Intent object, for chaining multiple calls
3955      * into a single statement.
3956      *
3957      * @see #putExtras
3958      * @see #removeExtra
3959      * @see #getDoubleExtra(String, double)
3960      */
putExtra(String name, double value)3961     public Intent putExtra(String name, double value) {
3962         if (mExtras == null) {
3963             mExtras = new Bundle();
3964         }
3965         mExtras.putDouble(name, value);
3966         return this;
3967     }
3968 
3969     /**
3970      * Add extended data to the intent.  The name must include a package
3971      * prefix, for example the app com.android.contacts would use names
3972      * like "com.android.contacts.ShowAll".
3973      *
3974      * @param name The name of the extra data, with package prefix.
3975      * @param value The String data value.
3976      *
3977      * @return Returns the same Intent object, for chaining multiple calls
3978      * into a single statement.
3979      *
3980      * @see #putExtras
3981      * @see #removeExtra
3982      * @see #getStringExtra(String)
3983      */
putExtra(String name, String value)3984     public Intent putExtra(String name, String value) {
3985         if (mExtras == null) {
3986             mExtras = new Bundle();
3987         }
3988         mExtras.putString(name, value);
3989         return this;
3990     }
3991 
3992     /**
3993      * Add extended data to the intent.  The name must include a package
3994      * prefix, for example the app com.android.contacts would use names
3995      * like "com.android.contacts.ShowAll".
3996      *
3997      * @param name The name of the extra data, with package prefix.
3998      * @param value The CharSequence data value.
3999      *
4000      * @return Returns the same Intent object, for chaining multiple calls
4001      * into a single statement.
4002      *
4003      * @see #putExtras
4004      * @see #removeExtra
4005      * @see #getCharSequenceExtra(String)
4006      */
putExtra(String name, CharSequence value)4007     public Intent putExtra(String name, CharSequence value) {
4008         if (mExtras == null) {
4009             mExtras = new Bundle();
4010         }
4011         mExtras.putCharSequence(name, value);
4012         return this;
4013     }
4014 
4015     /**
4016      * Add extended data to the intent.  The name must include a package
4017      * prefix, for example the app com.android.contacts would use names
4018      * like "com.android.contacts.ShowAll".
4019      *
4020      * @param name The name of the extra data, with package prefix.
4021      * @param value The Parcelable data value.
4022      *
4023      * @return Returns the same Intent object, for chaining multiple calls
4024      * into a single statement.
4025      *
4026      * @see #putExtras
4027      * @see #removeExtra
4028      * @see #getParcelableExtra(String)
4029      */
putExtra(String name, Parcelable value)4030     public Intent putExtra(String name, Parcelable value) {
4031         if (mExtras == null) {
4032             mExtras = new Bundle();
4033         }
4034         mExtras.putParcelable(name, value);
4035         return this;
4036     }
4037 
4038     /**
4039      * Add extended data to the intent.  The name must include a package
4040      * prefix, for example the app com.android.contacts would use names
4041      * like "com.android.contacts.ShowAll".
4042      *
4043      * @param name The name of the extra data, with package prefix.
4044      * @param value The Parcelable[] data value.
4045      *
4046      * @return Returns the same Intent object, for chaining multiple calls
4047      * into a single statement.
4048      *
4049      * @see #putExtras
4050      * @see #removeExtra
4051      * @see #getParcelableArrayExtra(String)
4052      */
putExtra(String name, Parcelable[] value)4053     public Intent putExtra(String name, Parcelable[] value) {
4054         if (mExtras == null) {
4055             mExtras = new Bundle();
4056         }
4057         mExtras.putParcelableArray(name, value);
4058         return this;
4059     }
4060 
4061     /**
4062      * Add extended data to the intent.  The name must include a package
4063      * prefix, for example the app com.android.contacts would use names
4064      * like "com.android.contacts.ShowAll".
4065      *
4066      * @param name The name of the extra data, with package prefix.
4067      * @param value The ArrayList<Parcelable> data value.
4068      *
4069      * @return Returns the same Intent object, for chaining multiple calls
4070      * into a single statement.
4071      *
4072      * @see #putExtras
4073      * @see #removeExtra
4074      * @see #getParcelableArrayListExtra(String)
4075      */
putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)4076     public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
4077         if (mExtras == null) {
4078             mExtras = new Bundle();
4079         }
4080         mExtras.putParcelableArrayList(name, value);
4081         return this;
4082     }
4083 
4084     /**
4085      * Add extended data to the intent.  The name must include a package
4086      * prefix, for example the app com.android.contacts would use names
4087      * like "com.android.contacts.ShowAll".
4088      *
4089      * @param name The name of the extra data, with package prefix.
4090      * @param value The ArrayList<Integer> data value.
4091      *
4092      * @return Returns the same Intent object, for chaining multiple calls
4093      * into a single statement.
4094      *
4095      * @see #putExtras
4096      * @see #removeExtra
4097      * @see #getIntegerArrayListExtra(String)
4098      */
putIntegerArrayListExtra(String name, ArrayList<Integer> value)4099     public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
4100         if (mExtras == null) {
4101             mExtras = new Bundle();
4102         }
4103         mExtras.putIntegerArrayList(name, value);
4104         return this;
4105     }
4106 
4107     /**
4108      * Add extended data to the intent.  The name must include a package
4109      * prefix, for example the app com.android.contacts would use names
4110      * like "com.android.contacts.ShowAll".
4111      *
4112      * @param name The name of the extra data, with package prefix.
4113      * @param value The ArrayList<String> data value.
4114      *
4115      * @return Returns the same Intent object, for chaining multiple calls
4116      * into a single statement.
4117      *
4118      * @see #putExtras
4119      * @see #removeExtra
4120      * @see #getStringArrayListExtra(String)
4121      */
putStringArrayListExtra(String name, ArrayList<String> value)4122     public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
4123         if (mExtras == null) {
4124             mExtras = new Bundle();
4125         }
4126         mExtras.putStringArrayList(name, value);
4127         return this;
4128     }
4129 
4130     /**
4131      * Add extended data to the intent.  The name must include a package
4132      * prefix, for example the app com.android.contacts would use names
4133      * like "com.android.contacts.ShowAll".
4134      *
4135      * @param name The name of the extra data, with package prefix.
4136      * @param value The Serializable data value.
4137      *
4138      * @return Returns the same Intent object, for chaining multiple calls
4139      * into a single statement.
4140      *
4141      * @see #putExtras
4142      * @see #removeExtra
4143      * @see #getSerializableExtra(String)
4144      */
putExtra(String name, Serializable value)4145     public Intent putExtra(String name, Serializable value) {
4146         if (mExtras == null) {
4147             mExtras = new Bundle();
4148         }
4149         mExtras.putSerializable(name, value);
4150         return this;
4151     }
4152 
4153     /**
4154      * Add extended data to the intent.  The name must include a package
4155      * prefix, for example the app com.android.contacts would use names
4156      * like "com.android.contacts.ShowAll".
4157      *
4158      * @param name The name of the extra data, with package prefix.
4159      * @param value The boolean array data value.
4160      *
4161      * @return Returns the same Intent object, for chaining multiple calls
4162      * into a single statement.
4163      *
4164      * @see #putExtras
4165      * @see #removeExtra
4166      * @see #getBooleanArrayExtra(String)
4167      */
putExtra(String name, boolean[] value)4168     public Intent putExtra(String name, boolean[] value) {
4169         if (mExtras == null) {
4170             mExtras = new Bundle();
4171         }
4172         mExtras.putBooleanArray(name, value);
4173         return this;
4174     }
4175 
4176     /**
4177      * Add extended data to the intent.  The name must include a package
4178      * prefix, for example the app com.android.contacts would use names
4179      * like "com.android.contacts.ShowAll".
4180      *
4181      * @param name The name of the extra data, with package prefix.
4182      * @param value The byte array data value.
4183      *
4184      * @return Returns the same Intent object, for chaining multiple calls
4185      * into a single statement.
4186      *
4187      * @see #putExtras
4188      * @see #removeExtra
4189      * @see #getByteArrayExtra(String)
4190      */
putExtra(String name, byte[] value)4191     public Intent putExtra(String name, byte[] value) {
4192         if (mExtras == null) {
4193             mExtras = new Bundle();
4194         }
4195         mExtras.putByteArray(name, value);
4196         return this;
4197     }
4198 
4199     /**
4200      * Add extended data to the intent.  The name must include a package
4201      * prefix, for example the app com.android.contacts would use names
4202      * like "com.android.contacts.ShowAll".
4203      *
4204      * @param name The name of the extra data, with package prefix.
4205      * @param value The short array data value.
4206      *
4207      * @return Returns the same Intent object, for chaining multiple calls
4208      * into a single statement.
4209      *
4210      * @see #putExtras
4211      * @see #removeExtra
4212      * @see #getShortArrayExtra(String)
4213      */
putExtra(String name, short[] value)4214     public Intent putExtra(String name, short[] value) {
4215         if (mExtras == null) {
4216             mExtras = new Bundle();
4217         }
4218         mExtras.putShortArray(name, value);
4219         return this;
4220     }
4221 
4222     /**
4223      * Add extended data to the intent.  The name must include a package
4224      * prefix, for example the app com.android.contacts would use names
4225      * like "com.android.contacts.ShowAll".
4226      *
4227      * @param name The name of the extra data, with package prefix.
4228      * @param value The char array data value.
4229      *
4230      * @return Returns the same Intent object, for chaining multiple calls
4231      * into a single statement.
4232      *
4233      * @see #putExtras
4234      * @see #removeExtra
4235      * @see #getCharArrayExtra(String)
4236      */
putExtra(String name, char[] value)4237     public Intent putExtra(String name, char[] value) {
4238         if (mExtras == null) {
4239             mExtras = new Bundle();
4240         }
4241         mExtras.putCharArray(name, value);
4242         return this;
4243     }
4244 
4245     /**
4246      * Add extended data to the intent.  The name must include a package
4247      * prefix, for example the app com.android.contacts would use names
4248      * like "com.android.contacts.ShowAll".
4249      *
4250      * @param name The name of the extra data, with package prefix.
4251      * @param value The int array data value.
4252      *
4253      * @return Returns the same Intent object, for chaining multiple calls
4254      * into a single statement.
4255      *
4256      * @see #putExtras
4257      * @see #removeExtra
4258      * @see #getIntArrayExtra(String)
4259      */
putExtra(String name, int[] value)4260     public Intent putExtra(String name, int[] value) {
4261         if (mExtras == null) {
4262             mExtras = new Bundle();
4263         }
4264         mExtras.putIntArray(name, value);
4265         return this;
4266     }
4267 
4268     /**
4269      * Add extended data to the intent.  The name must include a package
4270      * prefix, for example the app com.android.contacts would use names
4271      * like "com.android.contacts.ShowAll".
4272      *
4273      * @param name The name of the extra data, with package prefix.
4274      * @param value The byte array data value.
4275      *
4276      * @return Returns the same Intent object, for chaining multiple calls
4277      * into a single statement.
4278      *
4279      * @see #putExtras
4280      * @see #removeExtra
4281      * @see #getLongArrayExtra(String)
4282      */
putExtra(String name, long[] value)4283     public Intent putExtra(String name, long[] value) {
4284         if (mExtras == null) {
4285             mExtras = new Bundle();
4286         }
4287         mExtras.putLongArray(name, value);
4288         return this;
4289     }
4290 
4291     /**
4292      * Add extended data to the intent.  The name must include a package
4293      * prefix, for example the app com.android.contacts would use names
4294      * like "com.android.contacts.ShowAll".
4295      *
4296      * @param name The name of the extra data, with package prefix.
4297      * @param value The float array data value.
4298      *
4299      * @return Returns the same Intent object, for chaining multiple calls
4300      * into a single statement.
4301      *
4302      * @see #putExtras
4303      * @see #removeExtra
4304      * @see #getFloatArrayExtra(String)
4305      */
putExtra(String name, float[] value)4306     public Intent putExtra(String name, float[] value) {
4307         if (mExtras == null) {
4308             mExtras = new Bundle();
4309         }
4310         mExtras.putFloatArray(name, value);
4311         return this;
4312     }
4313 
4314     /**
4315      * Add extended data to the intent.  The name must include a package
4316      * prefix, for example the app com.android.contacts would use names
4317      * like "com.android.contacts.ShowAll".
4318      *
4319      * @param name The name of the extra data, with package prefix.
4320      * @param value The double array data value.
4321      *
4322      * @return Returns the same Intent object, for chaining multiple calls
4323      * into a single statement.
4324      *
4325      * @see #putExtras
4326      * @see #removeExtra
4327      * @see #getDoubleArrayExtra(String)
4328      */
putExtra(String name, double[] value)4329     public Intent putExtra(String name, double[] value) {
4330         if (mExtras == null) {
4331             mExtras = new Bundle();
4332         }
4333         mExtras.putDoubleArray(name, value);
4334         return this;
4335     }
4336 
4337     /**
4338      * Add extended data to the intent.  The name must include a package
4339      * prefix, for example the app com.android.contacts would use names
4340      * like "com.android.contacts.ShowAll".
4341      *
4342      * @param name The name of the extra data, with package prefix.
4343      * @param value The String array data value.
4344      *
4345      * @return Returns the same Intent object, for chaining multiple calls
4346      * into a single statement.
4347      *
4348      * @see #putExtras
4349      * @see #removeExtra
4350      * @see #getStringArrayExtra(String)
4351      */
putExtra(String name, String[] value)4352     public Intent putExtra(String name, String[] value) {
4353         if (mExtras == null) {
4354             mExtras = new Bundle();
4355         }
4356         mExtras.putStringArray(name, value);
4357         return this;
4358     }
4359 
4360     /**
4361      * Add extended data to the intent.  The name must include a package
4362      * prefix, for example the app com.android.contacts would use names
4363      * like "com.android.contacts.ShowAll".
4364      *
4365      * @param name The name of the extra data, with package prefix.
4366      * @param value The Bundle data value.
4367      *
4368      * @return Returns the same Intent object, for chaining multiple calls
4369      * into a single statement.
4370      *
4371      * @see #putExtras
4372      * @see #removeExtra
4373      * @see #getBundleExtra(String)
4374      */
putExtra(String name, Bundle value)4375     public Intent putExtra(String name, Bundle value) {
4376         if (mExtras == null) {
4377             mExtras = new Bundle();
4378         }
4379         mExtras.putBundle(name, value);
4380         return this;
4381     }
4382 
4383     /**
4384      * Add extended data to the intent.  The name must include a package
4385      * prefix, for example the app com.android.contacts would use names
4386      * like "com.android.contacts.ShowAll".
4387      *
4388      * @param name The name of the extra data, with package prefix.
4389      * @param value The IBinder data value.
4390      *
4391      * @return Returns the same Intent object, for chaining multiple calls
4392      * into a single statement.
4393      *
4394      * @see #putExtras
4395      * @see #removeExtra
4396      * @see #getIBinderExtra(String)
4397      *
4398      * @deprecated
4399      * @hide
4400      */
4401     @Deprecated
putExtra(String name, IBinder value)4402     public Intent putExtra(String name, IBinder value) {
4403         if (mExtras == null) {
4404             mExtras = new Bundle();
4405         }
4406         mExtras.putIBinder(name, value);
4407         return this;
4408     }
4409 
4410     /**
4411      * Copy all extras in 'src' in to this intent.
4412      *
4413      * @param src Contains the extras to copy.
4414      *
4415      * @see #putExtra
4416      */
putExtras(Intent src)4417     public Intent putExtras(Intent src) {
4418         if (src.mExtras != null) {
4419             if (mExtras == null) {
4420                 mExtras = new Bundle(src.mExtras);
4421             } else {
4422                 mExtras.putAll(src.mExtras);
4423             }
4424         }
4425         return this;
4426     }
4427 
4428     /**
4429      * Add a set of extended data to the intent.  The keys must include a package
4430      * prefix, for example the app com.android.contacts would use names
4431      * like "com.android.contacts.ShowAll".
4432      *
4433      * @param extras The Bundle of extras to add to this intent.
4434      *
4435      * @see #putExtra
4436      * @see #removeExtra
4437      */
putExtras(Bundle extras)4438     public Intent putExtras(Bundle extras) {
4439         if (mExtras == null) {
4440             mExtras = new Bundle();
4441         }
4442         mExtras.putAll(extras);
4443         return this;
4444     }
4445 
4446     /**
4447      * Completely replace the extras in the Intent with the extras in the
4448      * given Intent.
4449      *
4450      * @param src The exact extras contained in this Intent are copied
4451      * into the target intent, replacing any that were previously there.
4452      */
replaceExtras(Intent src)4453     public Intent replaceExtras(Intent src) {
4454         mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null;
4455         return this;
4456     }
4457 
4458     /**
4459      * Completely replace the extras in the Intent with the given Bundle of
4460      * extras.
4461      *
4462      * @param extras The new set of extras in the Intent, or null to erase
4463      * all extras.
4464      */
replaceExtras(Bundle extras)4465     public Intent replaceExtras(Bundle extras) {
4466         mExtras = extras != null ? new Bundle(extras) : null;
4467         return this;
4468     }
4469 
4470     /**
4471      * Remove extended data from the intent.
4472      *
4473      * @see #putExtra
4474      */
removeExtra(String name)4475     public void removeExtra(String name) {
4476         if (mExtras != null) {
4477             mExtras.remove(name);
4478             if (mExtras.size() == 0) {
4479                 mExtras = null;
4480             }
4481         }
4482     }
4483 
4484     /**
4485      * Set special flags controlling how this intent is handled.  Most values
4486      * here depend on the type of component being executed by the Intent,
4487      * specifically the FLAG_ACTIVITY_* flags are all for use with
4488      * {@link Context#startActivity Context.startActivity()} and the
4489      * FLAG_RECEIVER_* flags are all for use with
4490      * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
4491      *
4492      * <p>See the <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
4493      * Activities and Tasks</a> documentation for important information on how some of these options impact
4494      * the behavior of your application.
4495      *
4496      * @param flags The desired flags.
4497      *
4498      * @return Returns the same Intent object, for chaining multiple calls
4499      * into a single statement.
4500      *
4501      * @see #getFlags
4502      * @see #addFlags
4503      *
4504      * @see #FLAG_GRANT_READ_URI_PERMISSION
4505      * @see #FLAG_GRANT_WRITE_URI_PERMISSION
4506      * @see #FLAG_DEBUG_LOG_RESOLUTION
4507      * @see #FLAG_FROM_BACKGROUND
4508      * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT
4509      * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
4510      * @see #FLAG_ACTIVITY_CLEAR_TOP
4511      * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
4512      * @see #FLAG_ACTIVITY_FORWARD_RESULT
4513      * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
4514      * @see #FLAG_ACTIVITY_MULTIPLE_TASK
4515      * @see #FLAG_ACTIVITY_NEW_TASK
4516      * @see #FLAG_ACTIVITY_NO_HISTORY
4517      * @see #FLAG_ACTIVITY_NO_USER_ACTION
4518      * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP
4519      * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
4520      * @see #FLAG_ACTIVITY_SINGLE_TOP
4521      * @see #FLAG_RECEIVER_REGISTERED_ONLY
4522      */
setFlags(int flags)4523     public Intent setFlags(int flags) {
4524         mFlags = flags;
4525         return this;
4526     }
4527 
4528     /**
4529      * Add additional flags to the intent (or with existing flags
4530      * value).
4531      *
4532      * @param flags The new flags to set.
4533      *
4534      * @return Returns the same Intent object, for chaining multiple calls
4535      * into a single statement.
4536      *
4537      * @see #setFlags
4538      */
addFlags(int flags)4539     public Intent addFlags(int flags) {
4540         mFlags |= flags;
4541         return this;
4542     }
4543 
4544     /**
4545      * (Usually optional) Set an explicit application package name that limits
4546      * the components this Intent will resolve to.  If left to the default
4547      * value of null, all components in all applications will considered.
4548      * If non-null, the Intent can only match the components in the given
4549      * application package.
4550      *
4551      * @param packageName The name of the application package to handle the
4552      * intent, or null to allow any application package.
4553      *
4554      * @return Returns the same Intent object, for chaining multiple calls
4555      * into a single statement.
4556      *
4557      * @see #getPackage
4558      * @see #resolveActivity
4559      */
setPackage(String packageName)4560     public Intent setPackage(String packageName) {
4561         mPackage = packageName;
4562         return this;
4563     }
4564 
4565     /**
4566      * (Usually optional) Explicitly set the component to handle the intent.
4567      * If left with the default value of null, the system will determine the
4568      * appropriate class to use based on the other fields (action, data,
4569      * type, categories) in the Intent.  If this class is defined, the
4570      * specified class will always be used regardless of the other fields.  You
4571      * should only set this value when you know you absolutely want a specific
4572      * class to be used; otherwise it is better to let the system find the
4573      * appropriate class so that you will respect the installed applications
4574      * and user preferences.
4575      *
4576      * @param component The name of the application component to handle the
4577      * intent, or null to let the system find one for you.
4578      *
4579      * @return Returns the same Intent object, for chaining multiple calls
4580      * into a single statement.
4581      *
4582      * @see #setClass
4583      * @see #setClassName(Context, String)
4584      * @see #setClassName(String, String)
4585      * @see #getComponent
4586      * @see #resolveActivity
4587      */
setComponent(ComponentName component)4588     public Intent setComponent(ComponentName component) {
4589         mComponent = component;
4590         return this;
4591     }
4592 
4593     /**
4594      * Convenience for calling {@link #setComponent} with an
4595      * explicit class name.
4596      *
4597      * @param packageContext A Context of the application package implementing
4598      * this class.
4599      * @param className The name of a class inside of the application package
4600      * that will be used as the component for this Intent.
4601      *
4602      * @return Returns the same Intent object, for chaining multiple calls
4603      * into a single statement.
4604      *
4605      * @see #setComponent
4606      * @see #setClass
4607      */
setClassName(Context packageContext, String className)4608     public Intent setClassName(Context packageContext, String className) {
4609         mComponent = new ComponentName(packageContext, className);
4610         return this;
4611     }
4612 
4613     /**
4614      * Convenience for calling {@link #setComponent} with an
4615      * explicit application package name and class name.
4616      *
4617      * @param packageName The name of the package implementing the desired
4618      * component.
4619      * @param className The name of a class inside of the application package
4620      * that will be used as the component for this Intent.
4621      *
4622      * @return Returns the same Intent object, for chaining multiple calls
4623      * into a single statement.
4624      *
4625      * @see #setComponent
4626      * @see #setClass
4627      */
setClassName(String packageName, String className)4628     public Intent setClassName(String packageName, String className) {
4629         mComponent = new ComponentName(packageName, className);
4630         return this;
4631     }
4632 
4633     /**
4634      * Convenience for calling {@link #setComponent(ComponentName)} with the
4635      * name returned by a {@link Class} object.
4636      *
4637      * @param packageContext A Context of the application package implementing
4638      * this class.
4639      * @param cls The class name to set, equivalent to
4640      *            <code>setClassName(context, cls.getName())</code>.
4641      *
4642      * @return Returns the same Intent object, for chaining multiple calls
4643      * into a single statement.
4644      *
4645      * @see #setComponent
4646      */
setClass(Context packageContext, Class<?> cls)4647     public Intent setClass(Context packageContext, Class<?> cls) {
4648         mComponent = new ComponentName(packageContext, cls);
4649         return this;
4650     }
4651 
4652     /**
4653      * Use with {@link #fillIn} to allow the current action value to be
4654      * overwritten, even if it is already set.
4655      */
4656     public static final int FILL_IN_ACTION = 1<<0;
4657 
4658     /**
4659      * Use with {@link #fillIn} to allow the current data or type value
4660      * overwritten, even if it is already set.
4661      */
4662     public static final int FILL_IN_DATA = 1<<1;
4663 
4664     /**
4665      * Use with {@link #fillIn} to allow the current categories to be
4666      * overwritten, even if they are already set.
4667      */
4668     public static final int FILL_IN_CATEGORIES = 1<<2;
4669 
4670     /**
4671      * Use with {@link #fillIn} to allow the current component value to be
4672      * overwritten, even if it is already set.
4673      */
4674     public static final int FILL_IN_COMPONENT = 1<<3;
4675 
4676     /**
4677      * Use with {@link #fillIn} to allow the current package value to be
4678      * overwritten, even if it is already set.
4679      */
4680     public static final int FILL_IN_PACKAGE = 1<<4;
4681 
4682     /**
4683      * Copy the contents of <var>other</var> in to this object, but only
4684      * where fields are not defined by this object.  For purposes of a field
4685      * being defined, the following pieces of data in the Intent are
4686      * considered to be separate fields:
4687      *
4688      * <ul>
4689      * <li> action, as set by {@link #setAction}.
4690      * <li> data URI and MIME type, as set by {@link #setData(Uri)},
4691      * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}.
4692      * <li> categories, as set by {@link #addCategory}.
4693      * <li> package, as set by {@link #setPackage}.
4694      * <li> component, as set by {@link #setComponent(ComponentName)} or
4695      * related methods.
4696      * <li> each top-level name in the associated extras.
4697      * </ul>
4698      *
4699      * <p>In addition, you can use the {@link #FILL_IN_ACTION},
4700      * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
4701      * and {@link #FILL_IN_COMPONENT} to override the restriction where the
4702      * corresponding field will not be replaced if it is already set.
4703      *
4704      * <p>Note: The component field will only be copied if {@link #FILL_IN_COMPONENT} is explicitly
4705      * specified.
4706      *
4707      * <p>For example, consider Intent A with {data="foo", categories="bar"}
4708      * and Intent B with {action="gotit", data-type="some/thing",
4709      * categories="one","two"}.
4710      *
4711      * <p>Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now
4712      * containing: {action="gotit", data-type="some/thing",
4713      * categories="bar"}.
4714      *
4715      * @param other Another Intent whose values are to be used to fill in
4716      * the current one.
4717      * @param flags Options to control which fields can be filled in.
4718      *
4719      * @return Returns a bit mask of {@link #FILL_IN_ACTION},
4720      * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
4721      * and {@link #FILL_IN_COMPONENT} indicating which fields were changed.
4722      */
fillIn(Intent other, int flags)4723     public int fillIn(Intent other, int flags) {
4724         int changes = 0;
4725         if (other.mAction != null
4726                 && (mAction == null || (flags&FILL_IN_ACTION) != 0)) {
4727             mAction = other.mAction;
4728             changes |= FILL_IN_ACTION;
4729         }
4730         if ((other.mData != null || other.mType != null)
4731                 && ((mData == null && mType == null)
4732                         || (flags&FILL_IN_DATA) != 0)) {
4733             mData = other.mData;
4734             mType = other.mType;
4735             changes |= FILL_IN_DATA;
4736         }
4737         if (other.mCategories != null
4738                 && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) {
4739             if (other.mCategories != null) {
4740                 mCategories = new HashSet<String>(other.mCategories);
4741             }
4742             changes |= FILL_IN_CATEGORIES;
4743         }
4744         if (other.mPackage != null
4745                 && (mPackage == null || (flags&FILL_IN_PACKAGE) != 0)) {
4746             mPackage = other.mPackage;
4747             changes |= FILL_IN_PACKAGE;
4748         }
4749         // Component is special: it can -only- be set if explicitly allowed,
4750         // since otherwise the sender could force the intent somewhere the
4751         // originator didn't intend.
4752         if (other.mComponent != null && (flags&FILL_IN_COMPONENT) != 0) {
4753             mComponent = other.mComponent;
4754             changes |= FILL_IN_COMPONENT;
4755         }
4756         mFlags |= other.mFlags;
4757         if (mExtras == null) {
4758             if (other.mExtras != null) {
4759                 mExtras = new Bundle(other.mExtras);
4760             }
4761         } else if (other.mExtras != null) {
4762             try {
4763                 Bundle newb = new Bundle(other.mExtras);
4764                 newb.putAll(mExtras);
4765                 mExtras = newb;
4766             } catch (RuntimeException e) {
4767                 // Modifying the extras can cause us to unparcel the contents
4768                 // of the bundle, and if we do this in the system process that
4769                 // may fail.  We really should handle this (i.e., the Bundle
4770                 // impl shouldn't be on top of a plain map), but for now just
4771                 // ignore it and keep the original contents. :(
4772                 Log.w("Intent", "Failure filling in extras", e);
4773             }
4774         }
4775         return changes;
4776     }
4777 
4778     /**
4779      * Wrapper class holding an Intent and implementing comparisons on it for
4780      * the purpose of filtering.  The class implements its
4781      * {@link #equals equals()} and {@link #hashCode hashCode()} methods as
4782      * simple calls to {@link Intent#filterEquals(Intent)}  filterEquals()} and
4783      * {@link android.content.Intent#filterHashCode()}  filterHashCode()}
4784      * on the wrapped Intent.
4785      */
4786     public static final class FilterComparison {
4787         private final Intent mIntent;
4788         private final int mHashCode;
4789 
FilterComparison(Intent intent)4790         public FilterComparison(Intent intent) {
4791             mIntent = intent;
4792             mHashCode = intent.filterHashCode();
4793         }
4794 
4795         /**
4796          * Return the Intent that this FilterComparison represents.
4797          * @return Returns the Intent held by the FilterComparison.  Do
4798          * not modify!
4799          */
getIntent()4800         public Intent getIntent() {
4801             return mIntent;
4802         }
4803 
4804         @Override
equals(Object obj)4805         public boolean equals(Object obj) {
4806             if (obj instanceof FilterComparison) {
4807                 Intent other = ((FilterComparison)obj).mIntent;
4808                 return mIntent.filterEquals(other);
4809             }
4810             return false;
4811         }
4812 
4813         @Override
hashCode()4814         public int hashCode() {
4815             return mHashCode;
4816         }
4817     }
4818 
4819     /**
4820      * Determine if two intents are the same for the purposes of intent
4821      * resolution (filtering). That is, if their action, data, type,
4822      * class, and categories are the same.  This does <em>not</em> compare
4823      * any extra data included in the intents.
4824      *
4825      * @param other The other Intent to compare against.
4826      *
4827      * @return Returns true if action, data, type, class, and categories
4828      *         are the same.
4829      */
filterEquals(Intent other)4830     public boolean filterEquals(Intent other) {
4831         if (other == null) {
4832             return false;
4833         }
4834         if (mAction != other.mAction) {
4835             if (mAction != null) {
4836                 if (!mAction.equals(other.mAction)) {
4837                     return false;
4838                 }
4839             } else {
4840                 if (!other.mAction.equals(mAction)) {
4841                     return false;
4842                 }
4843             }
4844         }
4845         if (mData != other.mData) {
4846             if (mData != null) {
4847                 if (!mData.equals(other.mData)) {
4848                     return false;
4849                 }
4850             } else {
4851                 if (!other.mData.equals(mData)) {
4852                     return false;
4853                 }
4854             }
4855         }
4856         if (mType != other.mType) {
4857             if (mType != null) {
4858                 if (!mType.equals(other.mType)) {
4859                     return false;
4860                 }
4861             } else {
4862                 if (!other.mType.equals(mType)) {
4863                     return false;
4864                 }
4865             }
4866         }
4867         if (mPackage != other.mPackage) {
4868             if (mPackage != null) {
4869                 if (!mPackage.equals(other.mPackage)) {
4870                     return false;
4871                 }
4872             } else {
4873                 if (!other.mPackage.equals(mPackage)) {
4874                     return false;
4875                 }
4876             }
4877         }
4878         if (mComponent != other.mComponent) {
4879             if (mComponent != null) {
4880                 if (!mComponent.equals(other.mComponent)) {
4881                     return false;
4882                 }
4883             } else {
4884                 if (!other.mComponent.equals(mComponent)) {
4885                     return false;
4886                 }
4887             }
4888         }
4889         if (mCategories != other.mCategories) {
4890             if (mCategories != null) {
4891                 if (!mCategories.equals(other.mCategories)) {
4892                     return false;
4893                 }
4894             } else {
4895                 if (!other.mCategories.equals(mCategories)) {
4896                     return false;
4897                 }
4898             }
4899         }
4900 
4901         return true;
4902     }
4903 
4904     /**
4905      * Generate hash code that matches semantics of filterEquals().
4906      *
4907      * @return Returns the hash value of the action, data, type, class, and
4908      *         categories.
4909      *
4910      * @see #filterEquals
4911      */
filterHashCode()4912     public int filterHashCode() {
4913         int code = 0;
4914         if (mAction != null) {
4915             code += mAction.hashCode();
4916         }
4917         if (mData != null) {
4918             code += mData.hashCode();
4919         }
4920         if (mType != null) {
4921             code += mType.hashCode();
4922         }
4923         if (mPackage != null) {
4924             code += mPackage.hashCode();
4925         }
4926         if (mComponent != null) {
4927             code += mComponent.hashCode();
4928         }
4929         if (mCategories != null) {
4930             code += mCategories.hashCode();
4931         }
4932         return code;
4933     }
4934 
4935     @Override
toString()4936     public String toString() {
4937         StringBuilder   b = new StringBuilder(128);
4938 
4939         b.append("Intent { ");
4940         toShortString(b, true, true);
4941         b.append(" }");
4942 
4943         return b.toString();
4944     }
4945 
4946     /** @hide */
toShortString(boolean comp, boolean extras)4947     public String toShortString(boolean comp, boolean extras) {
4948         StringBuilder   b = new StringBuilder(128);
4949         toShortString(b, comp, extras);
4950         return b.toString();
4951     }
4952 
4953     /** @hide */
toShortString(StringBuilder b, boolean comp, boolean extras)4954     public void toShortString(StringBuilder b, boolean comp, boolean extras) {
4955         boolean first = true;
4956         if (mAction != null) {
4957             b.append("act=").append(mAction);
4958             first = false;
4959         }
4960         if (mCategories != null) {
4961             if (!first) {
4962                 b.append(' ');
4963             }
4964             first = false;
4965             b.append("cat=[");
4966             Iterator<String> i = mCategories.iterator();
4967             boolean didone = false;
4968             while (i.hasNext()) {
4969                 if (didone) b.append(",");
4970                 didone = true;
4971                 b.append(i.next());
4972             }
4973             b.append("]");
4974         }
4975         if (mData != null) {
4976             if (!first) {
4977                 b.append(' ');
4978             }
4979             first = false;
4980             b.append("dat=").append(mData);
4981         }
4982         if (mType != null) {
4983             if (!first) {
4984                 b.append(' ');
4985             }
4986             first = false;
4987             b.append("typ=").append(mType);
4988         }
4989         if (mFlags != 0) {
4990             if (!first) {
4991                 b.append(' ');
4992             }
4993             first = false;
4994             b.append("flg=0x").append(Integer.toHexString(mFlags));
4995         }
4996         if (mPackage != null) {
4997             if (!first) {
4998                 b.append(' ');
4999             }
5000             first = false;
5001             b.append("pkg=").append(mPackage);
5002         }
5003         if (comp && mComponent != null) {
5004             if (!first) {
5005                 b.append(' ');
5006             }
5007             first = false;
5008             b.append("cmp=").append(mComponent.flattenToShortString());
5009         }
5010         if (extras && mExtras != null) {
5011             if (!first) {
5012                 b.append(' ');
5013             }
5014             first = false;
5015             b.append("(has extras)");
5016         }
5017     }
5018 
5019     /**
5020      * Call {@link #toUri} with 0 flags.
5021      * @deprecated Use {@link #toUri} instead.
5022      */
5023     @Deprecated
toURI()5024     public String toURI() {
5025         return toUri(0);
5026     }
5027 
5028     /**
5029      * Convert this Intent into a String holding a URI representation of it.
5030      * The returned URI string has been properly URI encoded, so it can be
5031      * used with {@link Uri#parse Uri.parse(String)}.  The URI contains the
5032      * Intent's data as the base URI, with an additional fragment describing
5033      * the action, categories, type, flags, package, component, and extras.
5034      *
5035      * <p>You can convert the returned string back to an Intent with
5036      * {@link #getIntent}.
5037      *
5038      * @param flags Additional operating flags.  Either 0 or
5039      * {@link #URI_INTENT_SCHEME}.
5040      *
5041      * @return Returns a URI encoding URI string describing the entire contents
5042      * of the Intent.
5043      */
toUri(int flags)5044     public String toUri(int flags) {
5045         StringBuilder uri = new StringBuilder(128);
5046         String scheme = null;
5047         if (mData != null) {
5048             String data = mData.toString();
5049             if ((flags&URI_INTENT_SCHEME) != 0) {
5050                 final int N = data.length();
5051                 for (int i=0; i<N; i++) {
5052                     char c = data.charAt(i);
5053                     if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
5054                             || c == '.' || c == '-') {
5055                         continue;
5056                     }
5057                     if (c == ':' && i > 0) {
5058                         // Valid scheme.
5059                         scheme = data.substring(0, i);
5060                         uri.append("intent:");
5061                         data = data.substring(i+1);
5062                         break;
5063                     }
5064 
5065                     // No scheme.
5066                     break;
5067                 }
5068             }
5069             uri.append(data);
5070 
5071         } else if ((flags&URI_INTENT_SCHEME) != 0) {
5072             uri.append("intent:");
5073         }
5074 
5075         uri.append("#Intent;");
5076 
5077         if (scheme != null) {
5078             uri.append("scheme=").append(scheme).append(';');
5079         }
5080         if (mAction != null) {
5081             uri.append("action=").append(Uri.encode(mAction)).append(';');
5082         }
5083         if (mCategories != null) {
5084             for (String category : mCategories) {
5085                 uri.append("category=").append(Uri.encode(category)).append(';');
5086             }
5087         }
5088         if (mType != null) {
5089             uri.append("type=").append(Uri.encode(mType, "/")).append(';');
5090         }
5091         if (mFlags != 0) {
5092             uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
5093         }
5094         if (mPackage != null) {
5095             uri.append("package=").append(Uri.encode(mPackage)).append(';');
5096         }
5097         if (mComponent != null) {
5098             uri.append("component=").append(Uri.encode(
5099                     mComponent.flattenToShortString(), "/")).append(';');
5100         }
5101         if (mExtras != null) {
5102             for (String key : mExtras.keySet()) {
5103                 final Object value = mExtras.get(key);
5104                 char entryType =
5105                         value instanceof String    ? 'S' :
5106                         value instanceof Boolean   ? 'B' :
5107                         value instanceof Byte      ? 'b' :
5108                         value instanceof Character ? 'c' :
5109                         value instanceof Double    ? 'd' :
5110                         value instanceof Float     ? 'f' :
5111                         value instanceof Integer   ? 'i' :
5112                         value instanceof Long      ? 'l' :
5113                         value instanceof Short     ? 's' :
5114                         '\0';
5115 
5116                 if (entryType != '\0') {
5117                     uri.append(entryType);
5118                     uri.append('.');
5119                     uri.append(Uri.encode(key));
5120                     uri.append('=');
5121                     uri.append(Uri.encode(value.toString()));
5122                     uri.append(';');
5123                 }
5124             }
5125         }
5126 
5127         uri.append("end");
5128 
5129         return uri.toString();
5130     }
5131 
describeContents()5132     public int describeContents() {
5133         return (mExtras != null) ? mExtras.describeContents() : 0;
5134     }
5135 
writeToParcel(Parcel out, int flags)5136     public void writeToParcel(Parcel out, int flags) {
5137         out.writeString(mAction);
5138         Uri.writeToParcel(out, mData);
5139         out.writeString(mType);
5140         out.writeInt(mFlags);
5141         out.writeString(mPackage);
5142         ComponentName.writeToParcel(mComponent, out);
5143 
5144         if (mCategories != null) {
5145             out.writeInt(mCategories.size());
5146             for (String category : mCategories) {
5147                 out.writeString(category);
5148             }
5149         } else {
5150             out.writeInt(0);
5151         }
5152 
5153         out.writeBundle(mExtras);
5154     }
5155 
5156     public static final Parcelable.Creator<Intent> CREATOR
5157             = new Parcelable.Creator<Intent>() {
5158         public Intent createFromParcel(Parcel in) {
5159             return new Intent(in);
5160         }
5161         public Intent[] newArray(int size) {
5162             return new Intent[size];
5163         }
5164     };
5165 
5166     /** @hide */
Intent(Parcel in)5167     protected Intent(Parcel in) {
5168         readFromParcel(in);
5169     }
5170 
readFromParcel(Parcel in)5171     public void readFromParcel(Parcel in) {
5172         mAction = in.readString();
5173         mData = Uri.CREATOR.createFromParcel(in);
5174         mType = in.readString();
5175         mFlags = in.readInt();
5176         mPackage = in.readString();
5177         mComponent = ComponentName.readFromParcel(in);
5178 
5179         int N = in.readInt();
5180         if (N > 0) {
5181             mCategories = new HashSet<String>();
5182             int i;
5183             for (i=0; i<N; i++) {
5184                 mCategories.add(in.readString());
5185             }
5186         } else {
5187             mCategories = null;
5188         }
5189 
5190         mExtras = in.readBundle();
5191     }
5192 
5193     /**
5194      * Parses the "intent" element (and its children) from XML and instantiates
5195      * an Intent object.  The given XML parser should be located at the tag
5196      * where parsing should start (often named "intent"), from which the
5197      * basic action, data, type, and package and class name will be
5198      * retrieved.  The function will then parse in to any child elements,
5199      * looking for <category android:name="xxx"> tags to add categories and
5200      * <extra android:name="xxx" android:value="yyy"> to attach extra data
5201      * to the intent.
5202      *
5203      * @param resources The Resources to use when inflating resources.
5204      * @param parser The XML parser pointing at an "intent" tag.
5205      * @param attrs The AttributeSet interface for retrieving extended
5206      * attribute data at the current <var>parser</var> location.
5207      * @return An Intent object matching the XML data.
5208      * @throws XmlPullParserException If there was an XML parsing error.
5209      * @throws IOException If there was an I/O error.
5210      */
parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)5211     public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
5212             throws XmlPullParserException, IOException {
5213         Intent intent = new Intent();
5214 
5215         TypedArray sa = resources.obtainAttributes(attrs,
5216                 com.android.internal.R.styleable.Intent);
5217 
5218         intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action));
5219 
5220         String data = sa.getString(com.android.internal.R.styleable.Intent_data);
5221         String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType);
5222         intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType);
5223 
5224         String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage);
5225         String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass);
5226         if (packageName != null && className != null) {
5227             intent.setComponent(new ComponentName(packageName, className));
5228         }
5229 
5230         sa.recycle();
5231 
5232         int outerDepth = parser.getDepth();
5233         int type;
5234         while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
5235                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
5236             if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
5237                 continue;
5238             }
5239 
5240             String nodeName = parser.getName();
5241             if (nodeName.equals("category")) {
5242                 sa = resources.obtainAttributes(attrs,
5243                         com.android.internal.R.styleable.IntentCategory);
5244                 String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name);
5245                 sa.recycle();
5246 
5247                 if (cat != null) {
5248                     intent.addCategory(cat);
5249                 }
5250                 XmlUtils.skipCurrentTag(parser);
5251 
5252             } else if (nodeName.equals("extra")) {
5253                 if (intent.mExtras == null) {
5254                     intent.mExtras = new Bundle();
5255                 }
5256                 resources.parseBundleExtra("extra", attrs, intent.mExtras);
5257                 XmlUtils.skipCurrentTag(parser);
5258 
5259             } else {
5260                 XmlUtils.skipCurrentTag(parser);
5261             }
5262         }
5263 
5264         return intent;
5265     }
5266 }
5267