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