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