blob: 824fd9b1f7523d7e1e6cde5692479aa3e2c63c27 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
19import org.xmlpull.v1.XmlPullParser;
20import org.xmlpull.v1.XmlPullParserException;
21
22import android.annotation.SdkConstant;
23import android.annotation.SdkConstant.SdkConstantType;
24import android.content.pm.ActivityInfo;
25import android.content.pm.PackageManager;
26import android.content.pm.ResolveInfo;
27import android.content.res.Resources;
28import android.content.res.TypedArray;
29import android.net.Uri;
30import android.os.Bundle;
31import android.os.IBinder;
32import android.os.Parcel;
33import android.os.Parcelable;
34import android.util.AttributeSet;
35import android.util.Log;
36import com.android.internal.util.XmlUtils;
37
38import java.io.IOException;
39import java.io.Serializable;
40import java.net.URISyntaxException;
41import java.util.ArrayList;
42import java.util.HashSet;
43import java.util.Iterator;
44import 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/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/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/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/</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.app.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:value="android.intent.action.MAIN" /&gt;
244 * &lt;category android:value="android.intent.category.LAUNCHER" /&gt;
245 * &lt;/intent-filter&gt;
246 * &lt;intent-filter&gt;
247 * &lt;action android:value="android.intent.action.VIEW" /&gt;
248 * &lt;action android:value="android.intent.action.EDIT" /&gt;
249 * &lt;action android:value="android.intent.action.PICK" /&gt;
250 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
251 * &lt;type android:value="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
252 * &lt;/intent-filter&gt;
253 * &lt;intent-filter&gt;
254 * &lt;action android:value="android.intent.action.GET_CONTENT" /&gt;
255 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
256 * &lt;type android:value="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:value="android.intent.action.VIEW" /&gt;
263 * &lt;action android:value="android.intent.action.EDIT" /&gt;
264 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
265 * &lt;type android:value="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:value="android.intent.action.INSERT" /&gt;
270 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
271 * &lt;type android:value="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:value="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
280 * &lt;category android:value="android.intent.category.DEFAULT" /&gt;
281 * &lt;category android:value="android.intent.category.ALTERNATIVE" /&gt;
282 * &lt;category android:value="android.intent.category.SELECTED_ALTERNATIVE" /&gt;
283 * &lt;type android:value="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:value="{@link #ACTION_MAIN android.intent.action.MAIN}" /&gt;
298 * &lt;category android:value="{@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:value="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
307 * &lt;action android:value="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
308 * &lt;action android:value="{@link #ACTION_PICK android.intent.action.PICK}" /&gt;
309 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
310 * &lt;type android:value="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:value="{@link #ACTION_GET_CONTENT android.intent.action.GET_CONTENT}" /&gt;
326 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
327 * &lt;type android:value="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.app.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:value="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
375 * &lt;action android:value="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
376 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
377 * &lt;type android:value="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:value="{@link #ACTION_INSERT android.intent.action.INSERT}" /&gt;
388 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
389 * &lt;type android:value="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.app.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:value="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
426 * &lt;category android:value="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
427 * &lt;category android:value="{@link #CATEGORY_ALTERNATIVE android.intent.category.ALTERNATIVE}" /&gt;
428 * &lt;category android:value="{@link #CATEGORY_SELECTED_ALTERNATIVE android.intent.category.SELECTED_ALTERNATIVE}" /&gt;
429 * &lt;type android:value="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 * </ul>
512 *
513 * <h3>Standard Categories</h3>
514 *
515 * <p>These are the current standard categories that can be used to further
516 * clarify an Intent via {@link #addCategory}.
517 *
518 * <ul>
519 * <li> {@link #CATEGORY_DEFAULT}
520 * <li> {@link #CATEGORY_BROWSABLE}
521 * <li> {@link #CATEGORY_TAB}
522 * <li> {@link #CATEGORY_ALTERNATIVE}
523 * <li> {@link #CATEGORY_SELECTED_ALTERNATIVE}
524 * <li> {@link #CATEGORY_LAUNCHER}
525 * <li> {@link #CATEGORY_INFO}
526 * <li> {@link #CATEGORY_HOME}
527 * <li> {@link #CATEGORY_PREFERENCE}
528 * <li> {@link #CATEGORY_GADGET}
529 * <li> {@link #CATEGORY_TEST}
530 * </ul>
531 *
532 * <h3>Standard Extra Data</h3>
533 *
534 * <p>These are the current standard fields that can be used as extra data via
535 * {@link #putExtra}.
536 *
537 * <ul>
538 * <li> {@link #EXTRA_TEMPLATE}
539 * <li> {@link #EXTRA_INTENT}
540 * <li> {@link #EXTRA_STREAM}
541 * <li> {@link #EXTRA_TEXT}
542 * </ul>
543 *
544 * <h3>Flags</h3>
545 *
546 * <p>These are the possible flags that can be used in the Intent via
547 * {@link #setFlags} and {@link #addFlags}. See {@link #setFlags} for a list
548 * of all possible flags.
549 */
550public class Intent implements Parcelable {
551 // ---------------------------------------------------------------------
552 // ---------------------------------------------------------------------
553 // Standard intent activity actions (see action variable).
554
555 /**
556 * Activity Action: Start as a main entry point, does not expect to
557 * receive data.
558 * <p>Input: nothing
559 * <p>Output: nothing
560 */
561 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
562 public static final String ACTION_MAIN = "android.intent.action.MAIN";
563
564 /**
565 * Activity Action: Display the data to the user. This is the most common
566 * action performed on data -- it is the generic action you can use on
567 * a piece of data to get the most reasonable thing to occur. For example,
568 * when used on a contacts entry it will view the entry; when used on a
569 * mailto: URI it will bring up a compose window filled with the information
570 * supplied by the URI; when used with a tel: URI it will invoke the
571 * dialer.
572 * <p>Input: {@link #getData} is URI from which to retrieve data.
573 * <p>Output: nothing.
574 */
575 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
576 public static final String ACTION_VIEW = "android.intent.action.VIEW";
577
578 /**
579 * A synonym for {@link #ACTION_VIEW}, the "standard" action that is
580 * performed on a piece of data.
581 */
582 public static final String ACTION_DEFAULT = ACTION_VIEW;
583
584 /**
585 * Used to indicate that some piece of data should be attached to some other
586 * place. For example, image data could be attached to a contact. It is up
587 * to the recipient to decide where the data should be attached; the intent
588 * does not specify the ultimate destination.
589 * <p>Input: {@link #getData} is URI of data to be attached.
590 * <p>Output: nothing.
591 */
592 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
593 public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
594
595 /**
596 * Activity Action: Provide explicit editable access to the given data.
597 * <p>Input: {@link #getData} is URI of data to be edited.
598 * <p>Output: nothing.
599 */
600 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
601 public static final String ACTION_EDIT = "android.intent.action.EDIT";
602
603 /**
604 * Activity Action: Pick an existing item, or insert a new item, and then edit it.
605 * <p>Input: {@link #getType} is the desired MIME type of the item to create or edit.
606 * The extras can contain type specific data to pass through to the editing/creating
607 * activity.
608 * <p>Output: The URI of the item that was picked. This must be a content:
609 * URI so that any receiver can access it.
610 */
611 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
612 public static final String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
613
614 /**
615 * Activity Action: Pick an item from the data, returning what was selected.
616 * <p>Input: {@link #getData} is URI containing a directory of data
617 * (vnd.android.cursor.dir/*) from which to pick an item.
618 * <p>Output: The URI of the item that was picked.
619 */
620 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
621 public static final String ACTION_PICK = "android.intent.action.PICK";
622
623 /**
624 * Activity Action: Creates a shortcut.
625 * <p>Input: Nothing.</p>
626 * <p>Output: An Intent representing the shortcut. The intent must contain three
627 * extras: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String),
628 * and SHORTCUT_ICON (value: Bitmap) or SHORTCUT_ICON_RESOURCE
629 * (value: ShortcutIconResource).</p>
630 *
631 * @see #EXTRA_SHORTCUT_INTENT
632 * @see #EXTRA_SHORTCUT_NAME
633 * @see #EXTRA_SHORTCUT_ICON
634 * @see #EXTRA_SHORTCUT_ICON_RESOURCE
635 * @see android.content.Intent.ShortcutIconResource
636 */
637 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
638 public static final String ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
639
640 /**
641 * The name of the extra used to define the Intent of a shortcut.
642 *
643 * @see #ACTION_CREATE_SHORTCUT
644 */
645 public static final String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
646 /**
647 * The name of the extra used to define the name of a shortcut.
648 *
649 * @see #ACTION_CREATE_SHORTCUT
650 */
651 public static final String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
652 /**
653 * The name of the extra used to define the icon, as a Bitmap, of a shortcut.
654 *
655 * @see #ACTION_CREATE_SHORTCUT
656 */
657 public static final String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
658 /**
659 * The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.
660 *
661 * @see #ACTION_CREATE_SHORTCUT
662 * @see android.content.Intent.ShortcutIconResource
663 */
664 public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
665 "android.intent.extra.shortcut.ICON_RESOURCE";
666
667 /**
668 * Represents a shortcut/live folder icon resource.
669 *
670 * @see Intent#ACTION_CREATE_SHORTCUT
671 * @see Intent#EXTRA_SHORTCUT_ICON_RESOURCE
672 * @see android.provider.LiveFolders#ACTION_CREATE_LIVE_FOLDER
673 * @see android.provider.LiveFolders#EXTRA_LIVE_FOLDER_ICON
674 */
675 public static class ShortcutIconResource implements Parcelable {
676 /**
677 * The package name of the application containing the icon.
678 */
679 public String packageName;
680
681 /**
682 * The resource name of the icon, including package, name and type.
683 */
684 public String resourceName;
685
686 /**
687 * Creates a new ShortcutIconResource for the specified context and resource
688 * identifier.
689 *
690 * @param context The context of the application.
691 * @param resourceId The resource idenfitier for the icon.
692 * @return A new ShortcutIconResource with the specified's context package name
693 * and icon resource idenfitier.
694 */
695 public static ShortcutIconResource fromContext(Context context, int resourceId) {
696 ShortcutIconResource icon = new ShortcutIconResource();
697 icon.packageName = context.getPackageName();
698 icon.resourceName = context.getResources().getResourceName(resourceId);
699 return icon;
700 }
701
702 /**
703 * Used to read a ShortcutIconResource from a Parcel.
704 */
705 public static final Parcelable.Creator<ShortcutIconResource> CREATOR =
706 new Parcelable.Creator<ShortcutIconResource>() {
707
708 public ShortcutIconResource createFromParcel(Parcel source) {
709 ShortcutIconResource icon = new ShortcutIconResource();
710 icon.packageName = source.readString();
711 icon.resourceName = source.readString();
712 return icon;
713 }
714
715 public ShortcutIconResource[] newArray(int size) {
716 return new ShortcutIconResource[size];
717 }
718 };
719
720 /**
721 * No special parcel contents.
722 */
723 public int describeContents() {
724 return 0;
725 }
726
727 public void writeToParcel(Parcel dest, int flags) {
728 dest.writeString(packageName);
729 dest.writeString(resourceName);
730 }
731
732 @Override
733 public String toString() {
734 return resourceName;
735 }
736 }
737
738 /**
739 * Activity Action: Display an activity chooser, allowing the user to pick
740 * what they want to before proceeding. This can be used as an alternative
741 * to the standard activity picker that is displayed by the system when
742 * you try to start an activity with multiple possible matches, with these
743 * differences in behavior:
744 * <ul>
745 * <li>You can specify the title that will appear in the activity chooser.
746 * <li>The user does not have the option to make one of the matching
747 * activities a preferred activity, and all possible activities will
748 * always be shown even if one of them is currently marked as the
749 * preferred activity.
750 * </ul>
751 * <p>
752 * This action should be used when the user will naturally expect to
753 * select an activity in order to proceed. An example if when not to use
754 * it is when the user clicks on a "mailto:" link. They would naturally
755 * expect to go directly to their mail app, so startActivity() should be
756 * called directly: it will
757 * either launch the current preferred app, or put up a dialog allowing the
758 * user to pick an app to use and optionally marking that as preferred.
759 * <p>
760 * In contrast, if the user is selecting a menu item to send a picture
761 * they are viewing to someone else, there are many different things they
762 * may want to do at this point: send it through e-mail, upload it to a
763 * web service, etc. In this case the CHOOSER action should be used, to
764 * always present to the user a list of the things they can do, with a
765 * nice title given by the caller such as "Send this photo with:".
766 * <p>
767 * As a convenience, an Intent of this form can be created with the
768 * {@link #createChooser} function.
769 * <p>Input: No data should be specified. get*Extra must have
770 * a {@link #EXTRA_INTENT} field containing the Intent being executed,
771 * and can optionally have a {@link #EXTRA_TITLE} field containing the
772 * title text to display in the chooser.
773 * <p>Output: Depends on the protocol of {@link #EXTRA_INTENT}.
774 */
775 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
776 public static final String ACTION_CHOOSER = "android.intent.action.CHOOSER";
777
778 /**
779 * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
780 *
781 * @param target The Intent that the user will be selecting an activity
782 * to perform.
783 * @param title Optional title that will be displayed in the chooser.
784 * @return Return a new Intent object that you can hand to
785 * {@link Context#startActivity(Intent) Context.startActivity()} and
786 * related methods.
787 */
788 public static Intent createChooser(Intent target, CharSequence title) {
789 Intent intent = new Intent(ACTION_CHOOSER);
790 intent.putExtra(EXTRA_INTENT, target);
791 if (title != null) {
792 intent.putExtra(EXTRA_TITLE, title);
793 }
794 return intent;
795 }
796 /**
797 * Activity Action: Allow the user to select a particular kind of data and
798 * return it. This is different than {@link #ACTION_PICK} in that here we
799 * just say what kind of data is desired, not a URI of existing data from
800 * which the user can pick. A ACTION_GET_CONTENT could allow the user to
801 * create the data as it runs (for example taking a picture or recording a
802 * sound), let them browser over the web and download the desired data,
803 * etc.
804 * <p>
805 * There are two main ways to use this action: if you want an specific kind
806 * of data, such as a person contact, you set the MIME type to the kind of
807 * data you want and launch it with {@link Context#startActivity(Intent)}.
808 * The system will then launch the best application to select that kind
809 * of data for you.
810 * <p>
811 * You may also be interested in any of a set of types of content the user
812 * can pick. For example, an e-mail application that wants to allow the
813 * user to add an attachment to an e-mail message can use this action to
814 * bring up a list of all of the types of content the user can attach.
815 * <p>
816 * In this case, you should wrap the GET_CONTENT intent with a chooser
817 * (through {@link #createChooser}), which will give the proper interface
818 * for the user to pick how to send your data and allow you to specify
819 * a prompt indicating what they are doing. You will usually specify a
820 * broad MIME type (such as image/* or {@literal *}/*), resulting in a
821 * broad range of content types the user can select from.
822 * <p>
823 * When using such a broad GET_CONTENT action, it is often desireable to
824 * only pick from data that can be represented as a stream. This is
825 * accomplished by requiring the {@link #CATEGORY_OPENABLE} in the Intent.
826 * <p>
827 * Input: {@link #getType} is the desired MIME type to retrieve. Note
828 * that no URI is supplied in the intent, as there are no constraints on
829 * where the returned data originally comes from. You may also include the
830 * {@link #CATEGORY_OPENABLE} if you can only accept data that can be
831 * opened as a stream.
832 * <p>
833 * Output: The URI of the item that was picked. This must be a content:
834 * URI so that any receiver can access it.
835 */
836 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
837 public static final String ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
838 /**
839 * Activity Action: Dial a number as specified by the data. This shows a
840 * UI with the number being dialed, allowing the user to explicitly
841 * initiate the call.
842 * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
843 * is URI of a phone number to be dialed or a tel: URI of an explicit phone
844 * number.
845 * <p>Output: nothing.
846 */
847 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
848 public static final String ACTION_DIAL = "android.intent.action.DIAL";
849 /**
850 * Activity Action: Perform a call to someone specified by the data.
851 * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
852 * is URI of a phone number to be dialed or a tel: URI of an explicit phone
853 * number.
854 * <p>Output: nothing.
855 *
856 * <p>Note: there will be restrictions on which applications can initiate a
857 * call; most applications should use the {@link #ACTION_DIAL}.
858 * <p>Note: this Intent <strong>cannot</strong> be used to call emergency
859 * numbers. Applications can <strong>dial</strong> emergency numbers using
860 * {@link #ACTION_DIAL}, however.
861 */
862 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
863 public static final String ACTION_CALL = "android.intent.action.CALL";
864 /**
865 * Activity Action: Perform a call to an emergency number specified by the
866 * data.
867 * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
868 * tel: URI of an explicit phone number.
869 * <p>Output: nothing.
870 * @hide
871 */
872 public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
873 /**
874 * Activity action: Perform a call to any number (emergency or not)
875 * specified by the data.
876 * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
877 * tel: URI of an explicit phone number.
878 * <p>Output: nothing.
879 * @hide
880 */
881 public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
882 /**
883 * Activity Action: Send a message to someone specified by the data.
884 * <p>Input: {@link #getData} is URI describing the target.
885 * <p>Output: nothing.
886 */
887 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
888 public static final String ACTION_SENDTO = "android.intent.action.SENDTO";
889 /**
890 * Activity Action: Deliver some data to someone else. Who the data is
891 * being delivered to is not specified; it is up to the receiver of this
892 * action to ask the user where the data should be sent.
893 * <p>
894 * When launching a SEND intent, you should usually wrap it in a chooser
895 * (through {@link #createChooser}), which will give the proper interface
896 * for the user to pick how to send your data and allow you to specify
897 * a prompt indicating what they are doing.
898 * <p>
899 * Input: {@link #getType} is the MIME type of the data being sent.
900 * get*Extra can have either a {@link #EXTRA_TEXT}
901 * or {@link #EXTRA_STREAM} field, containing the data to be sent. If
902 * using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it
903 * should be the MIME type of the data in EXTRA_STREAM. Use {@literal *}/*
904 * if the MIME type is unknown (this will only allow senders that can
905 * handle generic data streams).
906 * <p>
907 * Optional standard extras, which may be interpreted by some recipients as
908 * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
909 * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
910 * <p>
911 * Output: nothing.
912 */
913 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
914 public static final String ACTION_SEND = "android.intent.action.SEND";
915 /**
916 * Activity Action: Handle an incoming phone call.
917 * <p>Input: nothing.
918 * <p>Output: nothing.
919 */
920 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
921 public static final String ACTION_ANSWER = "android.intent.action.ANSWER";
922 /**
923 * Activity Action: Insert an empty item into the given container.
924 * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
925 * in which to place the data.
926 * <p>Output: URI of the new data that was created.
927 */
928 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
929 public static final String ACTION_INSERT = "android.intent.action.INSERT";
930 /**
931 * Activity Action: Delete the given data from its container.
932 * <p>Input: {@link #getData} is URI of data to be deleted.
933 * <p>Output: nothing.
934 */
935 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
936 public static final String ACTION_DELETE = "android.intent.action.DELETE";
937 /**
938 * Activity Action: Run the data, whatever that means.
939 * <p>Input: ? (Note: this is currently specific to the test harness.)
940 * <p>Output: nothing.
941 */
942 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
943 public static final String ACTION_RUN = "android.intent.action.RUN";
944 /**
945 * Activity Action: Perform a data synchronization.
946 * <p>Input: ?
947 * <p>Output: ?
948 */
949 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
950 public static final String ACTION_SYNC = "android.intent.action.SYNC";
951 /**
952 * Activity Action: Pick an activity given an intent, returning the class
953 * selected.
954 * <p>Input: get*Extra field {@link #EXTRA_INTENT} is an Intent
955 * used with {@link PackageManager#queryIntentActivities} to determine the
956 * set of activities from which to pick.
957 * <p>Output: Class name of the activity that was selected.
958 */
959 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
960 public static final String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
961 /**
962 * Activity Action: Perform a search.
963 * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
964 * is the text to search for. If empty, simply
965 * enter your search results Activity with the search UI activated.
966 * <p>Output: nothing.
967 */
968 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
969 public static final String ACTION_SEARCH = "android.intent.action.SEARCH";
970 /**
971 * Activity Action: Perform a web search.
972 * <p>
973 * Input: {@link android.app.SearchManager#QUERY
974 * getStringExtra(SearchManager.QUERY)} is the text to search for. If it is
975 * a url starts with http or https, the site will be opened. If it is plain
976 * text, Google search will be applied.
977 * <p>
978 * Output: nothing.
979 */
980 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
981 public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
982 /**
983 * Activity Action: List all available applications
984 * <p>Input: Nothing.
985 * <p>Output: nothing.
986 */
987 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
988 public static final String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
989 /**
990 * Activity Action: Show settings for choosing wallpaper
991 * <p>Input: Nothing.
992 * <p>Output: Nothing.
993 */
994 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
995 public static final String ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
996
997 /**
998 * Activity Action: Show activity for reporting a bug.
999 * <p>Input: Nothing.
1000 * <p>Output: Nothing.
1001 */
1002 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1003 public static final String ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
1004
1005 /**
1006 * Activity Action: Main entry point for factory tests. Only used when
1007 * the device is booting in factory test node. The implementing package
1008 * must be installed in the system image.
1009 * <p>Input: nothing
1010 * <p>Output: nothing
1011 */
1012 public static final String ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
1013
1014 /**
1015 * Activity Action: The user pressed the "call" button to go to the dialer
1016 * or other appropriate UI for placing a call.
1017 * <p>Input: Nothing.
1018 * <p>Output: Nothing.
1019 */
1020 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1021 public static final String ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
1022
1023 /**
1024 * Activity Action: Start Voice Command.
1025 * <p>Input: Nothing.
1026 * <p>Output: Nothing.
1027 */
1028 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1029 public static final String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
1030
1031 // ---------------------------------------------------------------------
1032 // ---------------------------------------------------------------------
1033 // Standard intent broadcast actions (see action variable).
1034
1035 /**
1036 * Broadcast Action: Sent after the screen turns off.
1037 */
1038 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1039 public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
1040 /**
1041 * Broadcast Action: Sent after the screen turns on.
1042 */
1043 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1044 public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001045
1046 /**
1047 * Broadcast Action: Sent when the user is present after device wakes up (e.g when the
1048 * keyguard is gone).
1049 */
1050 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1051 public static final String ACTION_USER_PRESENT= "android.intent.action.USER_PRESENT";
1052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 /**
1054 * Broadcast Action: The current time has changed. Sent every
1055 * minute. You can <em>not</em> receive this through components declared
1056 * in manifests, only by exlicitly registering for it with
1057 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1058 * Context.registerReceiver()}.
1059 */
1060 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1061 public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
1062 /**
1063 * Broadcast Action: The time was set.
1064 */
1065 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1066 public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
1067 /**
1068 * Broadcast Action: The date has changed.
1069 */
1070 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1071 public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
1072 /**
1073 * Broadcast Action: The timezone has changed. The intent will have the following extra values:</p>
1074 * <ul>
1075 * <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time zone.</li>
1076 * </ul>
1077 */
1078 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1079 public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
1080 /**
1081 * Alarm Changed Action: This is broadcast when the AlarmClock
1082 * application's alarm is set or unset. It is used by the
1083 * AlarmClock application and the StatusBar service.
1084 * @hide
1085 */
1086 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1087 public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
1088 /**
1089 * Sync State Changed Action: This is broadcast when the sync starts or stops or when one has
1090 * been failing for a long time. It is used by the SyncManager and the StatusBar service.
1091 * @hide
1092 */
1093 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1094 public static final String ACTION_SYNC_STATE_CHANGED
1095 = "android.intent.action.SYNC_STATE_CHANGED";
1096 /**
1097 * Broadcast Action: This is broadcast once, after the system has finished
1098 * booting. It can be used to perform application-specific initialization,
1099 * such as installing alarms. You must hold the
1100 * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
1101 * in order to receive this broadcast.
1102 */
1103 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1104 public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
1105 /**
1106 * Broadcast Action: This is broadcast when a user action should request a
1107 * temporary system dialog to dismiss. Some examples of temporary system
1108 * dialogs are the notification window-shade and the recent tasks dialog.
1109 */
1110 public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
1111 /**
1112 * Broadcast Action: Trigger the download and eventual installation
1113 * of a package.
1114 * <p>Input: {@link #getData} is the URI of the package file to download.
1115 */
1116 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1117 public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
1118 /**
1119 * Broadcast Action: A new application package has been installed on the
1120 * device. The data contains the name of the package.
1121 * <p>My include the following extras:
1122 * <ul>
1123 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1124 * <li> {@link #EXTRA_REPLACING} is set to true if this is following
1125 * an {@link #ACTION_PACKAGE_REMOVED} broadcast for the same package.
1126 * </ul>
1127 */
1128 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1129 public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
1130 /**
1131 * Broadcast Action: An existing application package has been removed from
1132 * the device. The data contains the name of the package. The package
1133 * that is being installed does <em>not</em> receive this Intent.
1134 * <ul>
1135 * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1136 * to the package.
1137 * <li> {@link #EXTRA_DATA_REMOVED} is set to true if the entire
1138 * application -- data and code -- is being removed.
1139 * <li> {@link #EXTRA_REPLACING} is set to true if this will be followed
1140 * by an {@link #ACTION_PACKAGE_ADDED} broadcast for the same package.
1141 * </ul>
1142 */
1143 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1144 public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
1145 /**
1146 * Broadcast Action: An existing application package has been changed (e.g. a component has been
1147 * enabled or disabled. The data contains the name of the package.
1148 * <ul>
1149 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1150 * </ul>
1151 */
1152 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1153 public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
1154 /**
1155 * Broadcast Action: The user has restarted a package, and all of its
1156 * processes have been killed. All runtime state
1157 * associated with it (processes, alarms, notifications, etc) should
1158 * be removed. The data contains the name of the package.
1159 * <ul>
1160 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1161 * </ul>
1162 */
1163 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1164 public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
1165 /**
1166 * Broadcast Action: The user has cleared the data of a package. This should
1167 * be preceded by {@link #ACTION_PACKAGE_RESTARTED}, after which all of
1168 * its persistent data is erased and this broadcast sent. The data contains
1169 * the name of the package.
1170 * <ul>
1171 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1172 * </ul>
1173 */
1174 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1175 public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
1176 /**
1177 * Broadcast Action: A user ID has been removed from the system. The user
1178 * ID number is stored in the extra data under {@link #EXTRA_UID}.
1179 */
1180 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1181 public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
1182 /**
1183 * Broadcast Action: The current system wallpaper has changed. See
1184 * {@link Context#getWallpaper} for retrieving the new wallpaper.
1185 */
1186 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1187 public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
1188 /**
1189 * Broadcast Action: The current device {@link android.content.res.Configuration}
1190 * (orientation, locale, etc) has changed. When such a change happens, the
1191 * UIs (view hierarchy) will need to be rebuilt based on this new
1192 * information; for the most part, applications don't need to worry about
1193 * this, because the system will take care of stopping and restarting the
1194 * application to make sure it sees the new changes. Some system code that
1195 * can not be restarted will need to watch for this action and handle it
1196 * appropriately.
1197 *
1198 * @see android.content.res.Configuration
1199 */
1200 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1201 public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
1202 /**
1203 * Broadcast Action: The charging state, or charge level of the battery has
1204 * changed.
1205 *
1206 * <p class="note">
1207 * You can <em>not</em> receive this through components declared
1208 * in manifests, only by exlicitly registering for it with
1209 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1210 * Context.registerReceiver()}.
1211 */
1212 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1213 public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
1214 /**
1215 * Broadcast Action: Indicates low battery condition on the device.
1216 * This broadcast corresponds to the "Low battery warning" system dialog.
1217 */
1218 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1219 public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
1220 /**
1221 * Broadcast Action: Indicates low memory condition on the device
1222 */
1223 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1224 public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
1225 /**
1226 * Broadcast Action: Indicates low memory condition on the device no longer exists
1227 */
1228 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1229 public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
1230 /**
1231 * Broadcast Action: Indicates low memory condition notification acknowledged by user
1232 * and package management should be started.
1233 * This is triggered by the user from the ACTION_DEVICE_STORAGE_LOW
1234 * notification.
1235 */
1236 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1237 public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
1238 /**
1239 * Broadcast Action: The device has entered USB Mass Storage mode.
1240 * This is used mainly for the USB Settings panel.
1241 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1242 * when the SD card file system is mounted or unmounted
1243 */
1244 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1245 public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
1246
1247 /**
1248 * Broadcast Action: The device has exited USB Mass Storage mode.
1249 * This is used mainly for the USB Settings panel.
1250 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1251 * when the SD card file system is mounted or unmounted
1252 */
1253 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1254 public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
1255
1256 /**
1257 * Broadcast Action: External media has been removed.
1258 * The path to the mount point for the removed media is contained in the Intent.mData field.
1259 */
1260 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1261 public static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
1262
1263 /**
1264 * Broadcast Action: External media is present, but not mounted at its mount point.
1265 * The path to the mount point for the removed media is contained in the Intent.mData field.
1266 */
1267 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1268 public static final String ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
1269
1270 /**
1271 * Broadcast Action: External media is present, and being disk-checked
1272 * The path to the mount point for the checking media is contained in the Intent.mData field.
1273 */
1274 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1275 public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
1276
1277 /**
1278 * Broadcast Action: External media is present, but is using an incompatible fs (or is blank)
1279 * The path to the mount point for the checking media is contained in the Intent.mData field.
1280 */
1281 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1282 public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
1283
1284 /**
1285 * Broadcast Action: External media is present and mounted at its mount point.
1286 * The path to the mount point for the removed media is contained in the Intent.mData field.
1287 * The Intent contains an extra with name "read-only" and Boolean value to indicate if the
1288 * media was mounted read only.
1289 */
1290 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1291 public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
1292
1293 /**
1294 * Broadcast Action: External media is unmounted because it is being shared via USB mass storage.
1295 * The path to the mount point for the removed media is contained in the Intent.mData field.
1296 */
1297 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1298 public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
1299
1300 /**
1301 * Broadcast Action: External media was removed from SD card slot, but mount point was not unmounted.
1302 * The path to the mount point for the removed media is contained in the Intent.mData field.
1303 */
1304 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1305 public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
1306
1307 /**
1308 * Broadcast Action: External media is present but cannot be mounted.
1309 * The path to the mount point for the removed media is contained in the Intent.mData field.
1310 */
1311 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1312 public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
1313
1314 /**
1315 * Broadcast Action: User has expressed the desire to remove the external storage media.
1316 * Applications should close all files they have open within the mount point when they receive this intent.
1317 * The path to the mount point for the media to be ejected is contained in the Intent.mData field.
1318 */
1319 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1320 public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
1321
1322 /**
1323 * Broadcast Action: The media scanner has started scanning a directory.
1324 * The path to the directory being scanned is contained in the Intent.mData field.
1325 */
1326 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1327 public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
1328
1329 /**
1330 * Broadcast Action: The media scanner has finished scanning a directory.
1331 * The path to the scanned directory is contained in the Intent.mData field.
1332 */
1333 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1334 public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
1335
1336 /**
1337 * Broadcast Action: Request the media scanner to scan a file and add it to the media database.
1338 * The path to the file is contained in the Intent.mData field.
1339 */
1340 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1341 public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
1342
1343 /**
1344 * Broadcast Action: The "Media Button" was pressed. Includes a single
1345 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1346 * caused the broadcast.
1347 */
1348 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1349 public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
1350
1351 /**
1352 * Broadcast Action: The "Camera Button" was pressed. Includes a single
1353 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1354 * caused the broadcast.
1355 */
1356 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1357 public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
1358
1359 // *** NOTE: @todo(*) The following really should go into a more domain-specific
1360 // location; they are not general-purpose actions.
1361
1362 /**
1363 * Broadcast Action: An GTalk connection has been established.
1364 */
1365 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1366 public static final String ACTION_GTALK_SERVICE_CONNECTED =
1367 "android.intent.action.GTALK_CONNECTED";
1368
1369 /**
1370 * Broadcast Action: An GTalk connection has been disconnected.
1371 */
1372 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1373 public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
1374 "android.intent.action.GTALK_DISCONNECTED";
1375
1376 /**
1377 * Broadcast Action: An input method has been changed.
1378 * {@hide pending API Council approval}
1379 */
1380 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1381 public static final String ACTION_INPUT_METHOD_CHANGED =
1382 "android.intent.action.INPUT_METHOD_CHANGED";
1383
1384 /**
1385 * <p>Broadcast Action: The user has switched the phone into or out of Airplane Mode. One or
1386 * more radios have been turned off or on. The intent will have the following extra value:</p>
1387 * <ul>
1388 * <li><em>state</em> - A boolean value indicating whether Airplane Mode is on. If true,
1389 * then cell radio and possibly other radios such as bluetooth or WiFi may have also been
1390 * turned off</li>
1391 * </ul>
1392 */
1393 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1394 public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
1395
1396 /**
1397 * Broadcast Action: Some content providers have parts of their namespace
1398 * where they publish new events or items that the user may be especially
1399 * interested in. For these things, they may broadcast this action when the
1400 * set of interesting items change.
1401 *
1402 * For example, GmailProvider sends this notification when the set of unread
1403 * mail in the inbox changes.
1404 *
1405 * <p>The data of the intent identifies which part of which provider
1406 * changed. When queried through the content resolver, the data URI will
1407 * return the data set in question.
1408 *
1409 * <p>The intent will have the following extra values:
1410 * <ul>
1411 * <li><em>count</em> - The number of items in the data set. This is the
1412 * same as the number of items in the cursor returned by querying the
1413 * data URI. </li>
1414 * </ul>
1415 *
1416 * This intent will be sent at boot (if the count is non-zero) and when the
1417 * data set changes. It is possible for the data set to change without the
1418 * count changing (for example, if a new unread message arrives in the same
1419 * sync operation in which a message is archived). The phone should still
1420 * ring/vibrate/etc as normal in this case.
1421 */
1422 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1423 public static final String ACTION_PROVIDER_CHANGED =
1424 "android.intent.action.PROVIDER_CHANGED";
1425
1426 /**
1427 * Broadcast Action: Wired Headset plugged in or unplugged.
1428 *
1429 * <p>The intent will have the following extra values:
1430 * <ul>
1431 * <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
1432 * <li><em>name</em> - Headset type, human readable string </li>
1433 * </ul>
1434 * </ul>
1435 */
1436 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1437 public static final String ACTION_HEADSET_PLUG =
1438 "android.intent.action.HEADSET_PLUG";
1439
1440 /**
1441 * Broadcast Action: An outgoing call is about to be placed.
1442 *
1443 * <p>The Intent will have the following extra value:
1444 * <ul>
1445 * <li><em>{@link android.content.Intent#EXTRA_PHONE_NUMBER}</em> -
1446 * the phone number originally intended to be dialed.</li>
1447 * </ul>
1448 * <p>Once the broadcast is finished, the resultData is used as the actual
1449 * number to call. If <code>null</code>, no call will be placed.</p>
1450 * <p>It is perfectly acceptable for multiple receivers to process the
1451 * outgoing call in turn: for example, a parental control application
1452 * might verify that the user is authorized to place the call at that
1453 * time, then a number-rewriting application might add an area code if
1454 * one was not specified.</p>
1455 * <p>For consistency, any receiver whose purpose is to prohibit phone
1456 * calls should have a priority of 0, to ensure it will see the final
1457 * phone number to be dialed.
1458 * Any receiver whose purpose is to rewrite phone numbers to be called
1459 * should have a positive priority.
1460 * Negative priorities are reserved for the system for this broadcast;
1461 * using them may cause problems.</p>
1462 * <p>Any BroadcastReceiver receiving this Intent <em>must not</em>
1463 * abort the broadcast.</p>
1464 * <p>Emergency calls cannot be intercepted using this mechanism, and
1465 * other calls cannot be modified to call emergency numbers using this
1466 * mechanism.
1467 * <p>You must hold the
1468 * {@link android.Manifest.permission#PROCESS_OUTGOING_CALLS}
1469 * permission to receive this Intent.</p>
1470 */
1471 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1472 public static final String ACTION_NEW_OUTGOING_CALL =
1473 "android.intent.action.NEW_OUTGOING_CALL";
1474
1475 /**
1476 * Broadcast Action: Have the device reboot. This is only for use by
1477 * system code.
1478 */
1479 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1480 public static final String ACTION_REBOOT =
1481 "android.intent.action.REBOOT";
1482
1483 // ---------------------------------------------------------------------
1484 // ---------------------------------------------------------------------
1485 // Standard intent categories (see addCategory()).
1486
1487 /**
1488 * Set if the activity should be an option for the default action
1489 * (center press) to perform on a piece of data. Setting this will
1490 * hide from the user any activities without it set when performing an
1491 * action on some data. Note that this is normal -not- set in the
1492 * Intent when initiating an action -- it is for use in intent filters
1493 * specified in packages.
1494 */
1495 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1496 public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
1497 /**
1498 * Activities that can be safely invoked from a browser must support this
1499 * category. For example, if the user is viewing a web page or an e-mail
1500 * and clicks on a link in the text, the Intent generated execute that
1501 * link will require the BROWSABLE category, so that only activities
1502 * supporting this category will be considered as possible actions. By
1503 * supporting this category, you are promising that there is nothing
1504 * damaging (without user intervention) that can happen by invoking any
1505 * matching Intent.
1506 */
1507 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1508 public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
1509 /**
1510 * Set if the activity should be considered as an alternative action to
1511 * the data the user is currently viewing. See also
1512 * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
1513 * applies to the selection in a list of items.
1514 *
1515 * <p>Supporting this category means that you would like your activity to be
1516 * displayed in the set of alternative things the user can do, usually as
1517 * part of the current activity's options menu. You will usually want to
1518 * include a specific label in the &lt;intent-filter&gt; of this action
1519 * describing to the user what it does.
1520 *
1521 * <p>The action of IntentFilter with this category is important in that it
1522 * describes the specific action the target will perform. This generally
1523 * should not be a generic action (such as {@link #ACTION_VIEW}, but rather
1524 * a specific name such as "com.android.camera.action.CROP. Only one
1525 * alternative of any particular action will be shown to the user, so using
1526 * a specific action like this makes sure that your alternative will be
1527 * displayed while also allowing other applications to provide their own
1528 * overrides of that particular action.
1529 */
1530 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1531 public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
1532 /**
1533 * Set if the activity should be considered as an alternative selection
1534 * action to the data the user has currently selected. This is like
1535 * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list
1536 * of items from which the user can select, giving them alternatives to the
1537 * default action that will be performed on it.
1538 */
1539 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1540 public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
1541 /**
1542 * Intended to be used as a tab inside of an containing TabActivity.
1543 */
1544 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1545 public static final String CATEGORY_TAB = "android.intent.category.TAB";
1546 /**
1547 * This activity can be embedded inside of another activity that is hosting
1548 * gadgets.
1549 */
1550 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1551 public static final String CATEGORY_GADGET = "android.intent.category.GADGET";
1552 /**
1553 * Should be displayed in the top-level launcher.
1554 */
1555 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1556 public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
1557 /**
1558 * Provides information about the package it is in; typically used if
1559 * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
1560 * a front-door to the user without having to be shown in the all apps list.
1561 */
1562 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1563 public static final String CATEGORY_INFO = "android.intent.category.INFO";
1564 /**
1565 * This is the home activity, that is the first activity that is displayed
1566 * when the device boots.
1567 */
1568 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1569 public static final String CATEGORY_HOME = "android.intent.category.HOME";
1570 /**
1571 * This activity is a preference panel.
1572 */
1573 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1574 public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
1575 /**
1576 * This activity is a development preference panel.
1577 */
1578 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1579 public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
1580 /**
1581 * Capable of running inside a parent activity container.
1582 *
1583 * <p>Note: being removed in favor of more explicit categories such as
1584 * CATEGORY_GADGET
1585 */
1586 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1587 public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
1588 /**
1589 * This activity may be exercised by the monkey or other automated test tools.
1590 */
1591 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1592 public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
1593 /**
1594 * To be used as a test (not part of the normal user experience).
1595 */
1596 public static final String CATEGORY_TEST = "android.intent.category.TEST";
1597 /**
1598 * To be used as a unit test (run through the Test Harness).
1599 */
1600 public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
1601 /**
1602 * To be used as an sample code example (not part of the normal user
1603 * experience).
1604 */
1605 public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
1606 /**
1607 * Used to indicate that a GET_CONTENT intent only wants URIs that can be opened with
1608 * ContentResolver.openInputStream. Openable URIs must support the columns in OpenableColumns
1609 * when queried, though it is allowable for those columns to be blank.
1610 */
1611 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1612 public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
1613
1614 /**
1615 * To be used as code under test for framework instrumentation tests.
1616 */
1617 public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
1618 "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
1619 // ---------------------------------------------------------------------
1620 // ---------------------------------------------------------------------
1621 // Standard extra data keys.
1622
1623 /**
1624 * The initial data to place in a newly created record. Use with
1625 * {@link #ACTION_INSERT}. The data here is a Map containing the same
1626 * fields as would be given to the underlying ContentProvider.insert()
1627 * call.
1628 */
1629 public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
1630
1631 /**
1632 * A constant CharSequence that is associated with the Intent, used with
1633 * {@link #ACTION_SEND} to supply the literal data to be sent. Note that
1634 * this may be a styled CharSequence, so you must use
1635 * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to
1636 * retrieve it.
1637 */
1638 public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
1639
1640 /**
1641 * A content: URI holding a stream of data associated with the Intent,
1642 * used with {@link #ACTION_SEND} to supply the data being sent.
1643 */
1644 public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
1645
1646 /**
1647 * A String[] holding e-mail addresses that should be delivered to.
1648 */
1649 public static final String EXTRA_EMAIL = "android.intent.extra.EMAIL";
1650
1651 /**
1652 * A String[] holding e-mail addresses that should be carbon copied.
1653 */
1654 public static final String EXTRA_CC = "android.intent.extra.CC";
1655
1656 /**
1657 * A String[] holding e-mail addresses that should be blind carbon copied.
1658 */
1659 public static final String EXTRA_BCC = "android.intent.extra.BCC";
1660
1661 /**
1662 * A constant string holding the desired subject line of a message.
1663 */
1664 public static final String EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
1665
1666 /**
1667 * An Intent describing the choices you would like shown with
1668 * {@link #ACTION_PICK_ACTIVITY}.
1669 */
1670 public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
1671
1672 /**
1673 * A CharSequence dialog title to provide to the user when used with a
1674 * {@link #ACTION_CHOOSER}.
1675 */
1676 public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
1677
1678 /**
1679 * A {@link android.view.KeyEvent} object containing the event that
1680 * triggered the creation of the Intent it is in.
1681 */
1682 public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
1683
1684 /**
1685 * Used as an boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
1686 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
1687 * of restarting the application.
1688 */
1689 public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
1690
1691 /**
1692 * A String holding the phone number originally entered in
1693 * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual
1694 * number to call in a {@link android.content.Intent#ACTION_CALL}.
1695 */
1696 public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
1697 /**
1698 * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED}
1699 * intents to supply the uid the package had been assigned. Also an optional
1700 * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
1701 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same
1702 * purpose.
1703 */
1704 public static final String EXTRA_UID = "android.intent.extra.UID";
1705
1706 /**
1707 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
1708 * intents to indicate whether this represents a full uninstall (removing
1709 * both the code and its data) or a partial uninstall (leaving its data,
1710 * implying that this is an update).
1711 */
1712 public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
1713
1714 /**
1715 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
1716 * intents to indicate that this is a replacement of the package, so this
1717 * broadcast will immediately be followed by an add broadcast for a
1718 * different version of the same package.
1719 */
1720 public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
1721
1722 /**
1723 * Used as an int extra field in {@link android.app.AlarmManager} intents
1724 * to tell the application being invoked how many pending alarms are being
1725 * delievered with the intent. For one-shot alarms this will always be 1.
1726 * For recurring alarms, this might be greater than 1 if the device was
1727 * asleep or powered off at the time an earlier alarm would have been
1728 * delivered.
1729 */
1730 public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
1731
1732 /**
1733 * Used as an int extra field in {@link android.content.Intent#ACTION_VOICE_COMMAND}
1734 * intents to request which audio route the voice command should prefer.
1735 * The value should be a route from {@link android.media.AudioManager}, for
1736 * example ROUTE_BLUETOOTH_SCO. Providing this value is optional.
1737 * {@hide pending API Council approval}
1738 */
1739 public static final String EXTRA_AUDIO_ROUTE = "android.intent.extra.AUDIO_ROUTE";
1740
1741 // ---------------------------------------------------------------------
1742 // ---------------------------------------------------------------------
1743 // Intent flags (see mFlags variable).
1744
1745 /**
1746 * If set, the recipient of this Intent will be granted permission to
1747 * perform read operations on the Uri in the Intent's data.
1748 */
1749 public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
1750 /**
1751 * If set, the recipient of this Intent will be granted permission to
1752 * perform write operations on the Uri in the Intent's data.
1753 */
1754 public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
1755 /**
1756 * Can be set by the caller to indicate that this Intent is coming from
1757 * a background operation, not from direct user interaction.
1758 */
1759 public static final int FLAG_FROM_BACKGROUND = 0x00000004;
1760 /**
1761 * A flag you can enable for debugging: when set, log messages will be
1762 * printed during the resolution of this intent to show you what has
1763 * been found to create the final resolved list.
1764 */
1765 public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
1766
1767 /**
1768 * If set, the new activity is not kept in the history stack. As soon as
1769 * the user navigates away from it, the activity is finished. This may also
1770 * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
1771 * noHistory} attribute.
1772 */
1773 public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
1774 /**
1775 * If set, the activity will not be launched if it is already running
1776 * at the top of the history stack.
1777 */
1778 public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
1779 /**
1780 * If set, this activity will become the start of a new task on this
1781 * history stack. A task (from the activity that started it to the
1782 * next task activity) defines an atomic group of activities that the
1783 * user can move to. Tasks can be moved to the foreground and background;
1784 * all of the activities inside of a particular task always remain in
1785 * the same order. See
1786 * <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
1787 * Activities and Tasks</a> for more details on tasks.
1788 *
1789 * <p>This flag is generally used by activities that want
1790 * to present a "launcher" style behavior: they give the user a list of
1791 * separate things that can be done, which otherwise run completely
1792 * independently of the activity launching them.
1793 *
1794 * <p>When using this flag, if a task is already running for the activity
1795 * you are now starting, then a new activity will not be started; instead,
1796 * the current task will simply be brought to the front of the screen with
1797 * the state it was last in. See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
1798 * to disable this behavior.
1799 *
1800 * <p>This flag can not be used when the caller is requesting a result from
1801 * the activity being launched.
1802 */
1803 public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
1804 /**
1805 * <strong>Do not use this flag unless you are implementing your own
1806 * top-level application launcher.</strong> Used in conjunction with
1807 * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the
1808 * behavior of bringing an existing task to the foreground. When set,
1809 * a new task is <em>always</em> started to host the Activity for the
1810 * Intent, regardless of whether there is already an existing task running
1811 * the same thing.
1812 *
1813 * <p><strong>Because the default system does not include graphical task management,
1814 * you should not use this flag unless you provide some way for a user to
1815 * return back to the tasks you have launched.</strong>
1816 *
1817 * <p>This flag is ignored if
1818 * {@link #FLAG_ACTIVITY_NEW_TASK} is not set.
1819 *
1820 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
1821 * Activities and Tasks</a> for more details on tasks.
1822 */
1823 public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
1824 /**
1825 * If set, and the activity being launched is already running in the
1826 * current task, then instead of launching a new instance of that activity,
1827 * all of the other activities on top of it will be closed and this Intent
1828 * will be delivered to the (now on top) old activity as a new Intent.
1829 *
1830 * <p>For example, consider a task consisting of the activities: A, B, C, D.
1831 * If D calls startActivity() with an Intent that resolves to the component
1832 * of activity B, then C and D will be finished and B receive the given
1833 * Intent, resulting in the stack now being: A, B.
1834 *
1835 * <p>The currently running instance of task B in the above example will
1836 * either receive the new intent you are starting here in its
1837 * onNewIntent() method, or be itself finished and restarted with the
1838 * new intent. If it has declared its launch mode to be "multiple" (the
1839 * default) it will be finished and re-created; for all other launch modes
1840 * it will receive the Intent in the current instance.
1841 *
1842 * <p>This launch mode can also be used to good effect in conjunction with
1843 * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity
1844 * of a task, it will bring any currently running instance of that task
1845 * to the foreground, and then clear it to its root state. This is
1846 * especially useful, for example, when launching an activity from the
1847 * notification manager.
1848 *
1849 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
1850 * Activities and Tasks</a> for more details on tasks.
1851 */
1852 public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
1853 /**
1854 * If set and this intent is being used to launch a new activity from an
1855 * existing one, then the reply target of the existing activity will be
1856 * transfered to the new activity. This way the new activity can call
1857 * {@link android.app.Activity#setResult} and have that result sent back to
1858 * the reply target of the original activity.
1859 */
1860 public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
1861 /**
1862 * If set and this intent is being used to launch a new activity from an
1863 * existing one, the current activity will not be counted as the top
1864 * activity for deciding whether the new intent should be delivered to
1865 * the top instead of starting a new one. The previous activity will
1866 * be used as the top, with the assumption being that the current activity
1867 * will finish itself immediately.
1868 */
1869 public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
1870 /**
1871 * If set, the new activity is not kept in the list of recently launched
1872 * activities.
1873 */
1874 public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
1875 /**
1876 * This flag is not normally set by application code, but set for you by
1877 * the system as described in the
1878 * {@link android.R.styleable#AndroidManifestActivity_launchMode
1879 * launchMode} documentation for the singleTask mode.
1880 */
1881 public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
1882 /**
1883 * If set, and this activity is either being started in a new task or
1884 * bringing to the top an existing task, then it will be launched as
1885 * the front door of the task. This will result in the application of
1886 * any affinities needed to have that task in the proper state (either
1887 * moving activities to or from it), or simply resetting that task to
1888 * its initial state if needed.
1889 */
1890 public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
1891 /**
1892 * This flag is not normally set by application code, but set for you by
1893 * the system if this activity is being launched from history
1894 * (longpress home key).
1895 */
1896 public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
1897 /**
1898 * If set, this marks a point in the task's activity stack that should
1899 * be cleared when the task is reset. That is, the next time the task
1900 * is broad to the foreground with
1901 * {@link #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED} (typically as a result of
1902 * the user re-launching it from home), this activity and all on top of
1903 * it will be finished so that the user does not return to them, but
1904 * instead returns to whatever activity preceeded it.
1905 *
1906 * <p>This is useful for cases where you have a logical break in your
1907 * application. For example, an e-mail application may have a command
1908 * to view an attachment, which launches an image view activity to
1909 * display it. This activity should be part of the e-mail application's
1910 * task, since it is a part of the task the user is involved in. However,
1911 * if the user leaves that task, and later selects the e-mail app from
1912 * home, we may like them to return to the conversation they were
1913 * viewing, not the picture attachment, since that is confusing. By
1914 * setting this flag when launching the image viewer, that viewer and
1915 * any activities it starts will be removed the next time the user returns
1916 * to mail.
1917 */
1918 public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
1919 /**
1920 * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint}
1921 * callback from occurring on the current frontmost activity before it is
1922 * paused as the newly-started activity is brought to the front.
1923 *
1924 * <p>Typically, an activity can rely on that callback to indicate that an
1925 * explicit user action has caused their activity to be moved out of the
1926 * foreground. The callback marks an appropriate point in the activity's
1927 * lifecycle for it to dismiss any notifications that it intends to display
1928 * "until the user has seen them," such as a blinking LED.
1929 *
1930 * <p>If an activity is ever started via any non-user-driven events such as
1931 * phone-call receipt or an alarm handler, this flag should be passed to {@link
1932 * Context#startActivity Context.startActivity}, ensuring that the pausing
1933 * activity does not think the user has acknowledged its notification.
1934 */
1935 public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
1936 /**
1937 * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
1938 * this flag will cause the launched activity to be brought to the front of its
1939 * task's history stack if it is already running.
1940 *
1941 * <p>For example, consider a task consisting of four activities: A, B, C, D.
1942 * If D calls startActivity() with an Intent that resolves to the component
1943 * of activity B, then B will be brought to the front of the history stack,
1944 * with this resulting order: A, C, D, B.
1945 *
1946 * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also
1947 * specified.
1948 */
1949 public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
1950 /**
1951 * If set, when sending a broadcast only registered receivers will be
1952 * called -- no BroadcastReceiver components will be launched.
1953 */
1954 public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
1955 /**
1956 * If set, when sending a broadcast <i>before boot has completed</i> only
1957 * registered receivers will be called -- no BroadcastReceiver components
1958 * will be launched. Sticky intent state will be recorded properly even
1959 * if no receivers wind up being called. If {@link #FLAG_RECEIVER_REGISTERED_ONLY}
1960 * is specified in the broadcast intent, this flag is unnecessary.
1961 *
1962 * <p>This flag is only for use by system sevices as a convenience to
1963 * avoid having to implement a more complex mechanism around detection
1964 * of boot completion.
1965 *
1966 * @hide
1967 */
1968 public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x20000000;
1969
1970 // ---------------------------------------------------------------------
1971
1972 private String mAction;
1973 private Uri mData;
1974 private String mType;
1975 private ComponentName mComponent;
1976 private int mFlags;
1977 private HashSet<String> mCategories;
1978 private Bundle mExtras;
1979
1980 // ---------------------------------------------------------------------
1981
1982 /**
1983 * Create an empty intent.
1984 */
1985 public Intent() {
1986 }
1987
1988 /**
1989 * Copy constructor.
1990 */
1991 public Intent(Intent o) {
1992 this.mAction = o.mAction;
1993 this.mData = o.mData;
1994 this.mType = o.mType;
1995 this.mComponent = o.mComponent;
1996 this.mFlags = o.mFlags;
1997 if (o.mCategories != null) {
1998 this.mCategories = new HashSet<String>(o.mCategories);
1999 }
2000 if (o.mExtras != null) {
2001 this.mExtras = new Bundle(o.mExtras);
2002 }
2003 }
2004
2005 @Override
2006 public Object clone() {
2007 return new Intent(this);
2008 }
2009
2010 private Intent(Intent o, boolean all) {
2011 this.mAction = o.mAction;
2012 this.mData = o.mData;
2013 this.mType = o.mType;
2014 this.mComponent = o.mComponent;
2015 if (o.mCategories != null) {
2016 this.mCategories = new HashSet<String>(o.mCategories);
2017 }
2018 }
2019
2020 /**
2021 * Make a clone of only the parts of the Intent that are relevant for
2022 * filter matching: the action, data, type, component, and categories.
2023 */
2024 public Intent cloneFilter() {
2025 return new Intent(this, false);
2026 }
2027
2028 /**
2029 * Create an intent with a given action. All other fields (data, type,
2030 * class) are null. Note that the action <em>must</em> be in a
2031 * namespace because Intents are used globally in the system -- for
2032 * example the system VIEW action is android.intent.action.VIEW; an
2033 * application's custom action would be something like
2034 * com.google.app.myapp.CUSTOM_ACTION.
2035 *
2036 * @param action The Intent action, such as ACTION_VIEW.
2037 */
2038 public Intent(String action) {
2039 mAction = action;
2040 }
2041
2042 /**
2043 * Create an intent with a given action and for a given data url. Note
2044 * that the action <em>must</em> be in a namespace because Intents are
2045 * used globally in the system -- for example the system VIEW action is
2046 * android.intent.action.VIEW; an application's custom action would be
2047 * something like com.google.app.myapp.CUSTOM_ACTION.
2048 *
2049 * @param action The Intent action, such as ACTION_VIEW.
2050 * @param uri The Intent data URI.
2051 */
2052 public Intent(String action, Uri uri) {
2053 mAction = action;
2054 mData = uri;
2055 }
2056
2057 /**
2058 * Create an intent for a specific component. All other fields (action, data,
2059 * type, class) are null, though they can be modified later with explicit
2060 * calls. This provides a convenient way to create an intent that is
2061 * intended to execute a hard-coded class name, rather than relying on the
2062 * system to find an appropriate class for you; see {@link #setComponent}
2063 * for more information on the repercussions of this.
2064 *
2065 * @param packageContext A Context of the application package implementing
2066 * this class.
2067 * @param cls The component class that is to be used for the intent.
2068 *
2069 * @see #setClass
2070 * @see #setComponent
2071 * @see #Intent(String, android.net.Uri , Context, Class)
2072 */
2073 public Intent(Context packageContext, Class<?> cls) {
2074 mComponent = new ComponentName(packageContext, cls);
2075 }
2076
2077 /**
2078 * Create an intent for a specific component with a specified action and data.
2079 * This is equivalent using {@link #Intent(String, android.net.Uri)} to
2080 * construct the Intent and then calling {@link #setClass} to set its
2081 * class.
2082 *
2083 * @param action The Intent action, such as ACTION_VIEW.
2084 * @param uri The Intent data URI.
2085 * @param packageContext A Context of the application package implementing
2086 * this class.
2087 * @param cls The component class that is to be used for the intent.
2088 *
2089 * @see #Intent(String, android.net.Uri)
2090 * @see #Intent(Context, Class)
2091 * @see #setClass
2092 * @see #setComponent
2093 */
2094 public Intent(String action, Uri uri,
2095 Context packageContext, Class<?> cls) {
2096 mAction = action;
2097 mData = uri;
2098 mComponent = new ComponentName(packageContext, cls);
2099 }
2100
2101 /**
2102 * Create an intent from a URI. This URI may encode the action,
2103 * category, and other intent fields, if it was returned by toURI(). If
2104 * the Intent was not generate by toURI(), its data will be the entire URI
2105 * and its action will be ACTION_VIEW.
2106 *
2107 * <p>The URI given here must not be relative -- that is, it must include
2108 * the scheme and full path.
2109 *
2110 * @param uri The URI to turn into an Intent.
2111 *
2112 * @return Intent The newly created Intent object.
2113 *
2114 * @see #toURI
2115 */
2116 public static Intent getIntent(String uri) throws URISyntaxException {
2117 int i = 0;
2118 try {
2119 // simple case
2120 i = uri.lastIndexOf("#");
2121 if (i == -1) return new Intent(ACTION_VIEW, Uri.parse(uri));
2122
2123 // old format Intent URI
2124 if (!uri.startsWith("#Intent;", i)) return getIntentOld(uri);
2125
2126 // new format
2127 Intent intent = new Intent(ACTION_VIEW);
2128
2129 // fetch data part, if present
2130 if (i > 0) {
2131 intent.mData = Uri.parse(uri.substring(0, i));
2132 }
2133 i += "#Intent;".length();
2134
2135 // loop over contents of Intent, all name=value;
2136 while (!uri.startsWith("end", i)) {
2137 int eq = uri.indexOf('=', i);
2138 int semi = uri.indexOf(';', eq);
2139 String value = uri.substring(eq + 1, semi);
2140
2141 // action
2142 if (uri.startsWith("action=", i)) {
2143 intent.mAction = value;
2144 }
2145
2146 // categories
2147 else if (uri.startsWith("category=", i)) {
2148 intent.addCategory(value);
2149 }
2150
2151 // type
2152 else if (uri.startsWith("type=", i)) {
2153 intent.mType = value;
2154 }
2155
2156 // launch flags
2157 else if (uri.startsWith("launchFlags=", i)) {
2158 intent.mFlags = Integer.decode(value).intValue();
2159 }
2160
2161 // component
2162 else if (uri.startsWith("component=", i)) {
2163 intent.mComponent = ComponentName.unflattenFromString(value);
2164 }
2165
2166 // extra
2167 else {
2168 String key = Uri.decode(uri.substring(i + 2, eq));
2169 value = Uri.decode(value);
2170 // create Bundle if it doesn't already exist
2171 if (intent.mExtras == null) intent.mExtras = new Bundle();
2172 Bundle b = intent.mExtras;
2173 // add EXTRA
2174 if (uri.startsWith("S.", i)) b.putString(key, value);
2175 else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
2176 else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
2177 else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
2178 else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
2179 else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
2180 else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
2181 else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
2182 else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
2183 else throw new URISyntaxException(uri, "unknown EXTRA type", i);
2184 }
2185
2186 // move to the next item
2187 i = semi + 1;
2188 }
2189
2190 return intent;
2191
2192 } catch (IndexOutOfBoundsException e) {
2193 throw new URISyntaxException(uri, "illegal Intent URI format", i);
2194 }
2195 }
2196
2197 public static Intent getIntentOld(String uri) throws URISyntaxException {
2198 Intent intent;
2199
2200 int i = uri.lastIndexOf('#');
2201 if (i >= 0) {
2202 Uri data = null;
2203 String action = null;
2204 if (i > 0) {
2205 data = Uri.parse(uri.substring(0, i));
2206 }
2207
2208 i++;
2209
2210 if (uri.regionMatches(i, "action(", 0, 7)) {
2211 i += 7;
2212 int j = uri.indexOf(')', i);
2213 action = uri.substring(i, j);
2214 i = j + 1;
2215 }
2216
2217 intent = new Intent(action, data);
2218
2219 if (uri.regionMatches(i, "categories(", 0, 11)) {
2220 i += 11;
2221 int j = uri.indexOf(')', i);
2222 while (i < j) {
2223 int sep = uri.indexOf('!', i);
2224 if (sep < 0) sep = j;
2225 if (i < sep) {
2226 intent.addCategory(uri.substring(i, sep));
2227 }
2228 i = sep + 1;
2229 }
2230 i = j + 1;
2231 }
2232
2233 if (uri.regionMatches(i, "type(", 0, 5)) {
2234 i += 5;
2235 int j = uri.indexOf(')', i);
2236 intent.mType = uri.substring(i, j);
2237 i = j + 1;
2238 }
2239
2240 if (uri.regionMatches(i, "launchFlags(", 0, 12)) {
2241 i += 12;
2242 int j = uri.indexOf(')', i);
2243 intent.mFlags = Integer.decode(uri.substring(i, j)).intValue();
2244 i = j + 1;
2245 }
2246
2247 if (uri.regionMatches(i, "component(", 0, 10)) {
2248 i += 10;
2249 int j = uri.indexOf(')', i);
2250 int sep = uri.indexOf('!', i);
2251 if (sep >= 0 && sep < j) {
2252 String pkg = uri.substring(i, sep);
2253 String cls = uri.substring(sep + 1, j);
2254 intent.mComponent = new ComponentName(pkg, cls);
2255 }
2256 i = j + 1;
2257 }
2258
2259 if (uri.regionMatches(i, "extras(", 0, 7)) {
2260 i += 7;
2261
2262 final int closeParen = uri.indexOf(')', i);
2263 if (closeParen == -1) throw new URISyntaxException(uri,
2264 "EXTRA missing trailing ')'", i);
2265
2266 while (i < closeParen) {
2267 // fetch the key value
2268 int j = uri.indexOf('=', i);
2269 if (j <= i + 1 || i >= closeParen) {
2270 throw new URISyntaxException(uri, "EXTRA missing '='", i);
2271 }
2272 char type = uri.charAt(i);
2273 i++;
2274 String key = uri.substring(i, j);
2275 i = j + 1;
2276
2277 // get type-value
2278 j = uri.indexOf('!', i);
2279 if (j == -1 || j >= closeParen) j = closeParen;
2280 if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2281 String value = uri.substring(i, j);
2282 i = j;
2283
2284 // create Bundle if it doesn't already exist
2285 if (intent.mExtras == null) intent.mExtras = new Bundle();
2286
2287 // add item to bundle
2288 try {
2289 switch (type) {
2290 case 'S':
2291 intent.mExtras.putString(key, Uri.decode(value));
2292 break;
2293 case 'B':
2294 intent.mExtras.putBoolean(key, Boolean.parseBoolean(value));
2295 break;
2296 case 'b':
2297 intent.mExtras.putByte(key, Byte.parseByte(value));
2298 break;
2299 case 'c':
2300 intent.mExtras.putChar(key, Uri.decode(value).charAt(0));
2301 break;
2302 case 'd':
2303 intent.mExtras.putDouble(key, Double.parseDouble(value));
2304 break;
2305 case 'f':
2306 intent.mExtras.putFloat(key, Float.parseFloat(value));
2307 break;
2308 case 'i':
2309 intent.mExtras.putInt(key, Integer.parseInt(value));
2310 break;
2311 case 'l':
2312 intent.mExtras.putLong(key, Long.parseLong(value));
2313 break;
2314 case 's':
2315 intent.mExtras.putShort(key, Short.parseShort(value));
2316 break;
2317 default:
2318 throw new URISyntaxException(uri, "EXTRA has unknown type", i);
2319 }
2320 } catch (NumberFormatException e) {
2321 throw new URISyntaxException(uri, "EXTRA value can't be parsed", i);
2322 }
2323
2324 char ch = uri.charAt(i);
2325 if (ch == ')') break;
2326 if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2327 i++;
2328 }
2329 }
2330
2331 if (intent.mAction == null) {
2332 // By default, if no action is specified, then use VIEW.
2333 intent.mAction = ACTION_VIEW;
2334 }
2335
2336 } else {
2337 intent = new Intent(ACTION_VIEW, Uri.parse(uri));
2338 }
2339
2340 return intent;
2341 }
2342
2343 /**
2344 * Retrieve the general action to be performed, such as
2345 * {@link #ACTION_VIEW}. The action describes the general way the rest of
2346 * the information in the intent should be interpreted -- most importantly,
2347 * what to do with the data returned by {@link #getData}.
2348 *
2349 * @return The action of this intent or null if none is specified.
2350 *
2351 * @see #setAction
2352 */
2353 public String getAction() {
2354 return mAction;
2355 }
2356
2357 /**
2358 * Retrieve data this intent is operating on. This URI specifies the name
2359 * of the data; often it uses the content: scheme, specifying data in a
2360 * content provider. Other schemes may be handled by specific activities,
2361 * such as http: by the web browser.
2362 *
2363 * @return The URI of the data this intent is targeting or null.
2364 *
2365 * @see #getScheme
2366 * @see #setData
2367 */
2368 public Uri getData() {
2369 return mData;
2370 }
2371
2372 /**
2373 * The same as {@link #getData()}, but returns the URI as an encoded
2374 * String.
2375 */
2376 public String getDataString() {
2377 return mData != null ? mData.toString() : null;
2378 }
2379
2380 /**
2381 * Return the scheme portion of the intent's data. If the data is null or
2382 * does not include a scheme, null is returned. Otherwise, the scheme
2383 * prefix without the final ':' is returned, i.e. "http".
2384 *
2385 * <p>This is the same as calling getData().getScheme() (and checking for
2386 * null data).
2387 *
2388 * @return The scheme of this intent.
2389 *
2390 * @see #getData
2391 */
2392 public String getScheme() {
2393 return mData != null ? mData.getScheme() : null;
2394 }
2395
2396 /**
2397 * Retrieve any explicit MIME type included in the intent. This is usually
2398 * null, as the type is determined by the intent data.
2399 *
2400 * @return If a type was manually set, it is returned; else null is
2401 * returned.
2402 *
2403 * @see #resolveType(ContentResolver)
2404 * @see #setType
2405 */
2406 public String getType() {
2407 return mType;
2408 }
2409
2410 /**
2411 * Return the MIME data type of this intent. If the type field is
2412 * explicitly set, that is simply returned. Otherwise, if the data is set,
2413 * the type of that data is returned. If neither fields are set, a null is
2414 * returned.
2415 *
2416 * @return The MIME type of this intent.
2417 *
2418 * @see #getType
2419 * @see #resolveType(ContentResolver)
2420 */
2421 public String resolveType(Context context) {
2422 return resolveType(context.getContentResolver());
2423 }
2424
2425 /**
2426 * Return the MIME data type of this intent. If the type field is
2427 * explicitly set, that is simply returned. Otherwise, if the data is set,
2428 * the type of that data is returned. If neither fields are set, a null is
2429 * returned.
2430 *
2431 * @param resolver A ContentResolver that can be used to determine the MIME
2432 * type of the intent's data.
2433 *
2434 * @return The MIME type of this intent.
2435 *
2436 * @see #getType
2437 * @see #resolveType(Context)
2438 */
2439 public String resolveType(ContentResolver resolver) {
2440 if (mType != null) {
2441 return mType;
2442 }
2443 if (mData != null) {
2444 if ("content".equals(mData.getScheme())) {
2445 return resolver.getType(mData);
2446 }
2447 }
2448 return null;
2449 }
2450
2451 /**
2452 * Return the MIME data type of this intent, only if it will be needed for
2453 * intent resolution. This is not generally useful for application code;
2454 * it is used by the frameworks for communicating with back-end system
2455 * services.
2456 *
2457 * @param resolver A ContentResolver that can be used to determine the MIME
2458 * type of the intent's data.
2459 *
2460 * @return The MIME type of this intent, or null if it is unknown or not
2461 * needed.
2462 */
2463 public String resolveTypeIfNeeded(ContentResolver resolver) {
2464 if (mComponent != null) {
2465 return mType;
2466 }
2467 return resolveType(resolver);
2468 }
2469
2470 /**
2471 * Check if an category exists in the intent.
2472 *
2473 * @param category The category to check.
2474 *
2475 * @return boolean True if the intent contains the category, else false.
2476 *
2477 * @see #getCategories
2478 * @see #addCategory
2479 */
2480 public boolean hasCategory(String category) {
2481 return mCategories != null && mCategories.contains(category);
2482 }
2483
2484 /**
2485 * Return the set of all categories in the intent. If there are no categories,
2486 * returns NULL.
2487 *
2488 * @return Set The set of categories you can examine. Do not modify!
2489 *
2490 * @see #hasCategory
2491 * @see #addCategory
2492 */
2493 public Set<String> getCategories() {
2494 return mCategories;
2495 }
2496
2497 /**
2498 * Sets the ClassLoader that will be used when unmarshalling
2499 * any Parcelable values from the extras of this Intent.
2500 *
2501 * @param loader a ClassLoader, or null to use the default loader
2502 * at the time of unmarshalling.
2503 */
2504 public void setExtrasClassLoader(ClassLoader loader) {
2505 if (mExtras != null) {
2506 mExtras.setClassLoader(loader);
2507 }
2508 }
2509
2510 /**
2511 * Returns true if an extra value is associated with the given name.
2512 * @param name the extra's name
2513 * @return true if the given extra is present.
2514 */
2515 public boolean hasExtra(String name) {
2516 return mExtras != null && mExtras.containsKey(name);
2517 }
2518
2519 /**
2520 * Returns true if the Intent's extras contain a parcelled file descriptor.
2521 * @return true if the Intent contains a parcelled file descriptor.
2522 */
2523 public boolean hasFileDescriptors() {
2524 return mExtras != null && mExtras.hasFileDescriptors();
2525 }
2526
2527 /**
2528 * Retrieve extended data from the intent.
2529 *
2530 * @param name The name of the desired item.
2531 *
2532 * @return the value of an item that previously added with putExtra()
2533 * or null if none was found.
2534 *
2535 * @deprecated
2536 * @hide
2537 */
2538 @Deprecated
2539 public Object getExtra(String name) {
2540 return getExtra(name, null);
2541 }
2542
2543 /**
2544 * Retrieve extended data from the intent.
2545 *
2546 * @param name The name of the desired item.
2547 * @param defaultValue the value to be returned if no value of the desired
2548 * type is stored with the given name.
2549 *
2550 * @return the value of an item that previously added with putExtra()
2551 * or the default value if none was found.
2552 *
2553 * @see #putExtra(String, boolean)
2554 */
2555 public boolean getBooleanExtra(String name, boolean defaultValue) {
2556 return mExtras == null ? defaultValue :
2557 mExtras.getBoolean(name, defaultValue);
2558 }
2559
2560 /**
2561 * Retrieve extended data from the intent.
2562 *
2563 * @param name The name of the desired item.
2564 * @param defaultValue the value to be returned if no value of the desired
2565 * type is stored with the given name.
2566 *
2567 * @return the value of an item that previously added with putExtra()
2568 * or the default value if none was found.
2569 *
2570 * @see #putExtra(String, byte)
2571 */
2572 public byte getByteExtra(String name, byte defaultValue) {
2573 return mExtras == null ? defaultValue :
2574 mExtras.getByte(name, defaultValue);
2575 }
2576
2577 /**
2578 * Retrieve extended data from the intent.
2579 *
2580 * @param name The name of the desired item.
2581 * @param defaultValue the value to be returned if no value of the desired
2582 * type is stored with the given name.
2583 *
2584 * @return the value of an item that previously added with putExtra()
2585 * or the default value if none was found.
2586 *
2587 * @see #putExtra(String, short)
2588 */
2589 public short getShortExtra(String name, short defaultValue) {
2590 return mExtras == null ? defaultValue :
2591 mExtras.getShort(name, defaultValue);
2592 }
2593
2594 /**
2595 * Retrieve extended data from the intent.
2596 *
2597 * @param name The name of the desired item.
2598 * @param defaultValue the value to be returned if no value of the desired
2599 * type is stored with the given name.
2600 *
2601 * @return the value of an item that previously added with putExtra()
2602 * or the default value if none was found.
2603 *
2604 * @see #putExtra(String, char)
2605 */
2606 public char getCharExtra(String name, char defaultValue) {
2607 return mExtras == null ? defaultValue :
2608 mExtras.getChar(name, defaultValue);
2609 }
2610
2611 /**
2612 * Retrieve extended data from the intent.
2613 *
2614 * @param name The name of the desired item.
2615 * @param defaultValue the value to be returned if no value of the desired
2616 * type is stored with the given name.
2617 *
2618 * @return the value of an item that previously added with putExtra()
2619 * or the default value if none was found.
2620 *
2621 * @see #putExtra(String, int)
2622 */
2623 public int getIntExtra(String name, int defaultValue) {
2624 return mExtras == null ? defaultValue :
2625 mExtras.getInt(name, defaultValue);
2626 }
2627
2628 /**
2629 * Retrieve extended data from the intent.
2630 *
2631 * @param name The name of the desired item.
2632 * @param defaultValue the value to be returned if no value of the desired
2633 * type is stored with the given name.
2634 *
2635 * @return the value of an item that previously added with putExtra()
2636 * or the default value if none was found.
2637 *
2638 * @see #putExtra(String, long)
2639 */
2640 public long getLongExtra(String name, long defaultValue) {
2641 return mExtras == null ? defaultValue :
2642 mExtras.getLong(name, defaultValue);
2643 }
2644
2645 /**
2646 * Retrieve extended data from the intent.
2647 *
2648 * @param name The name of the desired item.
2649 * @param defaultValue the value to be returned if no value of the desired
2650 * type is stored with the given name.
2651 *
2652 * @return the value of an item that previously added with putExtra(),
2653 * or the default value if no such item is present
2654 *
2655 * @see #putExtra(String, float)
2656 */
2657 public float getFloatExtra(String name, float defaultValue) {
2658 return mExtras == null ? defaultValue :
2659 mExtras.getFloat(name, defaultValue);
2660 }
2661
2662 /**
2663 * Retrieve extended data from the intent.
2664 *
2665 * @param name The name of the desired item.
2666 * @param defaultValue the value to be returned if no value of the desired
2667 * type is stored with the given name.
2668 *
2669 * @return the value of an item that previously added with putExtra()
2670 * or the default value if none was found.
2671 *
2672 * @see #putExtra(String, double)
2673 */
2674 public double getDoubleExtra(String name, double defaultValue) {
2675 return mExtras == null ? defaultValue :
2676 mExtras.getDouble(name, defaultValue);
2677 }
2678
2679 /**
2680 * Retrieve extended data from the intent.
2681 *
2682 * @param name The name of the desired item.
2683 *
2684 * @return the value of an item that previously added with putExtra()
2685 * or null if no String value was found.
2686 *
2687 * @see #putExtra(String, String)
2688 */
2689 public String getStringExtra(String name) {
2690 return mExtras == null ? null : mExtras.getString(name);
2691 }
2692
2693 /**
2694 * Retrieve extended data from the intent.
2695 *
2696 * @param name The name of the desired item.
2697 *
2698 * @return the value of an item that previously added with putExtra()
2699 * or null if no CharSequence value was found.
2700 *
2701 * @see #putExtra(String, CharSequence)
2702 */
2703 public CharSequence getCharSequenceExtra(String name) {
2704 return mExtras == null ? null : mExtras.getCharSequence(name);
2705 }
2706
2707 /**
2708 * Retrieve extended data from the intent.
2709 *
2710 * @param name The name of the desired item.
2711 *
2712 * @return the value of an item that previously added with putExtra()
2713 * or null if no Parcelable value was found.
2714 *
2715 * @see #putExtra(String, Parcelable)
2716 */
2717 public <T extends Parcelable> T getParcelableExtra(String name) {
2718 return mExtras == null ? null : mExtras.<T>getParcelable(name);
2719 }
2720
2721 /**
2722 * Retrieve extended data from the intent.
2723 *
2724 * @param name The name of the desired item.
2725 *
2726 * @return the value of an item that previously added with putExtra()
2727 * or null if no Parcelable[] value was found.
2728 *
2729 * @see #putExtra(String, Parcelable[])
2730 */
2731 public Parcelable[] getParcelableArrayExtra(String name) {
2732 return mExtras == null ? null : mExtras.getParcelableArray(name);
2733 }
2734
2735 /**
2736 * Retrieve extended data from the intent.
2737 *
2738 * @param name The name of the desired item.
2739 *
2740 * @return the value of an item that previously added with putExtra()
2741 * or null if no ArrayList<Parcelable> value was found.
2742 *
2743 * @see #putParcelableArrayListExtra(String, ArrayList)
2744 */
2745 public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
2746 return mExtras == null ? null : mExtras.<T>getParcelableArrayList(name);
2747 }
2748
2749 /**
2750 * Retrieve extended data from the intent.
2751 *
2752 * @param name The name of the desired item.
2753 *
2754 * @return the value of an item that previously added with putExtra()
2755 * or null if no Serializable value was found.
2756 *
2757 * @see #putExtra(String, Serializable)
2758 */
2759 public Serializable getSerializableExtra(String name) {
2760 return mExtras == null ? null : mExtras.getSerializable(name);
2761 }
2762
2763 /**
2764 * Retrieve extended data from the intent.
2765 *
2766 * @param name The name of the desired item.
2767 *
2768 * @return the value of an item that previously added with putExtra()
2769 * or null if no ArrayList<Integer> value was found.
2770 *
2771 * @see #putIntegerArrayListExtra(String, ArrayList)
2772 */
2773 public ArrayList<Integer> getIntegerArrayListExtra(String name) {
2774 return mExtras == null ? null : mExtras.getIntegerArrayList(name);
2775 }
2776
2777 /**
2778 * Retrieve extended data from the intent.
2779 *
2780 * @param name The name of the desired item.
2781 *
2782 * @return the value of an item that previously added with putExtra()
2783 * or null if no ArrayList<String> value was found.
2784 *
2785 * @see #putStringArrayListExtra(String, ArrayList)
2786 */
2787 public ArrayList<String> getStringArrayListExtra(String name) {
2788 return mExtras == null ? null : mExtras.getStringArrayList(name);
2789 }
2790
2791 /**
2792 * Retrieve extended data from the intent.
2793 *
2794 * @param name The name of the desired item.
2795 *
2796 * @return the value of an item that previously added with putExtra()
2797 * or null if no boolean array value was found.
2798 *
2799 * @see #putExtra(String, boolean[])
2800 */
2801 public boolean[] getBooleanArrayExtra(String name) {
2802 return mExtras == null ? null : mExtras.getBooleanArray(name);
2803 }
2804
2805 /**
2806 * Retrieve extended data from the intent.
2807 *
2808 * @param name The name of the desired item.
2809 *
2810 * @return the value of an item that previously added with putExtra()
2811 * or null if no byte array value was found.
2812 *
2813 * @see #putExtra(String, byte[])
2814 */
2815 public byte[] getByteArrayExtra(String name) {
2816 return mExtras == null ? null : mExtras.getByteArray(name);
2817 }
2818
2819 /**
2820 * Retrieve extended data from the intent.
2821 *
2822 * @param name The name of the desired item.
2823 *
2824 * @return the value of an item that previously added with putExtra()
2825 * or null if no short array value was found.
2826 *
2827 * @see #putExtra(String, short[])
2828 */
2829 public short[] getShortArrayExtra(String name) {
2830 return mExtras == null ? null : mExtras.getShortArray(name);
2831 }
2832
2833 /**
2834 * Retrieve extended data from the intent.
2835 *
2836 * @param name The name of the desired item.
2837 *
2838 * @return the value of an item that previously added with putExtra()
2839 * or null if no char array value was found.
2840 *
2841 * @see #putExtra(String, char[])
2842 */
2843 public char[] getCharArrayExtra(String name) {
2844 return mExtras == null ? null : mExtras.getCharArray(name);
2845 }
2846
2847 /**
2848 * Retrieve extended data from the intent.
2849 *
2850 * @param name The name of the desired item.
2851 *
2852 * @return the value of an item that previously added with putExtra()
2853 * or null if no int array value was found.
2854 *
2855 * @see #putExtra(String, int[])
2856 */
2857 public int[] getIntArrayExtra(String name) {
2858 return mExtras == null ? null : mExtras.getIntArray(name);
2859 }
2860
2861 /**
2862 * Retrieve extended data from the intent.
2863 *
2864 * @param name The name of the desired item.
2865 *
2866 * @return the value of an item that previously added with putExtra()
2867 * or null if no long array value was found.
2868 *
2869 * @see #putExtra(String, long[])
2870 */
2871 public long[] getLongArrayExtra(String name) {
2872 return mExtras == null ? null : mExtras.getLongArray(name);
2873 }
2874
2875 /**
2876 * Retrieve extended data from the intent.
2877 *
2878 * @param name The name of the desired item.
2879 *
2880 * @return the value of an item that previously added with putExtra()
2881 * or null if no float array value was found.
2882 *
2883 * @see #putExtra(String, float[])
2884 */
2885 public float[] getFloatArrayExtra(String name) {
2886 return mExtras == null ? null : mExtras.getFloatArray(name);
2887 }
2888
2889 /**
2890 * Retrieve extended data from the intent.
2891 *
2892 * @param name The name of the desired item.
2893 *
2894 * @return the value of an item that previously added with putExtra()
2895 * or null if no double array value was found.
2896 *
2897 * @see #putExtra(String, double[])
2898 */
2899 public double[] getDoubleArrayExtra(String name) {
2900 return mExtras == null ? null : mExtras.getDoubleArray(name);
2901 }
2902
2903 /**
2904 * Retrieve extended data from the intent.
2905 *
2906 * @param name The name of the desired item.
2907 *
2908 * @return the value of an item that previously added with putExtra()
2909 * or null if no String array value was found.
2910 *
2911 * @see #putExtra(String, String[])
2912 */
2913 public String[] getStringArrayExtra(String name) {
2914 return mExtras == null ? null : mExtras.getStringArray(name);
2915 }
2916
2917 /**
2918 * Retrieve extended data from the intent.
2919 *
2920 * @param name The name of the desired item.
2921 *
2922 * @return the value of an item that previously added with putExtra()
2923 * or null if no Bundle value was found.
2924 *
2925 * @see #putExtra(String, Bundle)
2926 */
2927 public Bundle getBundleExtra(String name) {
2928 return mExtras == null ? null : mExtras.getBundle(name);
2929 }
2930
2931 /**
2932 * Retrieve extended data from the intent.
2933 *
2934 * @param name The name of the desired item.
2935 *
2936 * @return the value of an item that previously added with putExtra()
2937 * or null if no IBinder value was found.
2938 *
2939 * @see #putExtra(String, IBinder)
2940 *
2941 * @deprecated
2942 * @hide
2943 */
2944 @Deprecated
2945 public IBinder getIBinderExtra(String name) {
2946 return mExtras == null ? null : mExtras.getIBinder(name);
2947 }
2948
2949 /**
2950 * Retrieve extended data from the intent.
2951 *
2952 * @param name The name of the desired item.
2953 * @param defaultValue The default value to return in case no item is
2954 * associated with the key 'name'
2955 *
2956 * @return the value of an item that previously added with putExtra()
2957 * or defaultValue if none was found.
2958 *
2959 * @see #putExtra
2960 *
2961 * @deprecated
2962 * @hide
2963 */
2964 @Deprecated
2965 public Object getExtra(String name, Object defaultValue) {
2966 Object result = defaultValue;
2967 if (mExtras != null) {
2968 Object result2 = mExtras.get(name);
2969 if (result2 != null) {
2970 result = result2;
2971 }
2972 }
2973
2974 return result;
2975 }
2976
2977 /**
2978 * Retrieves a map of extended data from the intent.
2979 *
2980 * @return the map of all extras previously added with putExtra(),
2981 * or null if none have been added.
2982 */
2983 public Bundle getExtras() {
2984 return (mExtras != null)
2985 ? new Bundle(mExtras)
2986 : null;
2987 }
2988
2989 /**
2990 * Retrieve any special flags associated with this intent. You will
2991 * normally just set them with {@link #setFlags} and let the system
2992 * take the appropriate action with them.
2993 *
2994 * @return int The currently set flags.
2995 *
2996 * @see #setFlags
2997 */
2998 public int getFlags() {
2999 return mFlags;
3000 }
3001
3002 /**
3003 * Retrieve the concrete component associated with the intent. When receiving
3004 * an intent, this is the component that was found to best handle it (that is,
3005 * yourself) and will always be non-null; in all other cases it will be
3006 * null unless explicitly set.
3007 *
3008 * @return The name of the application component to handle the intent.
3009 *
3010 * @see #resolveActivity
3011 * @see #setComponent
3012 */
3013 public ComponentName getComponent() {
3014 return mComponent;
3015 }
3016
3017 /**
3018 * Return the Activity component that should be used to handle this intent.
3019 * The appropriate component is determined based on the information in the
3020 * intent, evaluated as follows:
3021 *
3022 * <p>If {@link #getComponent} returns an explicit class, that is returned
3023 * without any further consideration.
3024 *
3025 * <p>The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent
3026 * category to be considered.
3027 *
3028 * <p>If {@link #getAction} is non-NULL, the activity must handle this
3029 * action.
3030 *
3031 * <p>If {@link #resolveType} returns non-NULL, the activity must handle
3032 * this type.
3033 *
3034 * <p>If {@link #addCategory} has added any categories, the activity must
3035 * handle ALL of the categories specified.
3036 *
3037 * <p>If there are no activities that satisfy all of these conditions, a
3038 * null string is returned.
3039 *
3040 * <p>If multiple activities are found to satisfy the intent, the one with
3041 * the highest priority will be used. If there are multiple activities
3042 * with the same priority, the system will either pick the best activity
3043 * based on user preference, or resolve to a system class that will allow
3044 * the user to pick an activity and forward from there.
3045 *
3046 * <p>This method is implemented simply by calling
3047 * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter
3048 * true.</p>
3049 * <p> This API is called for you as part of starting an activity from an
3050 * intent. You do not normally need to call it yourself.</p>
3051 *
3052 * @param pm The package manager with which to resolve the Intent.
3053 *
3054 * @return Name of the component implementing an activity that can
3055 * display the intent.
3056 *
3057 * @see #setComponent
3058 * @see #getComponent
3059 * @see #resolveActivityInfo
3060 */
3061 public ComponentName resolveActivity(PackageManager pm) {
3062 if (mComponent != null) {
3063 return mComponent;
3064 }
3065
3066 ResolveInfo info = pm.resolveActivity(
3067 this, PackageManager.MATCH_DEFAULT_ONLY);
3068 if (info != null) {
3069 return new ComponentName(
3070 info.activityInfo.applicationInfo.packageName,
3071 info.activityInfo.name);
3072 }
3073
3074 return null;
3075 }
3076
3077 /**
3078 * Resolve the Intent into an {@link ActivityInfo}
3079 * describing the activity that should execute the intent. Resolution
3080 * follows the same rules as described for {@link #resolveActivity}, but
3081 * you get back the completely information about the resolved activity
3082 * instead of just its class name.
3083 *
3084 * @param pm The package manager with which to resolve the Intent.
3085 * @param flags Addition information to retrieve as per
3086 * {@link PackageManager#getActivityInfo(ComponentName, int)
3087 * PackageManager.getActivityInfo()}.
3088 *
3089 * @return PackageManager.ActivityInfo
3090 *
3091 * @see #resolveActivity
3092 */
3093 public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) {
3094 ActivityInfo ai = null;
3095 if (mComponent != null) {
3096 try {
3097 ai = pm.getActivityInfo(mComponent, flags);
3098 } catch (PackageManager.NameNotFoundException e) {
3099 // ignore
3100 }
3101 } else {
3102 ResolveInfo info = pm.resolveActivity(
3103 this, PackageManager.MATCH_DEFAULT_ONLY);
3104 if (info != null) {
3105 ai = info.activityInfo;
3106 }
3107 }
3108
3109 return ai;
3110 }
3111
3112 /**
3113 * Set the general action to be performed.
3114 *
3115 * @param action An action name, such as ACTION_VIEW. Application-specific
3116 * actions should be prefixed with the vendor's package name.
3117 *
3118 * @return Returns the same Intent object, for chaining multiple calls
3119 * into a single statement.
3120 *
3121 * @see #getAction
3122 */
3123 public Intent setAction(String action) {
3124 mAction = action;
3125 return this;
3126 }
3127
3128 /**
3129 * Set the data this intent is operating on. This method automatically
3130 * clears any type that was previously set by {@link #setType}.
3131 *
3132 * @param data The URI of the data this intent is now targeting.
3133 *
3134 * @return Returns the same Intent object, for chaining multiple calls
3135 * into a single statement.
3136 *
3137 * @see #getData
3138 * @see #setType
3139 * @see #setDataAndType
3140 */
3141 public Intent setData(Uri data) {
3142 mData = data;
3143 mType = null;
3144 return this;
3145 }
3146
3147 /**
3148 * Set an explicit MIME data type. This is used to create intents that
3149 * only specify a type and not data, for example to indicate the type of
3150 * data to return. This method automatically clears any data that was
3151 * previously set by {@link #setData}.
3152 *
3153 * @param type The MIME type of the data being handled by this intent.
3154 *
3155 * @return Returns the same Intent object, for chaining multiple calls
3156 * into a single statement.
3157 *
3158 * @see #getType
3159 * @see #setData
3160 * @see #setDataAndType
3161 */
3162 public Intent setType(String type) {
3163 mData = null;
3164 mType = type;
3165 return this;
3166 }
3167
3168 /**
3169 * (Usually optional) Set the data for the intent along with an explicit
3170 * MIME data type. This method should very rarely be used -- it allows you
3171 * to override the MIME type that would ordinarily be inferred from the
3172 * data with your own type given here.
3173 *
3174 * @param data The URI of the data this intent is now targeting.
3175 * @param type The MIME type of the data being handled by this intent.
3176 *
3177 * @return Returns the same Intent object, for chaining multiple calls
3178 * into a single statement.
3179 *
3180 * @see #setData
3181 * @see #setType
3182 */
3183 public Intent setDataAndType(Uri data, String type) {
3184 mData = data;
3185 mType = type;
3186 return this;
3187 }
3188
3189 /**
3190 * Add a new category to the intent. Categories provide additional detail
3191 * about the action the intent is perform. When resolving an intent, only
3192 * activities that provide <em>all</em> of the requested categories will be
3193 * used.
3194 *
3195 * @param category The desired category. This can be either one of the
3196 * predefined Intent categories, or a custom category in your own
3197 * namespace.
3198 *
3199 * @return Returns the same Intent object, for chaining multiple calls
3200 * into a single statement.
3201 *
3202 * @see #hasCategory
3203 * @see #removeCategory
3204 */
3205 public Intent addCategory(String category) {
3206 if (mCategories == null) {
3207 mCategories = new HashSet<String>();
3208 }
3209 mCategories.add(category);
3210 return this;
3211 }
3212
3213 /**
3214 * Remove an category from an intent.
3215 *
3216 * @param category The category to remove.
3217 *
3218 * @see #addCategory
3219 */
3220 public void removeCategory(String category) {
3221 if (mCategories != null) {
3222 mCategories.remove(category);
3223 if (mCategories.size() == 0) {
3224 mCategories = null;
3225 }
3226 }
3227 }
3228
3229 /**
3230 * Add extended data to the intent. The name must include a package
3231 * prefix, for example the app com.android.contacts would use names
3232 * like "com.android.contacts.ShowAll".
3233 *
3234 * @param name The name of the extra data, with package prefix.
3235 * @param value The boolean data value.
3236 *
3237 * @return Returns the same Intent object, for chaining multiple calls
3238 * into a single statement.
3239 *
3240 * @see #putExtras
3241 * @see #removeExtra
3242 * @see #getBooleanExtra(String, boolean)
3243 */
3244 public Intent putExtra(String name, boolean value) {
3245 if (mExtras == null) {
3246 mExtras = new Bundle();
3247 }
3248 mExtras.putBoolean(name, value);
3249 return this;
3250 }
3251
3252 /**
3253 * Add extended data to the intent. The name must include a package
3254 * prefix, for example the app com.android.contacts would use names
3255 * like "com.android.contacts.ShowAll".
3256 *
3257 * @param name The name of the extra data, with package prefix.
3258 * @param value The byte data value.
3259 *
3260 * @return Returns the same Intent object, for chaining multiple calls
3261 * into a single statement.
3262 *
3263 * @see #putExtras
3264 * @see #removeExtra
3265 * @see #getByteExtra(String, byte)
3266 */
3267 public Intent putExtra(String name, byte value) {
3268 if (mExtras == null) {
3269 mExtras = new Bundle();
3270 }
3271 mExtras.putByte(name, value);
3272 return this;
3273 }
3274
3275 /**
3276 * Add extended data to the intent. The name must include a package
3277 * prefix, for example the app com.android.contacts would use names
3278 * like "com.android.contacts.ShowAll".
3279 *
3280 * @param name The name of the extra data, with package prefix.
3281 * @param value The char data value.
3282 *
3283 * @return Returns the same Intent object, for chaining multiple calls
3284 * into a single statement.
3285 *
3286 * @see #putExtras
3287 * @see #removeExtra
3288 * @see #getCharExtra(String, char)
3289 */
3290 public Intent putExtra(String name, char value) {
3291 if (mExtras == null) {
3292 mExtras = new Bundle();
3293 }
3294 mExtras.putChar(name, value);
3295 return this;
3296 }
3297
3298 /**
3299 * Add extended data to the intent. The name must include a package
3300 * prefix, for example the app com.android.contacts would use names
3301 * like "com.android.contacts.ShowAll".
3302 *
3303 * @param name The name of the extra data, with package prefix.
3304 * @param value The short data value.
3305 *
3306 * @return Returns the same Intent object, for chaining multiple calls
3307 * into a single statement.
3308 *
3309 * @see #putExtras
3310 * @see #removeExtra
3311 * @see #getShortExtra(String, short)
3312 */
3313 public Intent putExtra(String name, short value) {
3314 if (mExtras == null) {
3315 mExtras = new Bundle();
3316 }
3317 mExtras.putShort(name, value);
3318 return this;
3319 }
3320
3321 /**
3322 * Add extended data to the intent. The name must include a package
3323 * prefix, for example the app com.android.contacts would use names
3324 * like "com.android.contacts.ShowAll".
3325 *
3326 * @param name The name of the extra data, with package prefix.
3327 * @param value The integer data value.
3328 *
3329 * @return Returns the same Intent object, for chaining multiple calls
3330 * into a single statement.
3331 *
3332 * @see #putExtras
3333 * @see #removeExtra
3334 * @see #getIntExtra(String, int)
3335 */
3336 public Intent putExtra(String name, int value) {
3337 if (mExtras == null) {
3338 mExtras = new Bundle();
3339 }
3340 mExtras.putInt(name, value);
3341 return this;
3342 }
3343
3344 /**
3345 * Add extended data to the intent. The name must include a package
3346 * prefix, for example the app com.android.contacts would use names
3347 * like "com.android.contacts.ShowAll".
3348 *
3349 * @param name The name of the extra data, with package prefix.
3350 * @param value The long data value.
3351 *
3352 * @return Returns the same Intent object, for chaining multiple calls
3353 * into a single statement.
3354 *
3355 * @see #putExtras
3356 * @see #removeExtra
3357 * @see #getLongExtra(String, long)
3358 */
3359 public Intent putExtra(String name, long value) {
3360 if (mExtras == null) {
3361 mExtras = new Bundle();
3362 }
3363 mExtras.putLong(name, value);
3364 return this;
3365 }
3366
3367 /**
3368 * Add extended data to the intent. The name must include a package
3369 * prefix, for example the app com.android.contacts would use names
3370 * like "com.android.contacts.ShowAll".
3371 *
3372 * @param name The name of the extra data, with package prefix.
3373 * @param value The float data value.
3374 *
3375 * @return Returns the same Intent object, for chaining multiple calls
3376 * into a single statement.
3377 *
3378 * @see #putExtras
3379 * @see #removeExtra
3380 * @see #getFloatExtra(String, float)
3381 */
3382 public Intent putExtra(String name, float value) {
3383 if (mExtras == null) {
3384 mExtras = new Bundle();
3385 }
3386 mExtras.putFloat(name, value);
3387 return this;
3388 }
3389
3390 /**
3391 * Add extended data to the intent. The name must include a package
3392 * prefix, for example the app com.android.contacts would use names
3393 * like "com.android.contacts.ShowAll".
3394 *
3395 * @param name The name of the extra data, with package prefix.
3396 * @param value The double data value.
3397 *
3398 * @return Returns the same Intent object, for chaining multiple calls
3399 * into a single statement.
3400 *
3401 * @see #putExtras
3402 * @see #removeExtra
3403 * @see #getDoubleExtra(String, double)
3404 */
3405 public Intent putExtra(String name, double value) {
3406 if (mExtras == null) {
3407 mExtras = new Bundle();
3408 }
3409 mExtras.putDouble(name, value);
3410 return this;
3411 }
3412
3413 /**
3414 * Add extended data to the intent. The name must include a package
3415 * prefix, for example the app com.android.contacts would use names
3416 * like "com.android.contacts.ShowAll".
3417 *
3418 * @param name The name of the extra data, with package prefix.
3419 * @param value The String data value.
3420 *
3421 * @return Returns the same Intent object, for chaining multiple calls
3422 * into a single statement.
3423 *
3424 * @see #putExtras
3425 * @see #removeExtra
3426 * @see #getStringExtra(String)
3427 */
3428 public Intent putExtra(String name, String value) {
3429 if (mExtras == null) {
3430 mExtras = new Bundle();
3431 }
3432 mExtras.putString(name, value);
3433 return this;
3434 }
3435
3436 /**
3437 * Add extended data to the intent. The name must include a package
3438 * prefix, for example the app com.android.contacts would use names
3439 * like "com.android.contacts.ShowAll".
3440 *
3441 * @param name The name of the extra data, with package prefix.
3442 * @param value The CharSequence data value.
3443 *
3444 * @return Returns the same Intent object, for chaining multiple calls
3445 * into a single statement.
3446 *
3447 * @see #putExtras
3448 * @see #removeExtra
3449 * @see #getCharSequenceExtra(String)
3450 */
3451 public Intent putExtra(String name, CharSequence value) {
3452 if (mExtras == null) {
3453 mExtras = new Bundle();
3454 }
3455 mExtras.putCharSequence(name, value);
3456 return this;
3457 }
3458
3459 /**
3460 * Add extended data to the intent. The name must include a package
3461 * prefix, for example the app com.android.contacts would use names
3462 * like "com.android.contacts.ShowAll".
3463 *
3464 * @param name The name of the extra data, with package prefix.
3465 * @param value The Parcelable data value.
3466 *
3467 * @return Returns the same Intent object, for chaining multiple calls
3468 * into a single statement.
3469 *
3470 * @see #putExtras
3471 * @see #removeExtra
3472 * @see #getParcelableExtra(String)
3473 */
3474 public Intent putExtra(String name, Parcelable value) {
3475 if (mExtras == null) {
3476 mExtras = new Bundle();
3477 }
3478 mExtras.putParcelable(name, value);
3479 return this;
3480 }
3481
3482 /**
3483 * Add extended data to the intent. The name must include a package
3484 * prefix, for example the app com.android.contacts would use names
3485 * like "com.android.contacts.ShowAll".
3486 *
3487 * @param name The name of the extra data, with package prefix.
3488 * @param value The Parcelable[] data value.
3489 *
3490 * @return Returns the same Intent object, for chaining multiple calls
3491 * into a single statement.
3492 *
3493 * @see #putExtras
3494 * @see #removeExtra
3495 * @see #getParcelableArrayExtra(String)
3496 */
3497 public Intent putExtra(String name, Parcelable[] value) {
3498 if (mExtras == null) {
3499 mExtras = new Bundle();
3500 }
3501 mExtras.putParcelableArray(name, value);
3502 return this;
3503 }
3504
3505 /**
3506 * Add extended data to the intent. The name must include a package
3507 * prefix, for example the app com.android.contacts would use names
3508 * like "com.android.contacts.ShowAll".
3509 *
3510 * @param name The name of the extra data, with package prefix.
3511 * @param value The ArrayList<Parcelable> data value.
3512 *
3513 * @return Returns the same Intent object, for chaining multiple calls
3514 * into a single statement.
3515 *
3516 * @see #putExtras
3517 * @see #removeExtra
3518 * @see #getParcelableArrayListExtra(String)
3519 */
3520 public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
3521 if (mExtras == null) {
3522 mExtras = new Bundle();
3523 }
3524 mExtras.putParcelableArrayList(name, value);
3525 return this;
3526 }
3527
3528 /**
3529 * Add extended data to the intent. The name must include a package
3530 * prefix, for example the app com.android.contacts would use names
3531 * like "com.android.contacts.ShowAll".
3532 *
3533 * @param name The name of the extra data, with package prefix.
3534 * @param value The ArrayList<Integer> data value.
3535 *
3536 * @return Returns the same Intent object, for chaining multiple calls
3537 * into a single statement.
3538 *
3539 * @see #putExtras
3540 * @see #removeExtra
3541 * @see #getIntegerArrayListExtra(String)
3542 */
3543 public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
3544 if (mExtras == null) {
3545 mExtras = new Bundle();
3546 }
3547 mExtras.putIntegerArrayList(name, value);
3548 return this;
3549 }
3550
3551 /**
3552 * Add extended data to the intent. The name must include a package
3553 * prefix, for example the app com.android.contacts would use names
3554 * like "com.android.contacts.ShowAll".
3555 *
3556 * @param name The name of the extra data, with package prefix.
3557 * @param value The ArrayList<String> data value.
3558 *
3559 * @return Returns the same Intent object, for chaining multiple calls
3560 * into a single statement.
3561 *
3562 * @see #putExtras
3563 * @see #removeExtra
3564 * @see #getStringArrayListExtra(String)
3565 */
3566 public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
3567 if (mExtras == null) {
3568 mExtras = new Bundle();
3569 }
3570 mExtras.putStringArrayList(name, value);
3571 return this;
3572 }
3573
3574 /**
3575 * Add extended data to the intent. The name must include a package
3576 * prefix, for example the app com.android.contacts would use names
3577 * like "com.android.contacts.ShowAll".
3578 *
3579 * @param name The name of the extra data, with package prefix.
3580 * @param value The Serializable data value.
3581 *
3582 * @return Returns the same Intent object, for chaining multiple calls
3583 * into a single statement.
3584 *
3585 * @see #putExtras
3586 * @see #removeExtra
3587 * @see #getSerializableExtra(String)
3588 */
3589 public Intent putExtra(String name, Serializable value) {
3590 if (mExtras == null) {
3591 mExtras = new Bundle();
3592 }
3593 mExtras.putSerializable(name, value);
3594 return this;
3595 }
3596
3597 /**
3598 * Add extended data to the intent. The name must include a package
3599 * prefix, for example the app com.android.contacts would use names
3600 * like "com.android.contacts.ShowAll".
3601 *
3602 * @param name The name of the extra data, with package prefix.
3603 * @param value The boolean array data value.
3604 *
3605 * @return Returns the same Intent object, for chaining multiple calls
3606 * into a single statement.
3607 *
3608 * @see #putExtras
3609 * @see #removeExtra
3610 * @see #getBooleanArrayExtra(String)
3611 */
3612 public Intent putExtra(String name, boolean[] value) {
3613 if (mExtras == null) {
3614 mExtras = new Bundle();
3615 }
3616 mExtras.putBooleanArray(name, value);
3617 return this;
3618 }
3619
3620 /**
3621 * Add extended data to the intent. The name must include a package
3622 * prefix, for example the app com.android.contacts would use names
3623 * like "com.android.contacts.ShowAll".
3624 *
3625 * @param name The name of the extra data, with package prefix.
3626 * @param value The byte array data value.
3627 *
3628 * @return Returns the same Intent object, for chaining multiple calls
3629 * into a single statement.
3630 *
3631 * @see #putExtras
3632 * @see #removeExtra
3633 * @see #getByteArrayExtra(String)
3634 */
3635 public Intent putExtra(String name, byte[] value) {
3636 if (mExtras == null) {
3637 mExtras = new Bundle();
3638 }
3639 mExtras.putByteArray(name, value);
3640 return this;
3641 }
3642
3643 /**
3644 * Add extended data to the intent. The name must include a package
3645 * prefix, for example the app com.android.contacts would use names
3646 * like "com.android.contacts.ShowAll".
3647 *
3648 * @param name The name of the extra data, with package prefix.
3649 * @param value The short array data value.
3650 *
3651 * @return Returns the same Intent object, for chaining multiple calls
3652 * into a single statement.
3653 *
3654 * @see #putExtras
3655 * @see #removeExtra
3656 * @see #getShortArrayExtra(String)
3657 */
3658 public Intent putExtra(String name, short[] value) {
3659 if (mExtras == null) {
3660 mExtras = new Bundle();
3661 }
3662 mExtras.putShortArray(name, value);
3663 return this;
3664 }
3665
3666 /**
3667 * Add extended data to the intent. The name must include a package
3668 * prefix, for example the app com.android.contacts would use names
3669 * like "com.android.contacts.ShowAll".
3670 *
3671 * @param name The name of the extra data, with package prefix.
3672 * @param value The char array data value.
3673 *
3674 * @return Returns the same Intent object, for chaining multiple calls
3675 * into a single statement.
3676 *
3677 * @see #putExtras
3678 * @see #removeExtra
3679 * @see #getCharArrayExtra(String)
3680 */
3681 public Intent putExtra(String name, char[] value) {
3682 if (mExtras == null) {
3683 mExtras = new Bundle();
3684 }
3685 mExtras.putCharArray(name, value);
3686 return this;
3687 }
3688
3689 /**
3690 * Add extended data to the intent. The name must include a package
3691 * prefix, for example the app com.android.contacts would use names
3692 * like "com.android.contacts.ShowAll".
3693 *
3694 * @param name The name of the extra data, with package prefix.
3695 * @param value The int array data value.
3696 *
3697 * @return Returns the same Intent object, for chaining multiple calls
3698 * into a single statement.
3699 *
3700 * @see #putExtras
3701 * @see #removeExtra
3702 * @see #getIntArrayExtra(String)
3703 */
3704 public Intent putExtra(String name, int[] value) {
3705 if (mExtras == null) {
3706 mExtras = new Bundle();
3707 }
3708 mExtras.putIntArray(name, value);
3709 return this;
3710 }
3711
3712 /**
3713 * Add extended data to the intent. The name must include a package
3714 * prefix, for example the app com.android.contacts would use names
3715 * like "com.android.contacts.ShowAll".
3716 *
3717 * @param name The name of the extra data, with package prefix.
3718 * @param value The byte array data value.
3719 *
3720 * @return Returns the same Intent object, for chaining multiple calls
3721 * into a single statement.
3722 *
3723 * @see #putExtras
3724 * @see #removeExtra
3725 * @see #getLongArrayExtra(String)
3726 */
3727 public Intent putExtra(String name, long[] value) {
3728 if (mExtras == null) {
3729 mExtras = new Bundle();
3730 }
3731 mExtras.putLongArray(name, value);
3732 return this;
3733 }
3734
3735 /**
3736 * Add extended data to the intent. The name must include a package
3737 * prefix, for example the app com.android.contacts would use names
3738 * like "com.android.contacts.ShowAll".
3739 *
3740 * @param name The name of the extra data, with package prefix.
3741 * @param value The float array data value.
3742 *
3743 * @return Returns the same Intent object, for chaining multiple calls
3744 * into a single statement.
3745 *
3746 * @see #putExtras
3747 * @see #removeExtra
3748 * @see #getFloatArrayExtra(String)
3749 */
3750 public Intent putExtra(String name, float[] value) {
3751 if (mExtras == null) {
3752 mExtras = new Bundle();
3753 }
3754 mExtras.putFloatArray(name, value);
3755 return this;
3756 }
3757
3758 /**
3759 * Add extended data to the intent. The name must include a package
3760 * prefix, for example the app com.android.contacts would use names
3761 * like "com.android.contacts.ShowAll".
3762 *
3763 * @param name The name of the extra data, with package prefix.
3764 * @param value The double array data value.
3765 *
3766 * @return Returns the same Intent object, for chaining multiple calls
3767 * into a single statement.
3768 *
3769 * @see #putExtras
3770 * @see #removeExtra
3771 * @see #getDoubleArrayExtra(String)
3772 */
3773 public Intent putExtra(String name, double[] value) {
3774 if (mExtras == null) {
3775 mExtras = new Bundle();
3776 }
3777 mExtras.putDoubleArray(name, value);
3778 return this;
3779 }
3780
3781 /**
3782 * Add extended data to the intent. The name must include a package
3783 * prefix, for example the app com.android.contacts would use names
3784 * like "com.android.contacts.ShowAll".
3785 *
3786 * @param name The name of the extra data, with package prefix.
3787 * @param value The String array data value.
3788 *
3789 * @return Returns the same Intent object, for chaining multiple calls
3790 * into a single statement.
3791 *
3792 * @see #putExtras
3793 * @see #removeExtra
3794 * @see #getStringArrayExtra(String)
3795 */
3796 public Intent putExtra(String name, String[] value) {
3797 if (mExtras == null) {
3798 mExtras = new Bundle();
3799 }
3800 mExtras.putStringArray(name, value);
3801 return this;
3802 }
3803
3804 /**
3805 * Add extended data to the intent. The name must include a package
3806 * prefix, for example the app com.android.contacts would use names
3807 * like "com.android.contacts.ShowAll".
3808 *
3809 * @param name The name of the extra data, with package prefix.
3810 * @param value The Bundle data value.
3811 *
3812 * @return Returns the same Intent object, for chaining multiple calls
3813 * into a single statement.
3814 *
3815 * @see #putExtras
3816 * @see #removeExtra
3817 * @see #getBundleExtra(String)
3818 */
3819 public Intent putExtra(String name, Bundle value) {
3820 if (mExtras == null) {
3821 mExtras = new Bundle();
3822 }
3823 mExtras.putBundle(name, value);
3824 return this;
3825 }
3826
3827 /**
3828 * Add extended data to the intent. The name must include a package
3829 * prefix, for example the app com.android.contacts would use names
3830 * like "com.android.contacts.ShowAll".
3831 *
3832 * @param name The name of the extra data, with package prefix.
3833 * @param value The IBinder data value.
3834 *
3835 * @return Returns the same Intent object, for chaining multiple calls
3836 * into a single statement.
3837 *
3838 * @see #putExtras
3839 * @see #removeExtra
3840 * @see #getIBinderExtra(String)
3841 *
3842 * @deprecated
3843 * @hide
3844 */
3845 @Deprecated
3846 public Intent putExtra(String name, IBinder value) {
3847 if (mExtras == null) {
3848 mExtras = new Bundle();
3849 }
3850 mExtras.putIBinder(name, value);
3851 return this;
3852 }
3853
3854 /**
3855 * Copy all extras in 'src' in to this intent.
3856 *
3857 * @param src Contains the extras to copy.
3858 *
3859 * @see #putExtra
3860 */
3861 public Intent putExtras(Intent src) {
3862 if (src.mExtras != null) {
3863 if (mExtras == null) {
3864 mExtras = new Bundle(src.mExtras);
3865 } else {
3866 mExtras.putAll(src.mExtras);
3867 }
3868 }
3869 return this;
3870 }
3871
3872 /**
3873 * Add a set of extended data to the intent. The keys must include a package
3874 * prefix, for example the app com.android.contacts would use names
3875 * like "com.android.contacts.ShowAll".
3876 *
3877 * @param extras The Bundle of extras to add to this intent.
3878 *
3879 * @see #putExtra
3880 * @see #removeExtra
3881 */
3882 public Intent putExtras(Bundle extras) {
3883 if (mExtras == null) {
3884 mExtras = new Bundle();
3885 }
3886 mExtras.putAll(extras);
3887 return this;
3888 }
3889
3890 /**
3891 * Completely replace the extras in the Intent with the extras in the
3892 * given Intent.
3893 *
3894 * @param src The exact extras contained in this Intent are copied
3895 * into the target intent, replacing any that were previously there.
3896 */
3897 public Intent replaceExtras(Intent src) {
3898 mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null;
3899 return this;
3900 }
3901
3902 /**
3903 * Completely replace the extras in the Intent with the given Bundle of
3904 * extras.
3905 *
3906 * @param extras The new set of extras in the Intent, or null to erase
3907 * all extras.
3908 */
3909 public Intent replaceExtras(Bundle extras) {
3910 mExtras = extras != null ? new Bundle(extras) : null;
3911 return this;
3912 }
3913
3914 /**
3915 * Remove extended data from the intent.
3916 *
3917 * @see #putExtra
3918 */
3919 public void removeExtra(String name) {
3920 if (mExtras != null) {
3921 mExtras.remove(name);
3922 if (mExtras.size() == 0) {
3923 mExtras = null;
3924 }
3925 }
3926 }
3927
3928 /**
3929 * Set special flags controlling how this intent is handled. Most values
3930 * here depend on the type of component being executed by the Intent,
3931 * specifically the FLAG_ACTIVITY_* flags are all for use with
3932 * {@link Context#startActivity Context.startActivity()} and the
3933 * FLAG_RECEIVER_* flags are all for use with
3934 * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
3935 *
3936 * <p>See the <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
3937 * Activities and Tasks</a> documentation for important information on how some of these options impact
3938 * the behavior of your application.
3939 *
3940 * @param flags The desired flags.
3941 *
3942 * @return Returns the same Intent object, for chaining multiple calls
3943 * into a single statement.
3944 *
3945 * @see #getFlags
3946 * @see #addFlags
3947 *
3948 * @see #FLAG_GRANT_READ_URI_PERMISSION
3949 * @see #FLAG_GRANT_WRITE_URI_PERMISSION
3950 * @see #FLAG_DEBUG_LOG_RESOLUTION
3951 * @see #FLAG_FROM_BACKGROUND
3952 * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT
3953 * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
3954 * @see #FLAG_ACTIVITY_CLEAR_TOP
3955 * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
3956 * @see #FLAG_ACTIVITY_FORWARD_RESULT
3957 * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
3958 * @see #FLAG_ACTIVITY_MULTIPLE_TASK
3959 * @see #FLAG_ACTIVITY_NEW_TASK
3960 * @see #FLAG_ACTIVITY_NO_HISTORY
3961 * @see #FLAG_ACTIVITY_NO_USER_ACTION
3962 * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP
3963 * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
3964 * @see #FLAG_ACTIVITY_SINGLE_TOP
3965 * @see #FLAG_RECEIVER_REGISTERED_ONLY
3966 */
3967 public Intent setFlags(int flags) {
3968 mFlags = flags;
3969 return this;
3970 }
3971
3972 /**
3973 * Add additional flags to the intent (or with existing flags
3974 * value).
3975 *
3976 * @param flags The new flags to set.
3977 *
3978 * @return Returns the same Intent object, for chaining multiple calls
3979 * into a single statement.
3980 *
3981 * @see #setFlags
3982 */
3983 public Intent addFlags(int flags) {
3984 mFlags |= flags;
3985 return this;
3986 }
3987
3988 /**
3989 * (Usually optional) Explicitly set the component to handle the intent.
3990 * If left with the default value of null, the system will determine the
3991 * appropriate class to use based on the other fields (action, data,
3992 * type, categories) in the Intent. If this class is defined, the
3993 * specified class will always be used regardless of the other fields. You
3994 * should only set this value when you know you absolutely want a specific
3995 * class to be used; otherwise it is better to let the system find the
3996 * appropriate class so that you will respect the installed applications
3997 * and user preferences.
3998 *
3999 * @param component The name of the application component to handle the
4000 * intent, or null to let the system find one for you.
4001 *
4002 * @return Returns the same Intent object, for chaining multiple calls
4003 * into a single statement.
4004 *
4005 * @see #setClass
4006 * @see #setClassName(Context, String)
4007 * @see #setClassName(String, String)
4008 * @see #getComponent
4009 * @see #resolveActivity
4010 */
4011 public Intent setComponent(ComponentName component) {
4012 mComponent = component;
4013 return this;
4014 }
4015
4016 /**
4017 * Convenience for calling {@link #setComponent} with an
4018 * explicit class name.
4019 *
4020 * @param packageContext A Context of the application package implementing
4021 * this class.
4022 * @param className The name of a class inside of the application package
4023 * that will be used as the component for this Intent.
4024 *
4025 * @return Returns the same Intent object, for chaining multiple calls
4026 * into a single statement.
4027 *
4028 * @see #setComponent
4029 * @see #setClass
4030 */
4031 public Intent setClassName(Context packageContext, String className) {
4032 mComponent = new ComponentName(packageContext, className);
4033 return this;
4034 }
4035
4036 /**
4037 * Convenience for calling {@link #setComponent} with an
4038 * explicit application package name and class name.
4039 *
4040 * @param packageName The name of the package implementing the desired
4041 * component.
4042 * @param className The name of a class inside of the application package
4043 * that will be used as the component for this Intent.
4044 *
4045 * @return Returns the same Intent object, for chaining multiple calls
4046 * into a single statement.
4047 *
4048 * @see #setComponent
4049 * @see #setClass
4050 */
4051 public Intent setClassName(String packageName, String className) {
4052 mComponent = new ComponentName(packageName, className);
4053 return this;
4054 }
4055
4056 /**
4057 * Convenience for calling {@link #setComponent(ComponentName)} with the
4058 * name returned by a {@link Class} object.
4059 *
4060 * @param packageContext A Context of the application package implementing
4061 * this class.
4062 * @param cls The class name to set, equivalent to
4063 * <code>setClassName(context, cls.getName())</code>.
4064 *
4065 * @return Returns the same Intent object, for chaining multiple calls
4066 * into a single statement.
4067 *
4068 * @see #setComponent
4069 */
4070 public Intent setClass(Context packageContext, Class<?> cls) {
4071 mComponent = new ComponentName(packageContext, cls);
4072 return this;
4073 }
4074
4075 /**
4076 * Use with {@link #fillIn} to allow the current action value to be
4077 * overwritten, even if it is already set.
4078 */
4079 public static final int FILL_IN_ACTION = 1<<0;
4080
4081 /**
4082 * Use with {@link #fillIn} to allow the current data or type value
4083 * overwritten, even if it is already set.
4084 */
4085 public static final int FILL_IN_DATA = 1<<1;
4086
4087 /**
4088 * Use with {@link #fillIn} to allow the current categories to be
4089 * overwritten, even if they are already set.
4090 */
4091 public static final int FILL_IN_CATEGORIES = 1<<2;
4092
4093 /**
4094 * Use with {@link #fillIn} to allow the current component value to be
4095 * overwritten, even if it is already set.
4096 */
4097 public static final int FILL_IN_COMPONENT = 1<<3;
4098
4099 /**
4100 * Copy the contents of <var>other</var> in to this object, but only
4101 * where fields are not defined by this object. For purposes of a field
4102 * being defined, the following pieces of data in the Intent are
4103 * considered to be separate fields:
4104 *
4105 * <ul>
4106 * <li> action, as set by {@link #setAction}.
4107 * <li> data URI and MIME type, as set by {@link #setData(Uri)},
4108 * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}.
4109 * <li> categories, as set by {@link #addCategory}.
4110 * <li> component, as set by {@link #setComponent(ComponentName)} or
4111 * related methods.
4112 * <li> each top-level name in the associated extras.
4113 * </ul>
4114 *
4115 * <p>In addition, you can use the {@link #FILL_IN_ACTION},
4116 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, and
4117 * {@link #FILL_IN_COMPONENT} to override the restriction where the
4118 * corresponding field will not be replaced if it is already set.
4119 *
4120 * <p>For example, consider Intent A with {data="foo", categories="bar"}
4121 * and Intent B with {action="gotit", data-type="some/thing",
4122 * categories="one","two"}.
4123 *
4124 * <p>Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now
4125 * containing: {action="gotit", data-type="some/thing",
4126 * categories="bar"}.
4127 *
4128 * @param other Another Intent whose values are to be used to fill in
4129 * the current one.
4130 * @param flags Options to control which fields can be filled in.
4131 *
4132 * @return Returns a bit mask of {@link #FILL_IN_ACTION},
4133 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, and
4134 * {@link #FILL_IN_COMPONENT} indicating which fields were changed.
4135 */
4136 public int fillIn(Intent other, int flags) {
4137 int changes = 0;
4138 if ((mAction == null && other.mAction == null)
4139 || (flags&FILL_IN_ACTION) != 0) {
4140 mAction = other.mAction;
4141 changes |= FILL_IN_ACTION;
4142 }
4143 if ((mData == null && mType == null &&
4144 (other.mData != null || other.mType != null))
4145 || (flags&FILL_IN_DATA) != 0) {
4146 mData = other.mData;
4147 mType = other.mType;
4148 changes |= FILL_IN_DATA;
4149 }
4150 if ((mCategories == null && other.mCategories == null)
4151 || (flags&FILL_IN_CATEGORIES) != 0) {
4152 if (other.mCategories != null) {
4153 mCategories = new HashSet<String>(other.mCategories);
4154 }
4155 changes |= FILL_IN_CATEGORIES;
4156 }
4157 if ((mComponent == null && other.mComponent == null)
4158 || (flags&FILL_IN_COMPONENT) != 0) {
4159 mComponent = other.mComponent;
4160 changes |= FILL_IN_COMPONENT;
4161 }
4162 mFlags |= other.mFlags;
4163 if (mExtras == null) {
4164 if (other.mExtras != null) {
4165 mExtras = new Bundle(other.mExtras);
4166 }
4167 } else if (other.mExtras != null) {
4168 try {
4169 Bundle newb = new Bundle(other.mExtras);
4170 newb.putAll(mExtras);
4171 mExtras = newb;
4172 } catch (RuntimeException e) {
4173 // Modifying the extras can cause us to unparcel the contents
4174 // of the bundle, and if we do this in the system process that
4175 // may fail. We really should handle this (i.e., the Bundle
4176 // impl shouldn't be on top of a plain map), but for now just
4177 // ignore it and keep the original contents. :(
4178 Log.w("Intent", "Failure filling in extras", e);
4179 }
4180 }
4181 return changes;
4182 }
4183
4184 /**
4185 * Wrapper class holding an Intent and implementing comparisons on it for
4186 * the purpose of filtering. The class implements its
4187 * {@link #equals equals()} and {@link #hashCode hashCode()} methods as
4188 * simple calls to {@link Intent#filterEquals(Intent)} filterEquals()} and
4189 * {@link android.content.Intent#filterHashCode()} filterHashCode()}
4190 * on the wrapped Intent.
4191 */
4192 public static final class FilterComparison {
4193 private final Intent mIntent;
4194 private final int mHashCode;
4195
4196 public FilterComparison(Intent intent) {
4197 mIntent = intent;
4198 mHashCode = intent.filterHashCode();
4199 }
4200
4201 /**
4202 * Return the Intent that this FilterComparison represents.
4203 * @return Returns the Intent held by the FilterComparison. Do
4204 * not modify!
4205 */
4206 public Intent getIntent() {
4207 return mIntent;
4208 }
4209
4210 @Override
4211 public boolean equals(Object obj) {
4212 if (obj instanceof FilterComparison) {
4213 Intent other = ((FilterComparison)obj).mIntent;
4214 return mIntent.filterEquals(other);
4215 }
4216 return false;
4217 }
4218
4219 @Override
4220 public int hashCode() {
4221 return mHashCode;
4222 }
4223 }
4224
4225 /**
4226 * Determine if two intents are the same for the purposes of intent
4227 * resolution (filtering). That is, if their action, data, type,
4228 * class, and categories are the same. This does <em>not</em> compare
4229 * any extra data included in the intents.
4230 *
4231 * @param other The other Intent to compare against.
4232 *
4233 * @return Returns true if action, data, type, class, and categories
4234 * are the same.
4235 */
4236 public boolean filterEquals(Intent other) {
4237 if (other == null) {
4238 return false;
4239 }
4240 if (mAction != other.mAction) {
4241 if (mAction != null) {
4242 if (!mAction.equals(other.mAction)) {
4243 return false;
4244 }
4245 } else {
4246 if (!other.mAction.equals(mAction)) {
4247 return false;
4248 }
4249 }
4250 }
4251 if (mData != other.mData) {
4252 if (mData != null) {
4253 if (!mData.equals(other.mData)) {
4254 return false;
4255 }
4256 } else {
4257 if (!other.mData.equals(mData)) {
4258 return false;
4259 }
4260 }
4261 }
4262 if (mType != other.mType) {
4263 if (mType != null) {
4264 if (!mType.equals(other.mType)) {
4265 return false;
4266 }
4267 } else {
4268 if (!other.mType.equals(mType)) {
4269 return false;
4270 }
4271 }
4272 }
4273 if (mComponent != other.mComponent) {
4274 if (mComponent != null) {
4275 if (!mComponent.equals(other.mComponent)) {
4276 return false;
4277 }
4278 } else {
4279 if (!other.mComponent.equals(mComponent)) {
4280 return false;
4281 }
4282 }
4283 }
4284 if (mCategories != other.mCategories) {
4285 if (mCategories != null) {
4286 if (!mCategories.equals(other.mCategories)) {
4287 return false;
4288 }
4289 } else {
4290 if (!other.mCategories.equals(mCategories)) {
4291 return false;
4292 }
4293 }
4294 }
4295
4296 return true;
4297 }
4298
4299 /**
4300 * Generate hash code that matches semantics of filterEquals().
4301 *
4302 * @return Returns the hash value of the action, data, type, class, and
4303 * categories.
4304 *
4305 * @see #filterEquals
4306 */
4307 public int filterHashCode() {
4308 int code = 0;
4309 if (mAction != null) {
4310 code += mAction.hashCode();
4311 }
4312 if (mData != null) {
4313 code += mData.hashCode();
4314 }
4315 if (mType != null) {
4316 code += mType.hashCode();
4317 }
4318 if (mComponent != null) {
4319 code += mComponent.hashCode();
4320 }
4321 if (mCategories != null) {
4322 code += mCategories.hashCode();
4323 }
4324 return code;
4325 }
4326
4327 @Override
4328 public String toString() {
4329 StringBuilder b = new StringBuilder();
4330
4331 b.append("Intent {");
4332 if (mAction != null) b.append(" action=").append(mAction);
4333 if (mCategories != null) {
4334 b.append(" categories={");
4335 Iterator<String> i = mCategories.iterator();
4336 boolean didone = false;
4337 while (i.hasNext()) {
4338 if (didone) b.append(",");
4339 didone = true;
4340 b.append(i.next());
4341 }
4342 b.append("}");
4343 }
4344 if (mData != null) b.append(" data=").append(mData);
4345 if (mType != null) b.append(" type=").append(mType);
4346 if (mFlags != 0) b.append(" flags=0x").append(Integer.toHexString(mFlags));
4347 if (mComponent != null) b.append(" comp=").append(mComponent.toShortString());
4348 if (mExtras != null) b.append(" (has extras)");
4349 b.append(" }");
4350
4351 return b.toString();
4352 }
4353
4354 public String toURI() {
4355 StringBuilder uri = new StringBuilder(mData != null ? mData.toString() : "");
4356
4357 uri.append("#Intent;");
4358
4359 if (mAction != null) {
4360 uri.append("action=").append(mAction).append(';');
4361 }
4362 if (mCategories != null) {
4363 for (String category : mCategories) {
4364 uri.append("category=").append(category).append(';');
4365 }
4366 }
4367 if (mType != null) {
4368 uri.append("type=").append(mType).append(';');
4369 }
4370 if (mFlags != 0) {
4371 uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
4372 }
4373 if (mComponent != null) {
4374 uri.append("component=").append(mComponent.flattenToShortString()).append(';');
4375 }
4376 if (mExtras != null) {
4377 for (String key : mExtras.keySet()) {
4378 final Object value = mExtras.get(key);
4379 char entryType =
4380 value instanceof String ? 'S' :
4381 value instanceof Boolean ? 'B' :
4382 value instanceof Byte ? 'b' :
4383 value instanceof Character ? 'c' :
4384 value instanceof Double ? 'd' :
4385 value instanceof Float ? 'f' :
4386 value instanceof Integer ? 'i' :
4387 value instanceof Long ? 'l' :
4388 value instanceof Short ? 's' :
4389 '\0';
4390
4391 if (entryType != '\0') {
4392 uri.append(entryType);
4393 uri.append('.');
4394 uri.append(Uri.encode(key));
4395 uri.append('=');
4396 uri.append(Uri.encode(value.toString()));
4397 uri.append(';');
4398 }
4399 }
4400 }
4401
4402 uri.append("end");
4403
4404 return uri.toString();
4405 }
4406
4407 public int describeContents() {
4408 return (mExtras != null) ? mExtras.describeContents() : 0;
4409 }
4410
4411 public void writeToParcel(Parcel out, int flags) {
4412 out.writeString(mAction);
4413 Uri.writeToParcel(out, mData);
4414 out.writeString(mType);
4415 out.writeInt(mFlags);
4416 ComponentName.writeToParcel(mComponent, out);
4417
4418 if (mCategories != null) {
4419 out.writeInt(mCategories.size());
4420 for (String category : mCategories) {
4421 out.writeString(category);
4422 }
4423 } else {
4424 out.writeInt(0);
4425 }
4426
4427 out.writeBundle(mExtras);
4428 }
4429
4430 public static final Parcelable.Creator<Intent> CREATOR
4431 = new Parcelable.Creator<Intent>() {
4432 public Intent createFromParcel(Parcel in) {
4433 return new Intent(in);
4434 }
4435 public Intent[] newArray(int size) {
4436 return new Intent[size];
4437 }
4438 };
4439
4440 private Intent(Parcel in) {
4441 readFromParcel(in);
4442 }
4443
4444 public void readFromParcel(Parcel in) {
4445 mAction = in.readString();
4446 mData = Uri.CREATOR.createFromParcel(in);
4447 mType = in.readString();
4448 mFlags = in.readInt();
4449 mComponent = ComponentName.readFromParcel(in);
4450
4451 int N = in.readInt();
4452 if (N > 0) {
4453 mCategories = new HashSet<String>();
4454 int i;
4455 for (i=0; i<N; i++) {
4456 mCategories.add(in.readString());
4457 }
4458 } else {
4459 mCategories = null;
4460 }
4461
4462 mExtras = in.readBundle();
4463 }
4464
4465 /**
4466 * Parses the "intent" element (and its children) from XML and instantiates
4467 * an Intent object. The given XML parser should be located at the tag
4468 * where parsing should start (often named "intent"), from which the
4469 * basic action, data, type, and package and class name will be
4470 * retrieved. The function will then parse in to any child elements,
4471 * looking for <category android:name="xxx"> tags to add categories and
4472 * <extra android:name="xxx" android:value="yyy"> to attach extra data
4473 * to the intent.
4474 *
4475 * @param resources The Resources to use when inflating resources.
4476 * @param parser The XML parser pointing at an "intent" tag.
4477 * @param attrs The AttributeSet interface for retrieving extended
4478 * attribute data at the current <var>parser</var> location.
4479 * @return An Intent object matching the XML data.
4480 * @throws XmlPullParserException If there was an XML parsing error.
4481 * @throws IOException If there was an I/O error.
4482 */
4483 public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
4484 throws XmlPullParserException, IOException {
4485 Intent intent = new Intent();
4486
4487 TypedArray sa = resources.obtainAttributes(attrs,
4488 com.android.internal.R.styleable.Intent);
4489
4490 intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action));
4491
4492 String data = sa.getString(com.android.internal.R.styleable.Intent_data);
4493 String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType);
4494 intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType);
4495
4496 String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage);
4497 String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass);
4498 if (packageName != null && className != null) {
4499 intent.setComponent(new ComponentName(packageName, className));
4500 }
4501
4502 sa.recycle();
4503
4504 int outerDepth = parser.getDepth();
4505 int type;
4506 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
4507 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
4508 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
4509 continue;
4510 }
4511
4512 String nodeName = parser.getName();
4513 if (nodeName.equals("category")) {
4514 sa = resources.obtainAttributes(attrs,
4515 com.android.internal.R.styleable.IntentCategory);
4516 String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name);
4517 sa.recycle();
4518
4519 if (cat != null) {
4520 intent.addCategory(cat);
4521 }
4522 XmlUtils.skipCurrentTag(parser);
4523
4524 } else if (nodeName.equals("extra")) {
4525 if (intent.mExtras == null) {
4526 intent.mExtras = new Bundle();
4527 }
4528 resources.parseBundleExtra("extra", attrs, intent.mExtras);
4529 XmlUtils.skipCurrentTag(parser);
4530
4531 } else {
4532 XmlUtils.skipCurrentTag(parser);
4533 }
4534 }
4535
4536 return intent;
4537 }
4538}