blob: 99ec60e3c9b61fd55b609c090e6e8a2d832881c7 [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;
Joe Onoratoc7a63ee2009-12-02 21:13:17 -080029import android.graphics.Rect;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070030import android.net.Uri;
31import android.os.Bundle;
32import android.os.IBinder;
33import android.os.Parcel;
34import android.os.Parcelable;
35import android.util.AttributeSet;
36import android.util.Log;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070037import 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>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -070079 * <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/1</i></b> -- Display
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070080 * information about the person whose identifier is "1".</p>
81 * </li>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -070082 * <li> <p><b>{@link #ACTION_DIAL} <i>content://contacts/people/1</i></b> -- Display
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070083 * 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>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -070093 * <li> <p><b>{@link #ACTION_EDIT} <i>content://contacts/people/1</i></b> -- Edit
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070094 * information about the person whose identifier is "1".</p>
95 * </li>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -070096 * <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/</i></b> -- Display
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070097 * 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
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -0700160 * "android.intent.action.VIEW".</p>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700161 *
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;
Romain Guy4969af72009-06-17 10:53:19 -0700244 * &lt;action android:name="android.intent.action.MAIN" /&gt;
245 * &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700246 * &lt;/intent-filter&gt;
247 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700248 * &lt;action android:name="android.intent.action.VIEW" /&gt;
249 * &lt;action android:name="android.intent.action.EDIT" /&gt;
250 * &lt;action android:name="android.intent.action.PICK" /&gt;
251 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
252 * &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700253 * &lt;/intent-filter&gt;
254 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700255 * &lt;action android:name="android.intent.action.GET_CONTENT" /&gt;
256 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
257 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700258 * &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;
Romain Guy4969af72009-06-17 10:53:19 -0700263 * &lt;action android:name="android.intent.action.VIEW" /&gt;
264 * &lt;action android:name="android.intent.action.EDIT" /&gt;
265 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
266 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700267 * &lt;/intent-filter&gt;
268 *
269 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700270 * &lt;action android:name="android.intent.action.INSERT" /&gt;
271 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
272 * &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700273 * &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;
Romain Guy4969af72009-06-17 10:53:19 -0700280 * &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
281 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
282 * &lt;category android:name="android.intent.category.ALTERNATIVE" /&gt;
283 * &lt;category android:name="android.intent.category.SELECTED_ALTERNATIVE" /&gt;
284 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700285 * &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;
Romain Guy4969af72009-06-17 10:53:19 -0700298 * &lt;action android:name="{@link #ACTION_MAIN android.intent.action.MAIN}" /&gt;
299 * &lt;category android:name="{@link #CATEGORY_LAUNCHER android.intent.category.LAUNCHER}" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700300 * &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;
Romain Guy4969af72009-06-17 10:53:19 -0700307 * &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
308 * &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
309 * &lt;action android:name="{@link #ACTION_PICK android.intent.action.PICK}" /&gt;
310 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
311 * &lt;data mimeType:name="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700312 * &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;
Romain Guy4969af72009-06-17 10:53:19 -0700326 * &lt;action android:name="{@link #ACTION_GET_CONTENT android.intent.action.GET_CONTENT}" /&gt;
327 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
328 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700329 * &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>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -0700351 * <li> <p><b>{ action=android.intent.action.VIEW
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700352 * 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;
Romain Guy4969af72009-06-17 10:53:19 -0700375 * &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
376 * &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
377 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
378 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700379 * &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;
Romain Guy4969af72009-06-17 10:53:19 -0700388 * &lt;action android:name="{@link #ACTION_INSERT android.intent.action.INSERT}" /&gt;
389 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
390 * &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700391 * &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>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -0700403 * <li> <p><b>{ action=android.intent.action.VIEW
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700404 * 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;
Romain Guy4969af72009-06-17 10:53:19 -0700426 * &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
427 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
428 * &lt;category android:name="{@link #CATEGORY_ALTERNATIVE android.intent.category.ALTERNATIVE}" /&gt;
429 * &lt;category android:name="{@link #CATEGORY_SELECTED_ALTERNATIVE android.intent.category.SELECTED_ALTERNATIVE}" /&gt;
430 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700431 * &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}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 * <li> {@link #ACTION_PACKAGE_RESTARTED}
509 * <li> {@link #ACTION_PACKAGE_DATA_CLEARED}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700510 * <li> {@link #ACTION_UID_REMOVED}
511 * <li> {@link #ACTION_BATTERY_CHANGED}
Cliff Spradlinfda6fae2008-10-22 20:29:16 -0700512 * <li> {@link #ACTION_POWER_CONNECTED}
Romain Guy4969af72009-06-17 10:53:19 -0700513 * <li> {@link #ACTION_POWER_DISCONNECTED}
514 * <li> {@link #ACTION_SHUTDOWN}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700515 * </ul>
516 *
517 * <h3>Standard Categories</h3>
518 *
519 * <p>These are the current standard categories that can be used to further
520 * clarify an Intent via {@link #addCategory}.
521 *
522 * <ul>
523 * <li> {@link #CATEGORY_DEFAULT}
524 * <li> {@link #CATEGORY_BROWSABLE}
525 * <li> {@link #CATEGORY_TAB}
526 * <li> {@link #CATEGORY_ALTERNATIVE}
527 * <li> {@link #CATEGORY_SELECTED_ALTERNATIVE}
528 * <li> {@link #CATEGORY_LAUNCHER}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 * <li> {@link #CATEGORY_INFO}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700530 * <li> {@link #CATEGORY_HOME}
531 * <li> {@link #CATEGORY_PREFERENCE}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700532 * <li> {@link #CATEGORY_TEST}
Mike Lockwood9092ab42009-09-16 13:01:32 -0400533 * <li> {@link #CATEGORY_CAR_DOCK}
534 * <li> {@link #CATEGORY_DESK_DOCK}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700535 * </ul>
536 *
537 * <h3>Standard Extra Data</h3>
538 *
539 * <p>These are the current standard fields that can be used as extra data via
540 * {@link #putExtra}.
541 *
542 * <ul>
Trevor Johnsd59fb6e2009-11-20 12:54:57 -0800543 * <li> {@link #EXTRA_ALARM_COUNT}
544 * <li> {@link #EXTRA_BCC}
545 * <li> {@link #EXTRA_CC}
546 * <li> {@link #EXTRA_CHANGED_COMPONENT_NAME}
547 * <li> {@link #EXTRA_DATA_REMOVED}
548 * <li> {@link #EXTRA_DOCK_STATE}
549 * <li> {@link #EXTRA_DOCK_STATE_CAR}
550 * <li> {@link #EXTRA_DOCK_STATE_DESK}
551 * <li> {@link #EXTRA_DOCK_STATE_UNDOCKED}
552 * <li> {@link #EXTRA_DONT_KILL_APP}
553 * <li> {@link #EXTRA_EMAIL}
554 * <li> {@link #EXTRA_INITIAL_INTENTS}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700555 * <li> {@link #EXTRA_INTENT}
Trevor Johnsd59fb6e2009-11-20 12:54:57 -0800556 * <li> {@link #EXTRA_KEY_EVENT}
557 * <li> {@link #EXTRA_PHONE_NUMBER}
558 * <li> {@link #EXTRA_REMOTE_INTENT_TOKEN}
559 * <li> {@link #EXTRA_REPLACING}
560 * <li> {@link #EXTRA_SHORTCUT_ICON}
561 * <li> {@link #EXTRA_SHORTCUT_ICON_RESOURCE}
562 * <li> {@link #EXTRA_SHORTCUT_INTENT}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700563 * <li> {@link #EXTRA_STREAM}
Trevor Johnsd59fb6e2009-11-20 12:54:57 -0800564 * <li> {@link #EXTRA_SHORTCUT_NAME}
565 * <li> {@link #EXTRA_SUBJECT}
566 * <li> {@link #EXTRA_TEMPLATE}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700567 * <li> {@link #EXTRA_TEXT}
Trevor Johnsd59fb6e2009-11-20 12:54:57 -0800568 * <li> {@link #EXTRA_TITLE}
569 * <li> {@link #EXTRA_UID}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700570 * </ul>
571 *
572 * <h3>Flags</h3>
573 *
574 * <p>These are the possible flags that can be used in the Intent via
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800575 * {@link #setFlags} and {@link #addFlags}. See {@link #setFlags} for a list
576 * of all possible flags.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700577 */
Dianne Hackbornee0511d2009-12-21 18:08:13 -0800578public class Intent implements Parcelable, Cloneable {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700579 // ---------------------------------------------------------------------
580 // ---------------------------------------------------------------------
581 // Standard intent activity actions (see action variable).
582
583 /**
584 * Activity Action: Start as a main entry point, does not expect to
585 * receive data.
586 * <p>Input: nothing
587 * <p>Output: nothing
588 */
589 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
590 public static final String ACTION_MAIN = "android.intent.action.MAIN";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800591
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700592 /**
593 * Activity Action: Display the data to the user. This is the most common
594 * action performed on data -- it is the generic action you can use on
595 * a piece of data to get the most reasonable thing to occur. For example,
596 * when used on a contacts entry it will view the entry; when used on a
597 * mailto: URI it will bring up a compose window filled with the information
598 * supplied by the URI; when used with a tel: URI it will invoke the
599 * dialer.
600 * <p>Input: {@link #getData} is URI from which to retrieve data.
601 * <p>Output: nothing.
602 */
603 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
604 public static final String ACTION_VIEW = "android.intent.action.VIEW";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800605
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700606 /**
607 * A synonym for {@link #ACTION_VIEW}, the "standard" action that is
608 * performed on a piece of data.
609 */
610 public static final String ACTION_DEFAULT = ACTION_VIEW;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800611
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700612 /**
613 * Used to indicate that some piece of data should be attached to some other
614 * place. For example, image data could be attached to a contact. It is up
615 * to the recipient to decide where the data should be attached; the intent
616 * does not specify the ultimate destination.
617 * <p>Input: {@link #getData} is URI of data to be attached.
618 * <p>Output: nothing.
619 */
620 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
621 public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800622
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700623 /**
624 * Activity Action: Provide explicit editable access to the given data.
625 * <p>Input: {@link #getData} is URI of data to be edited.
626 * <p>Output: nothing.
627 */
628 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
629 public static final String ACTION_EDIT = "android.intent.action.EDIT";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800630
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700631 /**
632 * Activity Action: Pick an existing item, or insert a new item, and then edit it.
633 * <p>Input: {@link #getType} is the desired MIME type of the item to create or edit.
634 * The extras can contain type specific data to pass through to the editing/creating
635 * activity.
636 * <p>Output: The URI of the item that was picked. This must be a content:
637 * URI so that any receiver can access it.
638 */
639 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
640 public static final String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800641
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700642 /**
643 * Activity Action: Pick an item from the data, returning what was selected.
644 * <p>Input: {@link #getData} is URI containing a directory of data
645 * (vnd.android.cursor.dir/*) from which to pick an item.
646 * <p>Output: The URI of the item that was picked.
647 */
648 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
649 public static final String ACTION_PICK = "android.intent.action.PICK";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800650
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700651 /**
652 * Activity Action: Creates a shortcut.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800653 * <p>Input: Nothing.</p>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700654 * <p>Output: An Intent representing the shortcut. The intent must contain three
655 * extras: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String),
656 * and SHORTCUT_ICON (value: Bitmap) or SHORTCUT_ICON_RESOURCE
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800657 * (value: ShortcutIconResource).</p>
658 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700659 * @see #EXTRA_SHORTCUT_INTENT
660 * @see #EXTRA_SHORTCUT_NAME
661 * @see #EXTRA_SHORTCUT_ICON
662 * @see #EXTRA_SHORTCUT_ICON_RESOURCE
663 * @see android.content.Intent.ShortcutIconResource
664 */
665 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
666 public static final String ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
667
668 /**
669 * The name of the extra used to define the Intent of a shortcut.
670 *
671 * @see #ACTION_CREATE_SHORTCUT
672 */
673 public static final String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
674 /**
675 * The name of the extra used to define the name of a shortcut.
676 *
677 * @see #ACTION_CREATE_SHORTCUT
678 */
679 public static final String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
680 /**
681 * The name of the extra used to define the icon, as a Bitmap, of a shortcut.
682 *
683 * @see #ACTION_CREATE_SHORTCUT
684 */
685 public static final String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
686 /**
687 * The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.
688 *
689 * @see #ACTION_CREATE_SHORTCUT
690 * @see android.content.Intent.ShortcutIconResource
691 */
692 public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
693 "android.intent.extra.shortcut.ICON_RESOURCE";
694
695 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800696 * Represents a shortcut/live folder icon resource.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700697 *
698 * @see Intent#ACTION_CREATE_SHORTCUT
699 * @see Intent#EXTRA_SHORTCUT_ICON_RESOURCE
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800700 * @see android.provider.LiveFolders#ACTION_CREATE_LIVE_FOLDER
701 * @see android.provider.LiveFolders#EXTRA_LIVE_FOLDER_ICON
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700702 */
703 public static class ShortcutIconResource implements Parcelable {
704 /**
705 * The package name of the application containing the icon.
706 */
707 public String packageName;
708
709 /**
710 * The resource name of the icon, including package, name and type.
711 */
712 public String resourceName;
713
714 /**
715 * Creates a new ShortcutIconResource for the specified context and resource
716 * identifier.
717 *
718 * @param context The context of the application.
719 * @param resourceId The resource idenfitier for the icon.
720 * @return A new ShortcutIconResource with the specified's context package name
721 * and icon resource idenfitier.
722 */
723 public static ShortcutIconResource fromContext(Context context, int resourceId) {
724 ShortcutIconResource icon = new ShortcutIconResource();
725 icon.packageName = context.getPackageName();
726 icon.resourceName = context.getResources().getResourceName(resourceId);
727 return icon;
728 }
729
730 /**
731 * Used to read a ShortcutIconResource from a Parcel.
732 */
733 public static final Parcelable.Creator<ShortcutIconResource> CREATOR =
734 new Parcelable.Creator<ShortcutIconResource>() {
735
736 public ShortcutIconResource createFromParcel(Parcel source) {
737 ShortcutIconResource icon = new ShortcutIconResource();
738 icon.packageName = source.readString();
739 icon.resourceName = source.readString();
740 return icon;
741 }
742
743 public ShortcutIconResource[] newArray(int size) {
744 return new ShortcutIconResource[size];
745 }
746 };
747
748 /**
749 * No special parcel contents.
750 */
751 public int describeContents() {
752 return 0;
753 }
754
755 public void writeToParcel(Parcel dest, int flags) {
756 dest.writeString(packageName);
757 dest.writeString(resourceName);
758 }
759
760 @Override
761 public String toString() {
762 return resourceName;
763 }
764 }
765
766 /**
767 * Activity Action: Display an activity chooser, allowing the user to pick
768 * what they want to before proceeding. This can be used as an alternative
769 * to the standard activity picker that is displayed by the system when
770 * you try to start an activity with multiple possible matches, with these
771 * differences in behavior:
772 * <ul>
773 * <li>You can specify the title that will appear in the activity chooser.
774 * <li>The user does not have the option to make one of the matching
775 * activities a preferred activity, and all possible activities will
776 * always be shown even if one of them is currently marked as the
777 * preferred activity.
778 * </ul>
779 * <p>
780 * This action should be used when the user will naturally expect to
781 * select an activity in order to proceed. An example if when not to use
782 * it is when the user clicks on a "mailto:" link. They would naturally
783 * expect to go directly to their mail app, so startActivity() should be
784 * called directly: it will
785 * either launch the current preferred app, or put up a dialog allowing the
786 * user to pick an app to use and optionally marking that as preferred.
787 * <p>
788 * In contrast, if the user is selecting a menu item to send a picture
789 * they are viewing to someone else, there are many different things they
790 * may want to do at this point: send it through e-mail, upload it to a
791 * web service, etc. In this case the CHOOSER action should be used, to
792 * always present to the user a list of the things they can do, with a
793 * nice title given by the caller such as "Send this photo with:".
794 * <p>
795 * As a convenience, an Intent of this form can be created with the
796 * {@link #createChooser} function.
797 * <p>Input: No data should be specified. get*Extra must have
798 * a {@link #EXTRA_INTENT} field containing the Intent being executed,
799 * and can optionally have a {@link #EXTRA_TITLE} field containing the
800 * title text to display in the chooser.
801 * <p>Output: Depends on the protocol of {@link #EXTRA_INTENT}.
802 */
803 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
804 public static final String ACTION_CHOOSER = "android.intent.action.CHOOSER";
805
806 /**
807 * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
808 *
809 * @param target The Intent that the user will be selecting an activity
810 * to perform.
811 * @param title Optional title that will be displayed in the chooser.
812 * @return Return a new Intent object that you can hand to
813 * {@link Context#startActivity(Intent) Context.startActivity()} and
814 * related methods.
815 */
816 public static Intent createChooser(Intent target, CharSequence title) {
817 Intent intent = new Intent(ACTION_CHOOSER);
818 intent.putExtra(EXTRA_INTENT, target);
819 if (title != null) {
820 intent.putExtra(EXTRA_TITLE, title);
821 }
822 return intent;
823 }
824 /**
825 * Activity Action: Allow the user to select a particular kind of data and
826 * return it. This is different than {@link #ACTION_PICK} in that here we
827 * just say what kind of data is desired, not a URI of existing data from
828 * which the user can pick. A ACTION_GET_CONTENT could allow the user to
829 * create the data as it runs (for example taking a picture or recording a
830 * sound), let them browser over the web and download the desired data,
831 * etc.
832 * <p>
833 * There are two main ways to use this action: if you want an specific kind
834 * of data, such as a person contact, you set the MIME type to the kind of
835 * data you want and launch it with {@link Context#startActivity(Intent)}.
836 * The system will then launch the best application to select that kind
837 * of data for you.
838 * <p>
839 * You may also be interested in any of a set of types of content the user
840 * can pick. For example, an e-mail application that wants to allow the
841 * user to add an attachment to an e-mail message can use this action to
842 * bring up a list of all of the types of content the user can attach.
843 * <p>
844 * In this case, you should wrap the GET_CONTENT intent with a chooser
845 * (through {@link #createChooser}), which will give the proper interface
846 * for the user to pick how to send your data and allow you to specify
847 * a prompt indicating what they are doing. You will usually specify a
848 * broad MIME type (such as image/* or {@literal *}/*), resulting in a
849 * broad range of content types the user can select from.
850 * <p>
851 * When using such a broad GET_CONTENT action, it is often desireable to
852 * only pick from data that can be represented as a stream. This is
853 * accomplished by requiring the {@link #CATEGORY_OPENABLE} in the Intent.
854 * <p>
855 * Input: {@link #getType} is the desired MIME type to retrieve. Note
856 * that no URI is supplied in the intent, as there are no constraints on
857 * where the returned data originally comes from. You may also include the
858 * {@link #CATEGORY_OPENABLE} if you can only accept data that can be
859 * opened as a stream.
860 * <p>
861 * Output: The URI of the item that was picked. This must be a content:
862 * URI so that any receiver can access it.
863 */
864 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
865 public static final String ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
866 /**
867 * Activity Action: Dial a number as specified by the data. This shows a
868 * UI with the number being dialed, allowing the user to explicitly
869 * initiate the call.
870 * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
871 * is URI of a phone number to be dialed or a tel: URI of an explicit phone
872 * number.
873 * <p>Output: nothing.
874 */
875 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
876 public static final String ACTION_DIAL = "android.intent.action.DIAL";
877 /**
878 * Activity Action: Perform a call to someone specified by the data.
879 * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
880 * is URI of a phone number to be dialed or a tel: URI of an explicit phone
881 * number.
882 * <p>Output: nothing.
883 *
884 * <p>Note: there will be restrictions on which applications can initiate a
885 * call; most applications should use the {@link #ACTION_DIAL}.
886 * <p>Note: this Intent <strong>cannot</strong> be used to call emergency
887 * numbers. Applications can <strong>dial</strong> emergency numbers using
888 * {@link #ACTION_DIAL}, however.
889 */
890 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
891 public static final String ACTION_CALL = "android.intent.action.CALL";
892 /**
893 * Activity Action: Perform a call to an emergency number specified by the
894 * data.
895 * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
896 * tel: URI of an explicit phone number.
897 * <p>Output: nothing.
898 * @hide
899 */
900 public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
901 /**
902 * Activity action: Perform a call to any number (emergency or not)
903 * specified by the data.
904 * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
905 * tel: URI of an explicit phone number.
906 * <p>Output: nothing.
907 * @hide
908 */
909 public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
910 /**
911 * Activity Action: Send a message to someone specified by the data.
912 * <p>Input: {@link #getData} is URI describing the target.
913 * <p>Output: nothing.
914 */
915 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
916 public static final String ACTION_SENDTO = "android.intent.action.SENDTO";
917 /**
918 * Activity Action: Deliver some data to someone else. Who the data is
919 * being delivered to is not specified; it is up to the receiver of this
920 * action to ask the user where the data should be sent.
921 * <p>
922 * When launching a SEND intent, you should usually wrap it in a chooser
923 * (through {@link #createChooser}), which will give the proper interface
924 * for the user to pick how to send your data and allow you to specify
925 * a prompt indicating what they are doing.
926 * <p>
927 * Input: {@link #getType} is the MIME type of the data being sent.
928 * get*Extra can have either a {@link #EXTRA_TEXT}
929 * or {@link #EXTRA_STREAM} field, containing the data to be sent. If
930 * using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it
931 * should be the MIME type of the data in EXTRA_STREAM. Use {@literal *}/*
932 * if the MIME type is unknown (this will only allow senders that can
933 * handle generic data streams).
934 * <p>
935 * Optional standard extras, which may be interpreted by some recipients as
936 * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
937 * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
938 * <p>
939 * Output: nothing.
940 */
941 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
942 public static final String ACTION_SEND = "android.intent.action.SEND";
943 /**
Wu-cheng Li649f99e2009-06-17 14:29:57 +0800944 * Activity Action: Deliver multiple data to someone else.
945 * <p>
946 * Like ACTION_SEND, except the data is multiple.
947 * <p>
948 * Input: {@link #getType} is the MIME type of the data being sent.
949 * get*ArrayListExtra can have either a {@link #EXTRA_TEXT} or {@link
950 * #EXTRA_STREAM} field, containing the data to be sent.
951 * <p>
Chih-Chung Chang5962d272009-09-04 14:36:01 +0800952 * Multiple types are supported, and receivers should handle mixed types
953 * whenever possible. The right way for the receiver to check them is to
954 * use the content resolver on each URI. The intent sender should try to
955 * put the most concrete mime type in the intent type, but it can fall
956 * back to {@literal <type>/*} or {@literal *}/* as needed.
957 * <p>
958 * e.g. if you are sending image/jpg and image/jpg, the intent's type can
959 * be image/jpg, but if you are sending image/jpg and image/png, then the
960 * intent's type should be image/*.
961 * <p>
Wu-cheng Li649f99e2009-06-17 14:29:57 +0800962 * Optional standard extras, which may be interpreted by some recipients as
963 * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
964 * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
965 * <p>
966 * Output: nothing.
967 */
968 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
969 public static final String ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE";
970 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700971 * Activity Action: Handle an incoming phone call.
972 * <p>Input: nothing.
973 * <p>Output: nothing.
974 */
975 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
976 public static final String ACTION_ANSWER = "android.intent.action.ANSWER";
977 /**
978 * Activity Action: Insert an empty item into the given container.
979 * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
980 * in which to place the data.
981 * <p>Output: URI of the new data that was created.
982 */
983 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
984 public static final String ACTION_INSERT = "android.intent.action.INSERT";
985 /**
986 * Activity Action: Delete the given data from its container.
987 * <p>Input: {@link #getData} is URI of data to be deleted.
988 * <p>Output: nothing.
989 */
990 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
991 public static final String ACTION_DELETE = "android.intent.action.DELETE";
992 /**
993 * Activity Action: Run the data, whatever that means.
994 * <p>Input: ? (Note: this is currently specific to the test harness.)
995 * <p>Output: nothing.
996 */
997 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
998 public static final String ACTION_RUN = "android.intent.action.RUN";
999 /**
1000 * Activity Action: Perform a data synchronization.
1001 * <p>Input: ?
1002 * <p>Output: ?
1003 */
1004 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1005 public static final String ACTION_SYNC = "android.intent.action.SYNC";
1006 /**
1007 * Activity Action: Pick an activity given an intent, returning the class
1008 * selected.
1009 * <p>Input: get*Extra field {@link #EXTRA_INTENT} is an Intent
1010 * used with {@link PackageManager#queryIntentActivities} to determine the
1011 * set of activities from which to pick.
1012 * <p>Output: Class name of the activity that was selected.
1013 */
1014 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1015 public static final String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
1016 /**
1017 * Activity Action: Perform a search.
1018 * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
1019 * is the text to search for. If empty, simply
1020 * enter your search results Activity with the search UI activated.
1021 * <p>Output: nothing.
1022 */
1023 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1024 public static final String ACTION_SEARCH = "android.intent.action.SEARCH";
1025 /**
Jim Miller7e4ad352009-03-25 18:16:41 -07001026 * Activity Action: Start the platform-defined tutorial
1027 * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
1028 * is the text to search for. If empty, simply
1029 * enter your search results Activity with the search UI activated.
1030 * <p>Output: nothing.
1031 */
1032 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1033 public static final String ACTION_SYSTEM_TUTORIAL = "android.intent.action.SYSTEM_TUTORIAL";
1034 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001035 * Activity Action: Perform a web search.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001036 * <p>
1037 * Input: {@link android.app.SearchManager#QUERY
1038 * getStringExtra(SearchManager.QUERY)} is the text to search for. If it is
1039 * a url starts with http or https, the site will be opened. If it is plain
1040 * text, Google search will be applied.
1041 * <p>
1042 * Output: nothing.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001043 */
1044 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1045 public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
1046 /**
1047 * Activity Action: List all available applications
1048 * <p>Input: Nothing.
1049 * <p>Output: nothing.
1050 */
1051 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1052 public static final String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
1053 /**
1054 * Activity Action: Show settings for choosing wallpaper
1055 * <p>Input: Nothing.
1056 * <p>Output: Nothing.
1057 */
1058 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1059 public static final String ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
1060
1061 /**
1062 * Activity Action: Show activity for reporting a bug.
1063 * <p>Input: Nothing.
1064 * <p>Output: Nothing.
1065 */
1066 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1067 public static final String ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
1068
1069 /**
1070 * Activity Action: Main entry point for factory tests. Only used when
1071 * the device is booting in factory test node. The implementing package
1072 * must be installed in the system image.
1073 * <p>Input: nothing
1074 * <p>Output: nothing
1075 */
1076 public static final String ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
1077
1078 /**
1079 * Activity Action: The user pressed the "call" button to go to the dialer
1080 * or other appropriate UI for placing a call.
1081 * <p>Input: Nothing.
1082 * <p>Output: Nothing.
1083 */
1084 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1085 public static final String ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
1086
1087 /**
1088 * Activity Action: Start Voice Command.
1089 * <p>Input: Nothing.
1090 * <p>Output: Nothing.
1091 */
1092 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1093 public static final String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001094
1095 /**
1096 * Activity Action: Start action associated with long pressing on the
1097 * search key.
1098 * <p>Input: Nothing.
1099 * <p>Output: Nothing.
1100 */
1101 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1102 public static final String ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";
The Android Open Source Project10592532009-03-18 17:39:46 -07001103
Jacek Surazski86b6c532009-05-13 14:38:28 +02001104 /**
Bjorn Bringert3c50ef62009-12-09 12:23:12 +00001105 * Activity Action: Start the global search activity.
1106 * <p>Input: Nothing.
1107 * <p>Output: Nothing.
1108 *
1109 * @hide Pending API council approval
1110 */
1111 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1112 public static final String ACTION_GLOBAL_SEARCH = "android.intent.action.GLOBAL_SEARCH";
1113
1114 /**
Jacek Surazski86b6c532009-05-13 14:38:28 +02001115 * Activity Action: The user pressed the "Report" button in the crash/ANR dialog.
1116 * This intent is delivered to the package which installed the application, usually
1117 * the Market.
1118 * <p>Input: No data is specified. The bug report is passed in using
1119 * an {@link #EXTRA_BUG_REPORT} field.
1120 * <p>Output: Nothing.
1121 * @hide
1122 */
1123 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1124 public static final String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
Dianne Hackborn3d74bb42009-06-19 10:35:21 -07001125
1126 /**
1127 * Activity Action: Show power usage information to the user.
1128 * <p>Input: Nothing.
1129 * <p>Output: Nothing.
1130 */
1131 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1132 public static final String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
1133
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07001134 /**
1135 * Activity Action: Setup wizard to launch after a platform update. This
1136 * activity should have a string meta-data field associated with it,
1137 * {@link #METADATA_SETUP_VERSION}, which defines the current version of
1138 * the platform for setup. The activity will be launched only if
1139 * {@link android.provider.Settings.Secure#LAST_SETUP_SHOWN} is not the
1140 * same value.
1141 * <p>Input: Nothing.
1142 * <p>Output: Nothing.
1143 * @hide
1144 */
1145 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1146 public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
1147
1148 /**
1149 * A string associated with a {@link #ACTION_UPGRADE_SETUP} activity
1150 * describing the last run version of the platform that was setup.
1151 * @hide
1152 */
1153 public static final String METADATA_SETUP_VERSION = "android.SETUP_VERSION";
1154
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001155 // ---------------------------------------------------------------------
1156 // ---------------------------------------------------------------------
1157 // Standard intent broadcast actions (see action variable).
1158
1159 /**
1160 * Broadcast Action: Sent after the screen turns off.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001161 *
1162 * <p class="note">This is a protected intent that can only be sent
1163 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001164 */
1165 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1166 public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
1167 /**
1168 * Broadcast Action: Sent after the screen turns on.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001169 *
1170 * <p class="note">This is a protected intent that can only be sent
1171 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001172 */
1173 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1174 public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001175
1176 /**
The Android Open Source Project10592532009-03-18 17:39:46 -07001177 * Broadcast Action: Sent when the user is present after device wakes up (e.g when the
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001178 * keyguard is gone).
Dianne Hackborn854060af2009-07-09 18:14:31 -07001179 *
1180 * <p class="note">This is a protected intent that can only be sent
1181 * by the system.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001182 */
1183 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001184 public static final String ACTION_USER_PRESENT = "android.intent.action.USER_PRESENT";
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001185
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001186 /**
1187 * Broadcast Action: The current time has changed. Sent every
1188 * minute. You can <em>not</em> receive this through components declared
1189 * in manifests, only by exlicitly registering for it with
1190 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1191 * Context.registerReceiver()}.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001192 *
1193 * <p class="note">This is a protected intent that can only be sent
1194 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001195 */
1196 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1197 public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
1198 /**
1199 * Broadcast Action: The time was set.
1200 */
1201 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1202 public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
1203 /**
1204 * Broadcast Action: The date has changed.
1205 */
1206 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1207 public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
1208 /**
1209 * Broadcast Action: The timezone has changed. The intent will have the following extra values:</p>
1210 * <ul>
1211 * <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time zone.</li>
1212 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001213 *
1214 * <p class="note">This is a protected intent that can only be sent
1215 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001216 */
1217 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1218 public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
1219 /**
1220 * Alarm Changed Action: This is broadcast when the AlarmClock
1221 * application's alarm is set or unset. It is used by the
1222 * AlarmClock application and the StatusBar service.
1223 * @hide
1224 */
1225 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1226 public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
1227 /**
1228 * Sync State Changed Action: This is broadcast when the sync starts or stops or when one has
1229 * been failing for a long time. It is used by the SyncManager and the StatusBar service.
1230 * @hide
1231 */
1232 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1233 public static final String ACTION_SYNC_STATE_CHANGED
1234 = "android.intent.action.SYNC_STATE_CHANGED";
1235 /**
1236 * Broadcast Action: This is broadcast once, after the system has finished
1237 * booting. It can be used to perform application-specific initialization,
1238 * such as installing alarms. You must hold the
1239 * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
1240 * in order to receive this broadcast.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001241 *
1242 * <p class="note">This is a protected intent that can only be sent
1243 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001244 */
1245 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1246 public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
1247 /**
1248 * Broadcast Action: This is broadcast when a user action should request a
1249 * temporary system dialog to dismiss. Some examples of temporary system
1250 * dialogs are the notification window-shade and the recent tasks dialog.
1251 */
1252 public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
1253 /**
1254 * Broadcast Action: Trigger the download and eventual installation
1255 * of a package.
1256 * <p>Input: {@link #getData} is the URI of the package file to download.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001257 *
1258 * <p class="note">This is a protected intent that can only be sent
1259 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001260 */
1261 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1262 public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
1263 /**
1264 * Broadcast Action: A new application package has been installed on the
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001265 * device. The data contains the name of the package. Note that the
1266 * newly installed package does <em>not</em> receive this broadcast.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 * <p>My include the following extras:
1268 * <ul>
1269 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1270 * <li> {@link #EXTRA_REPLACING} is set to true if this is following
1271 * an {@link #ACTION_PACKAGE_REMOVED} broadcast for the same package.
1272 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001273 *
1274 * <p class="note">This is a protected intent that can only be sent
1275 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001276 */
1277 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1278 public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
1279 /**
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001280 * Broadcast Action: A new version of an application package has been
1281 * installed, replacing an existing version that was previously installed.
1282 * The data contains the name of the package.
1283 * <p>My include the following extras:
1284 * <ul>
1285 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1286 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001287 *
1288 * <p class="note">This is a protected intent that can only be sent
1289 * by the system.
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001290 */
1291 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1292 public static final String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
1293 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001294 * Broadcast Action: An existing application package has been removed from
1295 * the device. The data contains the name of the package. The package
1296 * that is being installed does <em>not</em> receive this Intent.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 * <ul>
1298 * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1299 * to the package.
1300 * <li> {@link #EXTRA_DATA_REMOVED} is set to true if the entire
1301 * application -- data and code -- is being removed.
1302 * <li> {@link #EXTRA_REPLACING} is set to true if this will be followed
1303 * by an {@link #ACTION_PACKAGE_ADDED} broadcast for the same package.
1304 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001305 *
1306 * <p class="note">This is a protected intent that can only be sent
1307 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001308 */
1309 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1310 public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
1311 /**
Dianne Hackborn86a72da2009-11-11 20:12:41 -08001312 * Broadcast Action: An existing application package has been changed (e.g.
1313 * a component has been enabled or disabled). The data contains the name of
1314 * the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 * <ul>
1316 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
Dianne Hackborn86a72da2009-11-11 20:12:41 -08001317 * <li> {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST} containing the class name
1318 * of the changed components.
1319 * <li> {@link #EXTRA_DONT_KILL_APP} containing boolean field to override the
1320 * default action of restarting the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001322 *
1323 * <p class="note">This is a protected intent that can only be sent
1324 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001325 */
1326 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1327 public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
1328 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 * Broadcast Action: The user has restarted a package, and all of its
1330 * processes have been killed. All runtime state
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001331 * associated with it (processes, alarms, notifications, etc) should
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001332 * be removed. Note that the restarted package does <em>not</em>
1333 * receive this broadcast.
1334 * The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 * <ul>
1336 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1337 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001338 *
1339 * <p class="note">This is a protected intent that can only be sent
1340 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001341 */
1342 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1343 public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
1344 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 * Broadcast Action: The user has cleared the data of a package. This should
1346 * be preceded by {@link #ACTION_PACKAGE_RESTARTED}, after which all of
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001347 * its persistent data is erased and this broadcast sent.
1348 * Note that the cleared package does <em>not</em>
1349 * receive this broadcast. The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 * <ul>
1351 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1352 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001353 *
1354 * <p class="note">This is a protected intent that can only be sent
1355 * by the system.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 */
1357 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1358 public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
1359 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001360 * Broadcast Action: A user ID has been removed from the system. The user
1361 * ID number is stored in the extra data under {@link #EXTRA_UID}.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001362 *
1363 * <p class="note">This is a protected intent that can only be sent
1364 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001365 */
1366 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1367 public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
1368 /**
1369 * Broadcast Action: The current system wallpaper has changed. See
Scott Main8b2e0002009-09-29 18:17:31 -07001370 * {@link android.app.WallpaperManager} for retrieving the new wallpaper.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001371 */
1372 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1373 public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
1374 /**
1375 * Broadcast Action: The current device {@link android.content.res.Configuration}
1376 * (orientation, locale, etc) has changed. When such a change happens, the
1377 * UIs (view hierarchy) will need to be rebuilt based on this new
1378 * information; for the most part, applications don't need to worry about
1379 * this, because the system will take care of stopping and restarting the
1380 * application to make sure it sees the new changes. Some system code that
1381 * can not be restarted will need to watch for this action and handle it
1382 * appropriately.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001383 *
Dianne Hackborn362d5b92009-11-11 18:04:39 -08001384 * <p class="note">
1385 * You can <em>not</em> receive this through components declared
1386 * in manifests, only by explicitly registering for it with
1387 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1388 * Context.registerReceiver()}.
1389 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001390 * <p class="note">This is a protected intent that can only be sent
1391 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001392 *
1393 * @see android.content.res.Configuration
1394 */
1395 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1396 public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
1397 /**
Dianne Hackborn362d5b92009-11-11 18:04:39 -08001398 * Broadcast Action: The current device's locale has changed.
1399 *
1400 * <p class="note">This is a protected intent that can only be sent
1401 * by the system.
1402 */
1403 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1404 public static final String ACTION_LOCALE_CHANGED = "android.intent.action.LOCALE_CHANGED";
1405 /**
Dianne Hackbornedd93162009-09-19 14:03:05 -07001406 * Broadcast Action: This is a <em>sticky broadcast</em> containing the
1407 * charging state, level, and other information about the battery.
1408 * See {@link android.os.BatteryManager} for documentation on the
1409 * contents of the Intent.
The Android Open Source Project10592532009-03-18 17:39:46 -07001410 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001411 * <p class="note">
1412 * You can <em>not</em> receive this through components declared
Dianne Hackborn854060af2009-07-09 18:14:31 -07001413 * in manifests, only by explicitly registering for it with
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001414 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
Dianne Hackbornedd93162009-09-19 14:03:05 -07001415 * Context.registerReceiver()}. See {@link #ACTION_BATTERY_LOW},
1416 * {@link #ACTION_BATTERY_OKAY}, {@link #ACTION_POWER_CONNECTED},
1417 * and {@link #ACTION_POWER_DISCONNECTED} for distinct battery-related
1418 * broadcasts that are sent and can be received through manifest
1419 * receivers.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001420 *
1421 * <p class="note">This is a protected intent that can only be sent
1422 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001423 */
1424 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1425 public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
1426 /**
1427 * Broadcast Action: Indicates low battery condition on the device.
1428 * This broadcast corresponds to the "Low battery warning" system dialog.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001429 *
1430 * <p class="note">This is a protected intent that can only be sent
1431 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001432 */
1433 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1434 public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
1435 /**
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001436 * Broadcast Action: Indicates the battery is now okay after being low.
1437 * This will be sent after {@link #ACTION_BATTERY_LOW} once the battery has
1438 * gone back up to an okay state.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001439 *
1440 * <p class="note">This is a protected intent that can only be sent
1441 * by the system.
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001442 */
1443 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1444 public static final String ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";
1445 /**
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001446 * Broadcast Action: External power has been connected to the device.
1447 * This is intended for applications that wish to register specifically to this notification.
1448 * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1449 * stay active to receive this notification. This action can be used to implement actions
1450 * that wait until power is available to trigger.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001451 *
1452 * <p class="note">This is a protected intent that can only be sent
1453 * by the system.
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001454 */
1455 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001456 public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001457 /**
1458 * Broadcast Action: External power has been removed from the device.
1459 * This is intended for applications that wish to register specifically to this notification.
1460 * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1461 * stay active to receive this notification. This action can be used to implement actions
Romain Guy4969af72009-06-17 10:53:19 -07001462 * that wait until power is available to trigger.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001463 *
1464 * <p class="note">This is a protected intent that can only be sent
1465 * by the system.
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001466 */
1467 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jean-Baptiste Queru1ef45642008-10-24 11:49:25 -07001468 public static final String ACTION_POWER_DISCONNECTED =
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001469 "android.intent.action.ACTION_POWER_DISCONNECTED";
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001470 /**
Dianne Hackborn55280a92009-05-07 15:53:46 -07001471 * Broadcast Action: Device is shutting down.
1472 * This is broadcast when the device is being shut down (completely turned
1473 * off, not sleeping). Once the broadcast is complete, the final shutdown
1474 * will proceed and all unsaved data lost. Apps will not normally need
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001475 * to handle this, since the foreground activity will be paused as well.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001476 *
1477 * <p class="note">This is a protected intent that can only be sent
1478 * by the system.
Dianne Hackborn55280a92009-05-07 15:53:46 -07001479 */
1480 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Romain Guy4969af72009-06-17 10:53:19 -07001481 public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
Dianne Hackborn55280a92009-05-07 15:53:46 -07001482 /**
Mike Lockwoodbad80e02009-07-30 01:21:08 -07001483 * Activity Action: Start this activity to request system shutdown.
1484 * The optional boolean extra field {@link #EXTRA_KEY_CONFIRM} can be set to true
1485 * to request confirmation from the user before shutting down.
1486 *
1487 * <p class="note">This is a protected intent that can only be sent
1488 * by the system.
1489 *
1490 * {@hide}
1491 */
1492 public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
1493 /**
Dianne Hackbornedd93162009-09-19 14:03:05 -07001494 * Broadcast Action: A sticky broadcast that indicates low memory
1495 * condition on the device
Dianne Hackborn854060af2009-07-09 18:14:31 -07001496 *
1497 * <p class="note">This is a protected intent that can only be sent
1498 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001499 */
1500 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1501 public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
1502 /**
1503 * Broadcast Action: Indicates low memory condition on the device no longer exists
Dianne Hackborn854060af2009-07-09 18:14:31 -07001504 *
1505 * <p class="note">This is a protected intent that can only be sent
1506 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001507 */
1508 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1509 public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
1510 /**
1511 * Broadcast Action: Indicates low memory condition notification acknowledged by user
1512 * and package management should be started.
1513 * This is triggered by the user from the ACTION_DEVICE_STORAGE_LOW
1514 * notification.
1515 */
1516 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1517 public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
1518 /**
1519 * Broadcast Action: The device has entered USB Mass Storage mode.
1520 * This is used mainly for the USB Settings panel.
1521 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1522 * when the SD card file system is mounted or unmounted
1523 */
1524 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1525 public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
1526
1527 /**
1528 * Broadcast Action: The device has exited USB Mass Storage mode.
1529 * This is used mainly for the USB Settings panel.
1530 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1531 * when the SD card file system is mounted or unmounted
1532 */
1533 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1534 public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
1535
1536 /**
1537 * Broadcast Action: External media has been removed.
1538 * The path to the mount point for the removed media is contained in the Intent.mData field.
1539 */
1540 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1541 public static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
1542
1543 /**
1544 * Broadcast Action: External media is present, but not mounted at its mount point.
1545 * The path to the mount point for the removed media is contained in the Intent.mData field.
1546 */
1547 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1548 public static final String ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
1549
1550 /**
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08001551 * Broadcast Action: External media is present, and being disk-checked
1552 * The path to the mount point for the checking media is contained in the Intent.mData field.
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08001553 */
1554 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1555 public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
1556
1557 /**
1558 * Broadcast Action: External media is present, but is using an incompatible fs (or is blank)
1559 * The path to the mount point for the checking media is contained in the Intent.mData field.
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08001560 */
1561 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1562 public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
1563
1564 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001565 * Broadcast Action: External media is present and mounted at its mount point.
1566 * The path to the mount point for the removed media is contained in the Intent.mData field.
1567 * The Intent contains an extra with name "read-only" and Boolean value to indicate if the
1568 * media was mounted read only.
1569 */
1570 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1571 public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
1572
1573 /**
1574 * Broadcast Action: External media is unmounted because it is being shared via USB mass storage.
1575 * The path to the mount point for the removed media is contained in the Intent.mData field.
1576 */
1577 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1578 public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
1579
1580 /**
1581 * Broadcast Action: External media was removed from SD card slot, but mount point was not unmounted.
1582 * The path to the mount point for the removed media is contained in the Intent.mData field.
1583 */
1584 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1585 public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
1586
1587 /**
1588 * Broadcast Action: External media is present but cannot be mounted.
1589 * The path to the mount point for the removed media is contained in the Intent.mData field.
1590 */
1591 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1592 public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
1593
1594 /**
1595 * Broadcast Action: User has expressed the desire to remove the external storage media.
1596 * Applications should close all files they have open within the mount point when they receive this intent.
1597 * The path to the mount point for the media to be ejected is contained in the Intent.mData field.
1598 */
1599 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1600 public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
1601
1602 /**
1603 * Broadcast Action: The media scanner has started scanning a directory.
1604 * The path to the directory being scanned is contained in the Intent.mData field.
1605 */
1606 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1607 public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
1608
1609 /**
1610 * Broadcast Action: The media scanner has finished scanning a directory.
1611 * The path to the scanned directory is contained in the Intent.mData field.
1612 */
1613 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1614 public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
1615
1616 /**
1617 * Broadcast Action: Request the media scanner to scan a file and add it to the media database.
1618 * The path to the file is contained in the Intent.mData field.
1619 */
1620 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1621 public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
1622
1623 /**
1624 * Broadcast Action: The "Media Button" was pressed. Includes a single
1625 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1626 * caused the broadcast.
1627 */
1628 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1629 public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
1630
1631 /**
1632 * Broadcast Action: The "Camera Button" was pressed. Includes a single
1633 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1634 * caused the broadcast.
1635 */
1636 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1637 public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
1638
1639 // *** NOTE: @todo(*) The following really should go into a more domain-specific
1640 // location; they are not general-purpose actions.
1641
1642 /**
1643 * Broadcast Action: An GTalk connection has been established.
1644 */
1645 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1646 public static final String ACTION_GTALK_SERVICE_CONNECTED =
1647 "android.intent.action.GTALK_CONNECTED";
1648
1649 /**
1650 * Broadcast Action: An GTalk connection has been disconnected.
1651 */
1652 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1653 public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
1654 "android.intent.action.GTALK_DISCONNECTED";
The Android Open Source Project10592532009-03-18 17:39:46 -07001655
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001656 /**
1657 * Broadcast Action: An input method has been changed.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001658 */
1659 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1660 public static final String ACTION_INPUT_METHOD_CHANGED =
1661 "android.intent.action.INPUT_METHOD_CHANGED";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001662
1663 /**
1664 * <p>Broadcast Action: The user has switched the phone into or out of Airplane Mode. One or
1665 * more radios have been turned off or on. The intent will have the following extra value:</p>
1666 * <ul>
1667 * <li><em>state</em> - A boolean value indicating whether Airplane Mode is on. If true,
1668 * then cell radio and possibly other radios such as bluetooth or WiFi may have also been
1669 * turned off</li>
1670 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001671 *
1672 * <p class="note">This is a protected intent that can only be sent
1673 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001674 */
1675 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1676 public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
1677
1678 /**
1679 * Broadcast Action: Some content providers have parts of their namespace
1680 * where they publish new events or items that the user may be especially
1681 * interested in. For these things, they may broadcast this action when the
1682 * set of interesting items change.
1683 *
1684 * For example, GmailProvider sends this notification when the set of unread
1685 * mail in the inbox changes.
1686 *
1687 * <p>The data of the intent identifies which part of which provider
1688 * changed. When queried through the content resolver, the data URI will
1689 * return the data set in question.
1690 *
1691 * <p>The intent will have the following extra values:
1692 * <ul>
1693 * <li><em>count</em> - The number of items in the data set. This is the
1694 * same as the number of items in the cursor returned by querying the
1695 * data URI. </li>
1696 * </ul>
1697 *
1698 * This intent will be sent at boot (if the count is non-zero) and when the
1699 * data set changes. It is possible for the data set to change without the
1700 * count changing (for example, if a new unread message arrives in the same
1701 * sync operation in which a message is archived). The phone should still
1702 * ring/vibrate/etc as normal in this case.
1703 */
1704 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1705 public static final String ACTION_PROVIDER_CHANGED =
1706 "android.intent.action.PROVIDER_CHANGED";
1707
1708 /**
1709 * Broadcast Action: Wired Headset plugged in or unplugged.
1710 *
1711 * <p>The intent will have the following extra values:
1712 * <ul>
1713 * <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
1714 * <li><em>name</em> - Headset type, human readable string </li>
Eric Laurent923d7d72009-11-12 12:09:06 -08001715 * <li><em>microphone</em> - 1 if headset has a microphone, 0 otherwise </li>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001716 * </ul>
1717 * </ul>
1718 */
1719 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1720 public static final String ACTION_HEADSET_PLUG =
1721 "android.intent.action.HEADSET_PLUG";
1722
1723 /**
1724 * Broadcast Action: An outgoing call is about to be placed.
1725 *
1726 * <p>The Intent will have the following extra value:
1727 * <ul>
The Android Open Source Project10592532009-03-18 17:39:46 -07001728 * <li><em>{@link android.content.Intent#EXTRA_PHONE_NUMBER}</em> -
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001729 * the phone number originally intended to be dialed.</li>
1730 * </ul>
1731 * <p>Once the broadcast is finished, the resultData is used as the actual
1732 * number to call. If <code>null</code>, no call will be placed.</p>
The Android Open Source Project10592532009-03-18 17:39:46 -07001733 * <p>It is perfectly acceptable for multiple receivers to process the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001734 * outgoing call in turn: for example, a parental control application
1735 * might verify that the user is authorized to place the call at that
1736 * time, then a number-rewriting application might add an area code if
1737 * one was not specified.</p>
1738 * <p>For consistency, any receiver whose purpose is to prohibit phone
1739 * calls should have a priority of 0, to ensure it will see the final
1740 * phone number to be dialed.
The Android Open Source Project10592532009-03-18 17:39:46 -07001741 * Any receiver whose purpose is to rewrite phone numbers to be called
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001742 * should have a positive priority.
1743 * Negative priorities are reserved for the system for this broadcast;
1744 * using them may cause problems.</p>
1745 * <p>Any BroadcastReceiver receiving this Intent <em>must not</em>
1746 * abort the broadcast.</p>
1747 * <p>Emergency calls cannot be intercepted using this mechanism, and
1748 * other calls cannot be modified to call emergency numbers using this
1749 * mechanism.
The Android Open Source Project10592532009-03-18 17:39:46 -07001750 * <p>You must hold the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001751 * {@link android.Manifest.permission#PROCESS_OUTGOING_CALLS}
1752 * permission to receive this Intent.</p>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001753 *
1754 * <p class="note">This is a protected intent that can only be sent
1755 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001756 */
1757 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1758 public static final String ACTION_NEW_OUTGOING_CALL =
1759 "android.intent.action.NEW_OUTGOING_CALL";
1760
1761 /**
1762 * Broadcast Action: Have the device reboot. This is only for use by
1763 * system code.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001764 *
1765 * <p class="note">This is a protected intent that can only be sent
1766 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001767 */
1768 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1769 public static final String ACTION_REBOOT =
1770 "android.intent.action.REBOOT";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771
Wei Huang97ecc9c2009-05-11 17:44:20 -07001772 /**
Dianne Hackbornedd93162009-09-19 14:03:05 -07001773 * Broadcast Action: A sticky broadcast indicating the phone was docked
1774 * or undocked. Includes the extra
1775 * field {@link #EXTRA_DOCK_STATE}, containing the current dock state.
1776 * This is intended for monitoring the current dock state.
1777 * To launch an activity from a dock state change, use {@link #CATEGORY_CAR_DOCK}
1778 * or {@link #CATEGORY_DESK_DOCK} instead.
1779 */
1780 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1781 public static final String ACTION_DOCK_EVENT =
1782 "android.intent.action.DOCK_EVENT";
1783
1784 /**
Wei Huang97ecc9c2009-05-11 17:44:20 -07001785 * Broadcast Action: a remote intent is to be broadcasted.
1786 *
1787 * A remote intent is used for remote RPC between devices. The remote intent
1788 * is serialized and sent from one device to another device. The receiving
1789 * device parses the remote intent and broadcasts it. Note that anyone can
1790 * broadcast a remote intent. However, if the intent receiver of the remote intent
1791 * does not trust intent broadcasts from arbitrary intent senders, it should require
1792 * the sender to hold certain permissions so only trusted sender's broadcast will be
1793 * let through.
Dianne Hackbornedd93162009-09-19 14:03:05 -07001794 * @hide
Wei Huang97ecc9c2009-05-11 17:44:20 -07001795 */
1796 public static final String ACTION_REMOTE_INTENT =
1797 "android.intent.action.REMOTE_INTENT";
1798
Dianne Hackborn9acc0302009-08-25 00:27:12 -07001799 /**
1800 * Broadcast Action: hook for permforming cleanup after a system update.
1801 *
1802 * The broadcast is sent when the system is booting, before the
1803 * BOOT_COMPLETED broadcast. It is only sent to receivers in the system
1804 * image. A receiver for this should do its work and then disable itself
1805 * so that it does not get run again at the next boot.
1806 * @hide
1807 */
1808 public static final String ACTION_PRE_BOOT_COMPLETED =
1809 "android.intent.action.PRE_BOOT_COMPLETED";
1810
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001811 // ---------------------------------------------------------------------
1812 // ---------------------------------------------------------------------
1813 // Standard intent categories (see addCategory()).
1814
1815 /**
1816 * Set if the activity should be an option for the default action
1817 * (center press) to perform on a piece of data. Setting this will
1818 * hide from the user any activities without it set when performing an
1819 * action on some data. Note that this is normal -not- set in the
1820 * Intent when initiating an action -- it is for use in intent filters
1821 * specified in packages.
1822 */
1823 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1824 public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
1825 /**
1826 * Activities that can be safely invoked from a browser must support this
1827 * category. For example, if the user is viewing a web page or an e-mail
1828 * and clicks on a link in the text, the Intent generated execute that
1829 * link will require the BROWSABLE category, so that only activities
1830 * supporting this category will be considered as possible actions. By
1831 * supporting this category, you are promising that there is nothing
1832 * damaging (without user intervention) that can happen by invoking any
1833 * matching Intent.
1834 */
1835 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1836 public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
1837 /**
1838 * Set if the activity should be considered as an alternative action to
1839 * the data the user is currently viewing. See also
1840 * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
1841 * applies to the selection in a list of items.
1842 *
1843 * <p>Supporting this category means that you would like your activity to be
1844 * displayed in the set of alternative things the user can do, usually as
1845 * part of the current activity's options menu. You will usually want to
1846 * include a specific label in the &lt;intent-filter&gt; of this action
1847 * describing to the user what it does.
1848 *
1849 * <p>The action of IntentFilter with this category is important in that it
1850 * describes the specific action the target will perform. This generally
1851 * should not be a generic action (such as {@link #ACTION_VIEW}, but rather
1852 * a specific name such as "com.android.camera.action.CROP. Only one
1853 * alternative of any particular action will be shown to the user, so using
1854 * a specific action like this makes sure that your alternative will be
1855 * displayed while also allowing other applications to provide their own
1856 * overrides of that particular action.
1857 */
1858 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1859 public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
1860 /**
1861 * Set if the activity should be considered as an alternative selection
1862 * action to the data the user has currently selected. This is like
1863 * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list
1864 * of items from which the user can select, giving them alternatives to the
1865 * default action that will be performed on it.
1866 */
1867 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1868 public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
1869 /**
1870 * Intended to be used as a tab inside of an containing TabActivity.
1871 */
1872 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1873 public static final String CATEGORY_TAB = "android.intent.category.TAB";
1874 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001875 * Should be displayed in the top-level launcher.
1876 */
1877 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1878 public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
1879 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 * Provides information about the package it is in; typically used if
1881 * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
1882 * a front-door to the user without having to be shown in the all apps list.
1883 */
1884 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1885 public static final String CATEGORY_INFO = "android.intent.category.INFO";
1886 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001887 * This is the home activity, that is the first activity that is displayed
1888 * when the device boots.
1889 */
1890 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1891 public static final String CATEGORY_HOME = "android.intent.category.HOME";
1892 /**
1893 * This activity is a preference panel.
1894 */
1895 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1896 public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
1897 /**
1898 * This activity is a development preference panel.
1899 */
1900 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1901 public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
1902 /**
1903 * Capable of running inside a parent activity container.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001904 */
1905 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1906 public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
1907 /**
1908 * This activity may be exercised by the monkey or other automated test tools.
1909 */
1910 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1911 public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
1912 /**
1913 * To be used as a test (not part of the normal user experience).
1914 */
1915 public static final String CATEGORY_TEST = "android.intent.category.TEST";
1916 /**
1917 * To be used as a unit test (run through the Test Harness).
1918 */
1919 public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
1920 /**
1921 * To be used as an sample code example (not part of the normal user
1922 * experience).
1923 */
1924 public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
1925 /**
1926 * Used to indicate that a GET_CONTENT intent only wants URIs that can be opened with
1927 * ContentResolver.openInputStream. Openable URIs must support the columns in OpenableColumns
1928 * when queried, though it is allowable for those columns to be blank.
1929 */
1930 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1931 public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
1932
1933 /**
1934 * To be used as code under test for framework instrumentation tests.
1935 */
1936 public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
1937 "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
Mike Lockwood9092ab42009-09-16 13:01:32 -04001938 /**
1939 * An activity to run when device is inserted into a car dock.
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001940 * Used with {@link #ACTION_MAIN} to launch an activity.
Mike Lockwood9092ab42009-09-16 13:01:32 -04001941 * To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
1942 */
1943 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1944 public static final String CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
1945 /**
1946 * An activity to run when device is inserted into a car dock.
1947 * Used with {@link #ACTION_MAIN} to launch an activity.
1948 * To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
1949 */
1950 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1951 public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05001952
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001953 // ---------------------------------------------------------------------
1954 // ---------------------------------------------------------------------
1955 // Standard extra data keys.
1956
1957 /**
1958 * The initial data to place in a newly created record. Use with
1959 * {@link #ACTION_INSERT}. The data here is a Map containing the same
1960 * fields as would be given to the underlying ContentProvider.insert()
1961 * call.
1962 */
1963 public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
1964
1965 /**
1966 * A constant CharSequence that is associated with the Intent, used with
1967 * {@link #ACTION_SEND} to supply the literal data to be sent. Note that
1968 * this may be a styled CharSequence, so you must use
1969 * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to
1970 * retrieve it.
1971 */
1972 public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
1973
1974 /**
1975 * A content: URI holding a stream of data associated with the Intent,
1976 * used with {@link #ACTION_SEND} to supply the data being sent.
1977 */
1978 public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
1979
1980 /**
1981 * A String[] holding e-mail addresses that should be delivered to.
1982 */
1983 public static final String EXTRA_EMAIL = "android.intent.extra.EMAIL";
1984
1985 /**
1986 * A String[] holding e-mail addresses that should be carbon copied.
1987 */
1988 public static final String EXTRA_CC = "android.intent.extra.CC";
1989
1990 /**
1991 * A String[] holding e-mail addresses that should be blind carbon copied.
1992 */
1993 public static final String EXTRA_BCC = "android.intent.extra.BCC";
1994
1995 /**
1996 * A constant string holding the desired subject line of a message.
1997 */
1998 public static final String EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
1999
2000 /**
2001 * An Intent describing the choices you would like shown with
2002 * {@link #ACTION_PICK_ACTIVITY}.
2003 */
2004 public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
2005
2006 /**
2007 * A CharSequence dialog title to provide to the user when used with a
2008 * {@link #ACTION_CHOOSER}.
2009 */
2010 public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
2011
2012 /**
Dianne Hackborneb034652009-09-07 00:49:58 -07002013 * A Parcelable[] of {@link Intent} or
2014 * {@link android.content.pm.LabeledIntent} objects as set with
2015 * {@link #putExtra(String, Parcelable[])} of additional activities to place
2016 * a the front of the list of choices, when shown to the user with a
2017 * {@link #ACTION_CHOOSER}.
2018 */
2019 public static final String EXTRA_INITIAL_INTENTS = "android.intent.extra.INITIAL_INTENTS";
2020
2021 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002022 * A {@link android.view.KeyEvent} object containing the event that
2023 * triggered the creation of the Intent it is in.
2024 */
2025 public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
2026
2027 /**
Mike Lockwoodbad80e02009-07-30 01:21:08 -07002028 * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to request confirmation from the user
2029 * before shutting down.
2030 *
2031 * {@hide}
2032 */
2033 public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";
2034
2035 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002036 * Used as an boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
2037 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
2038 * of restarting the application.
2039 */
2040 public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
2041
2042 /**
2043 * A String holding the phone number originally entered in
2044 * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual
2045 * number to call in a {@link android.content.Intent#ACTION_CALL}.
2046 */
2047 public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
2048 /**
2049 * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED}
2050 * intents to supply the uid the package had been assigned. Also an optional
2051 * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
2052 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same
2053 * purpose.
2054 */
2055 public static final String EXTRA_UID = "android.intent.extra.UID";
2056
2057 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002058 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
2059 * intents to indicate whether this represents a full uninstall (removing
2060 * both the code and its data) or a partial uninstall (leaving its data,
2061 * implying that this is an update).
2062 */
2063 public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
The Android Open Source Project10592532009-03-18 17:39:46 -07002064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 /**
2066 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
2067 * intents to indicate that this is a replacement of the package, so this
2068 * broadcast will immediately be followed by an add broadcast for a
2069 * different version of the same package.
2070 */
2071 public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
The Android Open Source Project10592532009-03-18 17:39:46 -07002072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002074 * Used as an int extra field in {@link android.app.AlarmManager} intents
2075 * to tell the application being invoked how many pending alarms are being
2076 * delievered with the intent. For one-shot alarms this will always be 1.
2077 * For recurring alarms, this might be greater than 1 if the device was
2078 * asleep or powered off at the time an earlier alarm would have been
2079 * delivered.
2080 */
2081 public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
Romain Guy4969af72009-06-17 10:53:19 -07002082
Jacek Surazski86b6c532009-05-13 14:38:28 +02002083 /**
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002084 * Used as an int extra field in {@link android.content.Intent#ACTION_DOCK_EVENT}
2085 * intents to request the dock state. Possible values are
Mike Lockwood725fcbf2009-08-24 13:09:20 -07002086 * {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
2087 * {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
2088 * {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002089 */
2090 public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
2091
2092 /**
2093 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2094 * to represent that the phone is not in any dock.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002095 */
2096 public static final int EXTRA_DOCK_STATE_UNDOCKED = 0;
2097
2098 /**
2099 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2100 * to represent that the phone is in a desk dock.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002101 */
2102 public static final int EXTRA_DOCK_STATE_DESK = 1;
2103
2104 /**
2105 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2106 * to represent that the phone is in a car dock.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002107 */
2108 public static final int EXTRA_DOCK_STATE_CAR = 2;
2109
2110 /**
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002111 * Boolean that can be supplied as meta-data with a dock activity, to
2112 * indicate that the dock should take over the home key when it is active.
2113 */
2114 public static final String METADATA_DOCK_HOME = "android.dock_home";
2115
2116 /**
Jacek Surazski86b6c532009-05-13 14:38:28 +02002117 * Used as a parcelable extra field in {@link #ACTION_APP_ERROR}, containing
2118 * the bug report.
Romain Guy4969af72009-06-17 10:53:19 -07002119 *
Jacek Surazski86b6c532009-05-13 14:38:28 +02002120 * @hide
2121 */
2122 public static final String EXTRA_BUG_REPORT = "android.intent.extra.BUG_REPORT";
2123
2124 /**
Romain Guy4969af72009-06-17 10:53:19 -07002125 * Used as a string extra field when sending an intent to PackageInstaller to install a
Jacek Surazski86b6c532009-05-13 14:38:28 +02002126 * package. Specifies the installer package name; this package will receive the
2127 * {@link #ACTION_APP_ERROR} intent.
Romain Guy4969af72009-06-17 10:53:19 -07002128 *
Jacek Surazski86b6c532009-05-13 14:38:28 +02002129 * @hide
2130 */
Romain Guy4969af72009-06-17 10:53:19 -07002131 public static final String EXTRA_INSTALLER_PACKAGE_NAME
Jacek Surazski86b6c532009-05-13 14:38:28 +02002132 = "android.intent.extra.INSTALLER_PACKAGE_NAME";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002133
Wei Huang97ecc9c2009-05-11 17:44:20 -07002134 /**
2135 * Used in the extra field in the remote intent. It's astring token passed with the
2136 * remote intent.
2137 */
2138 public static final String EXTRA_REMOTE_INTENT_TOKEN =
2139 "android.intent.extra.remote_intent_token";
2140
Suchi Amalapurapu0214e942009-09-02 11:03:18 -07002141 /**
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08002142 * @deprecated See {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST}; this field
Dianne Hackborn86a72da2009-11-11 20:12:41 -08002143 * will contain only the first name in the list.
Suchi Amalapurapu0214e942009-09-02 11:03:18 -07002144 */
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08002145 @Deprecated public static final String EXTRA_CHANGED_COMPONENT_NAME =
Suchi Amalapurapu0214e942009-09-02 11:03:18 -07002146 "android.intent.extra.changed_component_name";
2147
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002148 /**
Dianne Hackborn86a72da2009-11-11 20:12:41 -08002149 * This field is part of {@link android.content.Intent#ACTION_PACKAGE_CHANGED}
2150 * and contains a string array of all of the components that have changed.
2151 */
2152 public static final String EXTRA_CHANGED_COMPONENT_NAME_LIST =
2153 "android.intent.extra.changed_component_name_list";
2154
2155 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002156 * @hide
2157 * Magic extra system code can use when binding, to give a label for
2158 * who it is that has bound to a service. This is an integer giving
2159 * a framework string resource that can be displayed to the user.
2160 */
2161 public static final String EXTRA_CLIENT_LABEL =
2162 "android.intent.extra.client_label";
2163
2164 /**
2165 * @hide
2166 * Magic extra system code can use when binding, to give a PendingIntent object
2167 * that can be launched for the user to disable the system's use of this
2168 * service.
2169 */
2170 public static final String EXTRA_CLIENT_INTENT =
2171 "android.intent.extra.client_intent";
2172
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002173 // ---------------------------------------------------------------------
2174 // ---------------------------------------------------------------------
2175 // Intent flags (see mFlags variable).
2176
2177 /**
2178 * If set, the recipient of this Intent will be granted permission to
2179 * perform read operations on the Uri in the Intent's data.
2180 */
2181 public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
2182 /**
2183 * If set, the recipient of this Intent will be granted permission to
2184 * perform write operations on the Uri in the Intent's data.
2185 */
2186 public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
2187 /**
2188 * Can be set by the caller to indicate that this Intent is coming from
2189 * a background operation, not from direct user interaction.
2190 */
2191 public static final int FLAG_FROM_BACKGROUND = 0x00000004;
2192 /**
2193 * A flag you can enable for debugging: when set, log messages will be
2194 * printed during the resolution of this intent to show you what has
2195 * been found to create the final resolved list.
2196 */
2197 public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
2198
2199 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002200 * If set, the new activity is not kept in the history stack. As soon as
2201 * the user navigates away from it, the activity is finished. This may also
2202 * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
2203 * noHistory} attribute.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002204 */
2205 public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
2206 /**
2207 * If set, the activity will not be launched if it is already running
2208 * at the top of the history stack.
2209 */
2210 public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
2211 /**
2212 * If set, this activity will become the start of a new task on this
2213 * history stack. A task (from the activity that started it to the
2214 * next task activity) defines an atomic group of activities that the
2215 * user can move to. Tasks can be moved to the foreground and background;
2216 * all of the activities inside of a particular task always remain in
The Android Open Source Project10592532009-03-18 17:39:46 -07002217 * the same order. See
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 * <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2219 * Activities and Tasks</a> for more details on tasks.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002220 *
2221 * <p>This flag is generally used by activities that want
2222 * to present a "launcher" style behavior: they give the user a list of
2223 * separate things that can be done, which otherwise run completely
2224 * independently of the activity launching them.
2225 *
2226 * <p>When using this flag, if a task is already running for the activity
2227 * you are now starting, then a new activity will not be started; instead,
2228 * the current task will simply be brought to the front of the screen with
2229 * the state it was last in. See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
2230 * to disable this behavior.
2231 *
2232 * <p>This flag can not be used when the caller is requesting a result from
2233 * the activity being launched.
2234 */
2235 public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
2236 /**
2237 * <strong>Do not use this flag unless you are implementing your own
2238 * top-level application launcher.</strong> Used in conjunction with
2239 * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the
2240 * behavior of bringing an existing task to the foreground. When set,
2241 * a new task is <em>always</em> started to host the Activity for the
2242 * Intent, regardless of whether there is already an existing task running
2243 * the same thing.
2244 *
2245 * <p><strong>Because the default system does not include graphical task management,
2246 * you should not use this flag unless you provide some way for a user to
2247 * return back to the tasks you have launched.</strong>
The Android Open Source Project10592532009-03-18 17:39:46 -07002248 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002249 * <p>This flag is ignored if
2250 * {@link #FLAG_ACTIVITY_NEW_TASK} is not set.
2251 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2253 * Activities and Tasks</a> for more details on tasks.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002254 */
2255 public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
2256 /**
2257 * If set, and the activity being launched is already running in the
2258 * current task, then instead of launching a new instance of that activity,
2259 * all of the other activities on top of it will be closed and this Intent
2260 * will be delivered to the (now on top) old activity as a new Intent.
2261 *
2262 * <p>For example, consider a task consisting of the activities: A, B, C, D.
2263 * If D calls startActivity() with an Intent that resolves to the component
2264 * of activity B, then C and D will be finished and B receive the given
2265 * Intent, resulting in the stack now being: A, B.
2266 *
Dianne Hackbornaa52f9a2009-08-25 16:01:15 -07002267 * <p>The currently running instance of activity B in the above example will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 * either receive the new intent you are starting here in its
2269 * onNewIntent() method, or be itself finished and restarted with the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002270 * new intent. If it has declared its launch mode to be "multiple" (the
Dianne Hackbornaa52f9a2009-08-25 16:01:15 -07002271 * default) and you have not set {@link #FLAG_ACTIVITY_SINGLE_TOP} in
2272 * the same intent, then it will be finished and re-created; for all other
2273 * launch modes or if {@link #FLAG_ACTIVITY_SINGLE_TOP} is set then this
2274 * Intent will be delivered to the current instance's onNewIntent().
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002275 *
2276 * <p>This launch mode can also be used to good effect in conjunction with
2277 * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity
2278 * of a task, it will bring any currently running instance of that task
2279 * to the foreground, and then clear it to its root state. This is
2280 * especially useful, for example, when launching an activity from the
2281 * notification manager.
2282 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2284 * Activities and Tasks</a> for more details on tasks.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002285 */
2286 public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
2287 /**
2288 * If set and this intent is being used to launch a new activity from an
2289 * existing one, then the reply target of the existing activity will be
2290 * transfered to the new activity. This way the new activity can call
2291 * {@link android.app.Activity#setResult} and have that result sent back to
2292 * the reply target of the original activity.
2293 */
2294 public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
2295 /**
2296 * If set and this intent is being used to launch a new activity from an
2297 * existing one, the current activity will not be counted as the top
2298 * activity for deciding whether the new intent should be delivered to
2299 * the top instead of starting a new one. The previous activity will
2300 * be used as the top, with the assumption being that the current activity
2301 * will finish itself immediately.
2302 */
2303 public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
2304 /**
2305 * If set, the new activity is not kept in the list of recently launched
2306 * activities.
2307 */
2308 public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
2309 /**
2310 * This flag is not normally set by application code, but set for you by
2311 * the system as described in the
2312 * {@link android.R.styleable#AndroidManifestActivity_launchMode
2313 * launchMode} documentation for the singleTask mode.
2314 */
2315 public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
2316 /**
2317 * If set, and this activity is either being started in a new task or
2318 * bringing to the top an existing task, then it will be launched as
2319 * the front door of the task. This will result in the application of
2320 * any affinities needed to have that task in the proper state (either
2321 * moving activities to or from it), or simply resetting that task to
2322 * its initial state if needed.
2323 */
2324 public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
2325 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002326 * This flag is not normally set by application code, but set for you by
2327 * the system if this activity is being launched from history
2328 * (longpress home key).
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002329 */
2330 public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002331 /**
2332 * If set, this marks a point in the task's activity stack that should
2333 * be cleared when the task is reset. That is, the next time the task
Marco Nelissenc53fc4e2009-05-11 12:15:31 -07002334 * is brought to the foreground with
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002335 * {@link #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED} (typically as a result of
2336 * the user re-launching it from home), this activity and all on top of
2337 * it will be finished so that the user does not return to them, but
2338 * instead returns to whatever activity preceeded it.
The Android Open Source Project10592532009-03-18 17:39:46 -07002339 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002340 * <p>This is useful for cases where you have a logical break in your
2341 * application. For example, an e-mail application may have a command
2342 * to view an attachment, which launches an image view activity to
2343 * display it. This activity should be part of the e-mail application's
2344 * task, since it is a part of the task the user is involved in. However,
2345 * if the user leaves that task, and later selects the e-mail app from
2346 * home, we may like them to return to the conversation they were
2347 * viewing, not the picture attachment, since that is confusing. By
2348 * setting this flag when launching the image viewer, that viewer and
2349 * any activities it starts will be removed the next time the user returns
2350 * to mail.
2351 */
2352 public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002353 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint}
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002355 * callback from occurring on the current frontmost activity before it is
2356 * paused as the newly-started activity is brought to the front.
The Android Open Source Project10592532009-03-18 17:39:46 -07002357 *
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002358 * <p>Typically, an activity can rely on that callback to indicate that an
2359 * explicit user action has caused their activity to be moved out of the
2360 * foreground. The callback marks an appropriate point in the activity's
2361 * lifecycle for it to dismiss any notifications that it intends to display
2362 * "until the user has seen them," such as a blinking LED.
The Android Open Source Project10592532009-03-18 17:39:46 -07002363 *
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002364 * <p>If an activity is ever started via any non-user-driven events such as
2365 * phone-call receipt or an alarm handler, this flag should be passed to {@link
2366 * Context#startActivity Context.startActivity}, ensuring that the pausing
The Android Open Source Project10592532009-03-18 17:39:46 -07002367 * activity does not think the user has acknowledged its notification.
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002368 */
2369 public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 /**
2371 * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
2372 * this flag will cause the launched activity to be brought to the front of its
2373 * task's history stack if it is already running.
The Android Open Source Project10592532009-03-18 17:39:46 -07002374 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 * <p>For example, consider a task consisting of four activities: A, B, C, D.
2376 * If D calls startActivity() with an Intent that resolves to the component
2377 * of activity B, then B will be brought to the front of the history stack,
2378 * with this resulting order: A, C, D, B.
The Android Open Source Project10592532009-03-18 17:39:46 -07002379 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also
The Android Open Source Project10592532009-03-18 17:39:46 -07002381 * specified.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 */
2383 public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002384 /**
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002385 * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
2386 * this flag will prevent the system from applying an activity transition
2387 * animation to go to the next activity state. This doesn't mean an
2388 * animation will never run -- if another activity change happens that doesn't
2389 * specify this flag before the activity started here is displayed, then
2390 * that transition will be used. This this flag can be put to good use
2391 * when you are going to do a series of activity operations but the
2392 * animation seen by the user shouldn't be driven by the first activity
2393 * change but rather a later one.
2394 */
2395 public static final int FLAG_ACTIVITY_NO_ANIMATION = 0X00010000;
2396 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002397 * If set, when sending a broadcast only registered receivers will be
2398 * called -- no BroadcastReceiver components will be launched.
2399 */
2400 public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 /**
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08002402 * If set, when sending a broadcast the new broadcast will replace
2403 * any existing pending broadcast that matches it. Matching is defined
2404 * by {@link Intent#filterEquals(Intent) Intent.filterEquals} returning
2405 * true for the intents of the two broadcasts. When a match is found,
2406 * the new broadcast (and receivers associated with it) will replace the
2407 * existing one in the pending broadcast list, remaining at the same
2408 * position in the list.
2409 *
2410 * <p>This flag is most typically used with sticky broadcasts, which
2411 * only care about delivering the most recent values of the broadcast
2412 * to their receivers.
2413 */
2414 public static final int FLAG_RECEIVER_REPLACE_PENDING = 0x20000000;
2415 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 * If set, when sending a broadcast <i>before boot has completed</i> only
2417 * registered receivers will be called -- no BroadcastReceiver components
2418 * will be launched. Sticky intent state will be recorded properly even
2419 * if no receivers wind up being called. If {@link #FLAG_RECEIVER_REGISTERED_ONLY}
2420 * is specified in the broadcast intent, this flag is unnecessary.
The Android Open Source Project10592532009-03-18 17:39:46 -07002421 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 * <p>This flag is only for use by system sevices as a convenience to
2423 * avoid having to implement a more complex mechanism around detection
2424 * of boot completion.
The Android Open Source Project10592532009-03-18 17:39:46 -07002425 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 * @hide
2427 */
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08002428 public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x10000000;
Dianne Hackborn9acc0302009-08-25 00:27:12 -07002429 /**
2430 * Set when this broadcast is for a boot upgrade, a special mode that
2431 * allows the broadcast to be sent before the system is ready and launches
2432 * the app process with no providers running in it.
2433 * @hide
2434 */
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08002435 public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x08000000;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002436
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002437 /**
2438 * @hide Flags that can't be changed with PendingIntent.
2439 */
2440 public static final int IMMUTABLE_FLAGS =
2441 FLAG_GRANT_READ_URI_PERMISSION
2442 | FLAG_GRANT_WRITE_URI_PERMISSION;
2443
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002444 // ---------------------------------------------------------------------
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002445 // ---------------------------------------------------------------------
2446 // toUri() and parseUri() options.
2447
2448 /**
2449 * Flag for use with {@link #toUri} and {@link #parseUri}: the URI string
2450 * always has the "intent:" scheme. This syntax can be used when you want
2451 * to later disambiguate between URIs that are intended to describe an
2452 * Intent vs. all others that should be treated as raw URIs. When used
2453 * with {@link #parseUri}, any other scheme will result in a generic
2454 * VIEW action for that raw URI.
2455 */
2456 public static final int URI_INTENT_SCHEME = 1<<0;
2457
2458 // ---------------------------------------------------------------------
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002459
2460 private String mAction;
2461 private Uri mData;
2462 private String mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002463 private String mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002464 private ComponentName mComponent;
2465 private int mFlags;
2466 private HashSet<String> mCategories;
2467 private Bundle mExtras;
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08002468 private Rect mSourceBounds;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002469
2470 // ---------------------------------------------------------------------
2471
2472 /**
2473 * Create an empty intent.
2474 */
2475 public Intent() {
2476 }
2477
2478 /**
2479 * Copy constructor.
2480 */
2481 public Intent(Intent o) {
2482 this.mAction = o.mAction;
2483 this.mData = o.mData;
2484 this.mType = o.mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002485 this.mPackage = o.mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002486 this.mComponent = o.mComponent;
2487 this.mFlags = o.mFlags;
2488 if (o.mCategories != null) {
2489 this.mCategories = new HashSet<String>(o.mCategories);
2490 }
2491 if (o.mExtras != null) {
2492 this.mExtras = new Bundle(o.mExtras);
2493 }
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08002494 if (o.mSourceBounds != null) {
2495 this.mSourceBounds = new Rect(o.mSourceBounds);
2496 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002497 }
2498
2499 @Override
2500 public Object clone() {
2501 return new Intent(this);
2502 }
2503
2504 private Intent(Intent o, boolean all) {
2505 this.mAction = o.mAction;
2506 this.mData = o.mData;
2507 this.mType = o.mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002508 this.mPackage = o.mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002509 this.mComponent = o.mComponent;
2510 if (o.mCategories != null) {
2511 this.mCategories = new HashSet<String>(o.mCategories);
2512 }
2513 }
2514
2515 /**
2516 * Make a clone of only the parts of the Intent that are relevant for
2517 * filter matching: the action, data, type, component, and categories.
2518 */
2519 public Intent cloneFilter() {
2520 return new Intent(this, false);
2521 }
2522
2523 /**
2524 * Create an intent with a given action. All other fields (data, type,
2525 * class) are null. Note that the action <em>must</em> be in a
2526 * namespace because Intents are used globally in the system -- for
2527 * example the system VIEW action is android.intent.action.VIEW; an
2528 * application's custom action would be something like
2529 * com.google.app.myapp.CUSTOM_ACTION.
2530 *
2531 * @param action The Intent action, such as ACTION_VIEW.
2532 */
2533 public Intent(String action) {
2534 mAction = action;
2535 }
2536
2537 /**
2538 * Create an intent with a given action and for a given data url. Note
2539 * that the action <em>must</em> be in a namespace because Intents are
2540 * used globally in the system -- for example the system VIEW action is
2541 * android.intent.action.VIEW; an application's custom action would be
2542 * something like com.google.app.myapp.CUSTOM_ACTION.
2543 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07002544 * <p><em>Note: scheme and host name matching in the Android framework is
2545 * case-sensitive, unlike the formal RFC. As a result,
2546 * you should always ensure that you write your Uri with these elements
2547 * using lower case letters, and normalize any Uris you receive from
2548 * outside of Android to ensure the scheme and host is lower case.</em></p>
2549 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002550 * @param action The Intent action, such as ACTION_VIEW.
2551 * @param uri The Intent data URI.
2552 */
2553 public Intent(String action, Uri uri) {
2554 mAction = action;
2555 mData = uri;
2556 }
2557
2558 /**
2559 * Create an intent for a specific component. All other fields (action, data,
2560 * type, class) are null, though they can be modified later with explicit
2561 * calls. This provides a convenient way to create an intent that is
2562 * intended to execute a hard-coded class name, rather than relying on the
2563 * system to find an appropriate class for you; see {@link #setComponent}
2564 * for more information on the repercussions of this.
2565 *
2566 * @param packageContext A Context of the application package implementing
2567 * this class.
2568 * @param cls The component class that is to be used for the intent.
2569 *
2570 * @see #setClass
2571 * @see #setComponent
2572 * @see #Intent(String, android.net.Uri , Context, Class)
2573 */
2574 public Intent(Context packageContext, Class<?> cls) {
2575 mComponent = new ComponentName(packageContext, cls);
2576 }
2577
2578 /**
2579 * Create an intent for a specific component with a specified action and data.
2580 * This is equivalent using {@link #Intent(String, android.net.Uri)} to
2581 * construct the Intent and then calling {@link #setClass} to set its
2582 * class.
2583 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07002584 * <p><em>Note: scheme and host name matching in the Android framework is
2585 * case-sensitive, unlike the formal RFC. As a result,
2586 * you should always ensure that you write your Uri with these elements
2587 * using lower case letters, and normalize any Uris you receive from
2588 * outside of Android to ensure the scheme and host is lower case.</em></p>
2589 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002590 * @param action The Intent action, such as ACTION_VIEW.
2591 * @param uri The Intent data URI.
2592 * @param packageContext A Context of the application package implementing
2593 * this class.
2594 * @param cls The component class that is to be used for the intent.
2595 *
2596 * @see #Intent(String, android.net.Uri)
2597 * @see #Intent(Context, Class)
2598 * @see #setClass
2599 * @see #setComponent
2600 */
2601 public Intent(String action, Uri uri,
2602 Context packageContext, Class<?> cls) {
2603 mAction = action;
2604 mData = uri;
2605 mComponent = new ComponentName(packageContext, cls);
2606 }
2607
2608 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002609 * Call {@link #parseUri} with 0 flags.
2610 * @deprecated Use {@link #parseUri} instead.
2611 */
2612 @Deprecated
2613 public static Intent getIntent(String uri) throws URISyntaxException {
2614 return parseUri(uri, 0);
2615 }
2616
2617 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002618 * Create an intent from a URI. This URI may encode the action,
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002619 * category, and other intent fields, if it was returned by
Dianne Hackborn7f205432009-07-28 00:13:47 -07002620 * {@link #toUri}. If the Intent was not generate by toUri(), its data
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002621 * will be the entire URI and its action will be ACTION_VIEW.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002622 *
2623 * <p>The URI given here must not be relative -- that is, it must include
2624 * the scheme and full path.
2625 *
2626 * @param uri The URI to turn into an Intent.
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002627 * @param flags Additional processing flags. Either 0 or
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002628 * {@link #URI_INTENT_SCHEME}.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002629 *
2630 * @return Intent The newly created Intent object.
2631 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002632 * @throws URISyntaxException Throws URISyntaxError if the basic URI syntax
2633 * it bad (as parsed by the Uri class) or the Intent data within the
2634 * URI is invalid.
2635 *
2636 * @see #toUri
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002637 */
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002638 public static Intent parseUri(String uri, int flags) throws URISyntaxException {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002639 int i = 0;
2640 try {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002641 // Validate intent scheme for if requested.
2642 if ((flags&URI_INTENT_SCHEME) != 0) {
2643 if (!uri.startsWith("intent:")) {
2644 Intent intent = new Intent(ACTION_VIEW);
2645 try {
2646 intent.setData(Uri.parse(uri));
2647 } catch (IllegalArgumentException e) {
2648 throw new URISyntaxException(uri, e.getMessage());
2649 }
2650 return intent;
2651 }
2652 }
2653
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002654 // simple case
2655 i = uri.lastIndexOf("#");
2656 if (i == -1) return new Intent(ACTION_VIEW, Uri.parse(uri));
2657
2658 // old format Intent URI
2659 if (!uri.startsWith("#Intent;", i)) return getIntentOld(uri);
The Android Open Source Project10592532009-03-18 17:39:46 -07002660
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002661 // new format
2662 Intent intent = new Intent(ACTION_VIEW);
2663
2664 // fetch data part, if present
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002665 String data = i >= 0 ? uri.substring(0, i) : null;
2666 String scheme = null;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002667 i += "#Intent;".length();
The Android Open Source Project10592532009-03-18 17:39:46 -07002668
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002669 // loop over contents of Intent, all name=value;
2670 while (!uri.startsWith("end", i)) {
2671 int eq = uri.indexOf('=', i);
2672 int semi = uri.indexOf(';', eq);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002673 String value = Uri.decode(uri.substring(eq + 1, semi));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002674
2675 // action
2676 if (uri.startsWith("action=", i)) {
2677 intent.mAction = value;
2678 }
2679
2680 // categories
2681 else if (uri.startsWith("category=", i)) {
2682 intent.addCategory(value);
2683 }
2684
2685 // type
2686 else if (uri.startsWith("type=", i)) {
2687 intent.mType = value;
2688 }
2689
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08002690 // launch flags
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002691 else if (uri.startsWith("launchFlags=", i)) {
2692 intent.mFlags = Integer.decode(value).intValue();
2693 }
2694
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002695 // package
2696 else if (uri.startsWith("package=", i)) {
2697 intent.mPackage = value;
2698 }
2699
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002700 // component
2701 else if (uri.startsWith("component=", i)) {
2702 intent.mComponent = ComponentName.unflattenFromString(value);
2703 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002704
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002705 // scheme
2706 else if (uri.startsWith("scheme=", i)) {
2707 scheme = value;
2708 }
2709
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08002710 // source bounds
2711 else if (uri.startsWith("sourceBounds=", i)) {
2712 intent.mSourceBounds = Rect.unflattenFromString(value);
2713 }
2714
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002715 // extra
2716 else {
2717 String key = Uri.decode(uri.substring(i + 2, eq));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002718 // create Bundle if it doesn't already exist
2719 if (intent.mExtras == null) intent.mExtras = new Bundle();
2720 Bundle b = intent.mExtras;
2721 // add EXTRA
2722 if (uri.startsWith("S.", i)) b.putString(key, value);
2723 else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
2724 else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
2725 else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
2726 else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
2727 else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
2728 else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
2729 else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
2730 else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
2731 else throw new URISyntaxException(uri, "unknown EXTRA type", i);
2732 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002733
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002734 // move to the next item
2735 i = semi + 1;
2736 }
2737
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002738 if (data != null) {
2739 if (data.startsWith("intent:")) {
2740 data = data.substring(7);
2741 if (scheme != null) {
2742 data = scheme + ':' + data;
2743 }
2744 }
2745
2746 if (data.length() > 0) {
2747 try {
2748 intent.mData = Uri.parse(data);
2749 } catch (IllegalArgumentException e) {
2750 throw new URISyntaxException(uri, e.getMessage());
2751 }
2752 }
2753 }
2754
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002755 return intent;
The Android Open Source Project10592532009-03-18 17:39:46 -07002756
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002757 } catch (IndexOutOfBoundsException e) {
2758 throw new URISyntaxException(uri, "illegal Intent URI format", i);
2759 }
2760 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002761
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002762 public static Intent getIntentOld(String uri) throws URISyntaxException {
2763 Intent intent;
2764
2765 int i = uri.lastIndexOf('#');
2766 if (i >= 0) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002767 String action = null;
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002768 final int intentFragmentStart = i;
2769 boolean isIntentFragment = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002770
2771 i++;
2772
2773 if (uri.regionMatches(i, "action(", 0, 7)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002774 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002775 i += 7;
2776 int j = uri.indexOf(')', i);
2777 action = uri.substring(i, j);
2778 i = j + 1;
2779 }
2780
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002781 intent = new Intent(action);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002782
2783 if (uri.regionMatches(i, "categories(", 0, 11)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002784 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002785 i += 11;
2786 int j = uri.indexOf(')', i);
2787 while (i < j) {
2788 int sep = uri.indexOf('!', i);
2789 if (sep < 0) sep = j;
2790 if (i < sep) {
2791 intent.addCategory(uri.substring(i, sep));
2792 }
2793 i = sep + 1;
2794 }
2795 i = j + 1;
2796 }
2797
2798 if (uri.regionMatches(i, "type(", 0, 5)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002799 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002800 i += 5;
2801 int j = uri.indexOf(')', i);
2802 intent.mType = uri.substring(i, j);
2803 i = j + 1;
2804 }
2805
2806 if (uri.regionMatches(i, "launchFlags(", 0, 12)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002807 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002808 i += 12;
2809 int j = uri.indexOf(')', i);
2810 intent.mFlags = Integer.decode(uri.substring(i, j)).intValue();
2811 i = j + 1;
2812 }
2813
2814 if (uri.regionMatches(i, "component(", 0, 10)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002815 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002816 i += 10;
2817 int j = uri.indexOf(')', i);
2818 int sep = uri.indexOf('!', i);
2819 if (sep >= 0 && sep < j) {
2820 String pkg = uri.substring(i, sep);
2821 String cls = uri.substring(sep + 1, j);
2822 intent.mComponent = new ComponentName(pkg, cls);
2823 }
2824 i = j + 1;
2825 }
2826
2827 if (uri.regionMatches(i, "extras(", 0, 7)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002828 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002829 i += 7;
The Android Open Source Project10592532009-03-18 17:39:46 -07002830
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002831 final int closeParen = uri.indexOf(')', i);
2832 if (closeParen == -1) throw new URISyntaxException(uri,
2833 "EXTRA missing trailing ')'", i);
2834
2835 while (i < closeParen) {
2836 // fetch the key value
2837 int j = uri.indexOf('=', i);
2838 if (j <= i + 1 || i >= closeParen) {
2839 throw new URISyntaxException(uri, "EXTRA missing '='", i);
2840 }
2841 char type = uri.charAt(i);
2842 i++;
2843 String key = uri.substring(i, j);
2844 i = j + 1;
The Android Open Source Project10592532009-03-18 17:39:46 -07002845
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002846 // get type-value
2847 j = uri.indexOf('!', i);
2848 if (j == -1 || j >= closeParen) j = closeParen;
2849 if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2850 String value = uri.substring(i, j);
2851 i = j;
2852
2853 // create Bundle if it doesn't already exist
2854 if (intent.mExtras == null) intent.mExtras = new Bundle();
The Android Open Source Project10592532009-03-18 17:39:46 -07002855
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002856 // add item to bundle
2857 try {
2858 switch (type) {
2859 case 'S':
2860 intent.mExtras.putString(key, Uri.decode(value));
2861 break;
2862 case 'B':
2863 intent.mExtras.putBoolean(key, Boolean.parseBoolean(value));
2864 break;
2865 case 'b':
2866 intent.mExtras.putByte(key, Byte.parseByte(value));
2867 break;
2868 case 'c':
2869 intent.mExtras.putChar(key, Uri.decode(value).charAt(0));
2870 break;
2871 case 'd':
2872 intent.mExtras.putDouble(key, Double.parseDouble(value));
2873 break;
2874 case 'f':
2875 intent.mExtras.putFloat(key, Float.parseFloat(value));
2876 break;
2877 case 'i':
2878 intent.mExtras.putInt(key, Integer.parseInt(value));
2879 break;
2880 case 'l':
2881 intent.mExtras.putLong(key, Long.parseLong(value));
2882 break;
2883 case 's':
2884 intent.mExtras.putShort(key, Short.parseShort(value));
2885 break;
2886 default:
2887 throw new URISyntaxException(uri, "EXTRA has unknown type", i);
2888 }
2889 } catch (NumberFormatException e) {
2890 throw new URISyntaxException(uri, "EXTRA value can't be parsed", i);
2891 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002892
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002893 char ch = uri.charAt(i);
2894 if (ch == ')') break;
2895 if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2896 i++;
2897 }
2898 }
2899
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002900 if (isIntentFragment) {
2901 intent.mData = Uri.parse(uri.substring(0, intentFragmentStart));
2902 } else {
2903 intent.mData = Uri.parse(uri);
2904 }
2905
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002906 if (intent.mAction == null) {
2907 // By default, if no action is specified, then use VIEW.
2908 intent.mAction = ACTION_VIEW;
2909 }
2910
2911 } else {
2912 intent = new Intent(ACTION_VIEW, Uri.parse(uri));
2913 }
2914
2915 return intent;
2916 }
2917
2918 /**
2919 * Retrieve the general action to be performed, such as
2920 * {@link #ACTION_VIEW}. The action describes the general way the rest of
2921 * the information in the intent should be interpreted -- most importantly,
2922 * what to do with the data returned by {@link #getData}.
2923 *
2924 * @return The action of this intent or null if none is specified.
2925 *
2926 * @see #setAction
2927 */
2928 public String getAction() {
2929 return mAction;
2930 }
2931
2932 /**
2933 * Retrieve data this intent is operating on. This URI specifies the name
2934 * of the data; often it uses the content: scheme, specifying data in a
2935 * content provider. Other schemes may be handled by specific activities,
2936 * such as http: by the web browser.
2937 *
2938 * @return The URI of the data this intent is targeting or null.
2939 *
2940 * @see #getScheme
2941 * @see #setData
2942 */
2943 public Uri getData() {
2944 return mData;
2945 }
2946
2947 /**
2948 * The same as {@link #getData()}, but returns the URI as an encoded
2949 * String.
2950 */
2951 public String getDataString() {
2952 return mData != null ? mData.toString() : null;
2953 }
2954
2955 /**
2956 * Return the scheme portion of the intent's data. If the data is null or
2957 * does not include a scheme, null is returned. Otherwise, the scheme
2958 * prefix without the final ':' is returned, i.e. "http".
2959 *
2960 * <p>This is the same as calling getData().getScheme() (and checking for
2961 * null data).
2962 *
2963 * @return The scheme of this intent.
2964 *
2965 * @see #getData
2966 */
2967 public String getScheme() {
2968 return mData != null ? mData.getScheme() : null;
2969 }
2970
2971 /**
2972 * Retrieve any explicit MIME type included in the intent. This is usually
2973 * null, as the type is determined by the intent data.
2974 *
2975 * @return If a type was manually set, it is returned; else null is
2976 * returned.
2977 *
2978 * @see #resolveType(ContentResolver)
2979 * @see #setType
2980 */
2981 public String getType() {
2982 return mType;
2983 }
2984
2985 /**
2986 * Return the MIME data type of this intent. If the type field is
2987 * explicitly set, that is simply returned. Otherwise, if the data is set,
2988 * the type of that data is returned. If neither fields are set, a null is
2989 * returned.
2990 *
2991 * @return The MIME type of this intent.
2992 *
2993 * @see #getType
2994 * @see #resolveType(ContentResolver)
2995 */
2996 public String resolveType(Context context) {
2997 return resolveType(context.getContentResolver());
2998 }
2999
3000 /**
3001 * Return the MIME data type of this intent. If the type field is
3002 * explicitly set, that is simply returned. Otherwise, if the data is set,
3003 * the type of that data is returned. If neither fields are set, a null is
3004 * returned.
3005 *
3006 * @param resolver A ContentResolver that can be used to determine the MIME
3007 * type of the intent's data.
3008 *
3009 * @return The MIME type of this intent.
3010 *
3011 * @see #getType
3012 * @see #resolveType(Context)
3013 */
3014 public String resolveType(ContentResolver resolver) {
3015 if (mType != null) {
3016 return mType;
3017 }
3018 if (mData != null) {
3019 if ("content".equals(mData.getScheme())) {
3020 return resolver.getType(mData);
3021 }
3022 }
3023 return null;
3024 }
3025
3026 /**
3027 * Return the MIME data type of this intent, only if it will be needed for
3028 * intent resolution. This is not generally useful for application code;
3029 * it is used by the frameworks for communicating with back-end system
3030 * services.
3031 *
3032 * @param resolver A ContentResolver that can be used to determine the MIME
3033 * type of the intent's data.
3034 *
3035 * @return The MIME type of this intent, or null if it is unknown or not
3036 * needed.
3037 */
3038 public String resolveTypeIfNeeded(ContentResolver resolver) {
3039 if (mComponent != null) {
3040 return mType;
3041 }
3042 return resolveType(resolver);
3043 }
3044
3045 /**
3046 * Check if an category exists in the intent.
3047 *
3048 * @param category The category to check.
3049 *
3050 * @return boolean True if the intent contains the category, else false.
3051 *
3052 * @see #getCategories
3053 * @see #addCategory
3054 */
3055 public boolean hasCategory(String category) {
3056 return mCategories != null && mCategories.contains(category);
3057 }
3058
3059 /**
3060 * Return the set of all categories in the intent. If there are no categories,
3061 * returns NULL.
3062 *
3063 * @return Set The set of categories you can examine. Do not modify!
3064 *
3065 * @see #hasCategory
3066 * @see #addCategory
3067 */
3068 public Set<String> getCategories() {
3069 return mCategories;
3070 }
3071
3072 /**
3073 * Sets the ClassLoader that will be used when unmarshalling
3074 * any Parcelable values from the extras of this Intent.
3075 *
3076 * @param loader a ClassLoader, or null to use the default loader
3077 * at the time of unmarshalling.
3078 */
3079 public void setExtrasClassLoader(ClassLoader loader) {
3080 if (mExtras != null) {
3081 mExtras.setClassLoader(loader);
3082 }
3083 }
3084
3085 /**
3086 * Returns true if an extra value is associated with the given name.
3087 * @param name the extra's name
3088 * @return true if the given extra is present.
3089 */
3090 public boolean hasExtra(String name) {
3091 return mExtras != null && mExtras.containsKey(name);
3092 }
3093
3094 /**
3095 * Returns true if the Intent's extras contain a parcelled file descriptor.
3096 * @return true if the Intent contains a parcelled file descriptor.
3097 */
3098 public boolean hasFileDescriptors() {
3099 return mExtras != null && mExtras.hasFileDescriptors();
3100 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003101
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003102 /**
3103 * Retrieve extended data from the intent.
3104 *
3105 * @param name The name of the desired item.
3106 *
3107 * @return the value of an item that previously added with putExtra()
3108 * or null if none was found.
3109 *
3110 * @deprecated
3111 * @hide
3112 */
3113 @Deprecated
3114 public Object getExtra(String name) {
3115 return getExtra(name, null);
3116 }
3117
3118 /**
3119 * Retrieve extended data from the intent.
3120 *
3121 * @param name The name of the desired item.
3122 * @param defaultValue the value to be returned if no value of the desired
3123 * type is stored with the given name.
3124 *
3125 * @return the value of an item that previously added with putExtra()
3126 * or the default value if none was found.
3127 *
3128 * @see #putExtra(String, boolean)
3129 */
3130 public boolean getBooleanExtra(String name, boolean defaultValue) {
3131 return mExtras == null ? defaultValue :
3132 mExtras.getBoolean(name, defaultValue);
3133 }
3134
3135 /**
3136 * Retrieve extended data from the intent.
3137 *
3138 * @param name The name of the desired item.
3139 * @param defaultValue the value to be returned if no value of the desired
3140 * type is stored with the given name.
3141 *
3142 * @return the value of an item that previously added with putExtra()
3143 * or the default value if none was found.
3144 *
3145 * @see #putExtra(String, byte)
3146 */
3147 public byte getByteExtra(String name, byte defaultValue) {
3148 return mExtras == null ? defaultValue :
3149 mExtras.getByte(name, defaultValue);
3150 }
3151
3152 /**
3153 * Retrieve extended data from the intent.
3154 *
3155 * @param name The name of the desired item.
3156 * @param defaultValue the value to be returned if no value of the desired
3157 * type is stored with the given name.
3158 *
3159 * @return the value of an item that previously added with putExtra()
3160 * or the default value if none was found.
3161 *
3162 * @see #putExtra(String, short)
3163 */
3164 public short getShortExtra(String name, short defaultValue) {
3165 return mExtras == null ? defaultValue :
3166 mExtras.getShort(name, defaultValue);
3167 }
3168
3169 /**
3170 * Retrieve extended data from the intent.
3171 *
3172 * @param name The name of the desired item.
3173 * @param defaultValue the value to be returned if no value of the desired
3174 * type is stored with the given name.
3175 *
3176 * @return the value of an item that previously added with putExtra()
3177 * or the default value if none was found.
3178 *
3179 * @see #putExtra(String, char)
3180 */
3181 public char getCharExtra(String name, char defaultValue) {
3182 return mExtras == null ? defaultValue :
3183 mExtras.getChar(name, defaultValue);
3184 }
3185
3186 /**
3187 * Retrieve extended data from the intent.
3188 *
3189 * @param name The name of the desired item.
3190 * @param defaultValue the value to be returned if no value of the desired
3191 * type is stored with the given name.
3192 *
3193 * @return the value of an item that previously added with putExtra()
3194 * or the default value if none was found.
3195 *
3196 * @see #putExtra(String, int)
3197 */
3198 public int getIntExtra(String name, int defaultValue) {
3199 return mExtras == null ? defaultValue :
3200 mExtras.getInt(name, defaultValue);
3201 }
3202
3203 /**
3204 * Retrieve extended data from the intent.
3205 *
3206 * @param name The name of the desired item.
3207 * @param defaultValue the value to be returned if no value of the desired
3208 * type is stored with the given name.
3209 *
3210 * @return the value of an item that previously added with putExtra()
3211 * or the default value if none was found.
3212 *
3213 * @see #putExtra(String, long)
3214 */
3215 public long getLongExtra(String name, long defaultValue) {
3216 return mExtras == null ? defaultValue :
3217 mExtras.getLong(name, defaultValue);
3218 }
3219
3220 /**
3221 * Retrieve extended data from the intent.
3222 *
3223 * @param name The name of the desired item.
3224 * @param defaultValue the value to be returned if no value of the desired
3225 * type is stored with the given name.
3226 *
3227 * @return the value of an item that previously added with putExtra(),
3228 * or the default value if no such item is present
3229 *
3230 * @see #putExtra(String, float)
3231 */
3232 public float getFloatExtra(String name, float defaultValue) {
3233 return mExtras == null ? defaultValue :
3234 mExtras.getFloat(name, defaultValue);
3235 }
3236
3237 /**
3238 * Retrieve extended data from the intent.
3239 *
3240 * @param name The name of the desired item.
3241 * @param defaultValue the value to be returned if no value of the desired
3242 * type is stored with the given name.
3243 *
3244 * @return the value of an item that previously added with putExtra()
3245 * or the default value if none was found.
3246 *
3247 * @see #putExtra(String, double)
3248 */
3249 public double getDoubleExtra(String name, double defaultValue) {
3250 return mExtras == null ? defaultValue :
3251 mExtras.getDouble(name, defaultValue);
3252 }
3253
3254 /**
3255 * Retrieve extended data from the intent.
3256 *
3257 * @param name The name of the desired item.
3258 *
3259 * @return the value of an item that previously added with putExtra()
3260 * or null if no String value was found.
3261 *
3262 * @see #putExtra(String, String)
3263 */
3264 public String getStringExtra(String name) {
3265 return mExtras == null ? null : mExtras.getString(name);
3266 }
3267
3268 /**
3269 * Retrieve extended data from the intent.
3270 *
3271 * @param name The name of the desired item.
3272 *
3273 * @return the value of an item that previously added with putExtra()
3274 * or null if no CharSequence value was found.
3275 *
3276 * @see #putExtra(String, CharSequence)
3277 */
3278 public CharSequence getCharSequenceExtra(String name) {
3279 return mExtras == null ? null : mExtras.getCharSequence(name);
3280 }
3281
3282 /**
3283 * Retrieve extended data from the intent.
3284 *
3285 * @param name The name of the desired item.
3286 *
3287 * @return the value of an item that previously added with putExtra()
3288 * or null if no Parcelable value was found.
3289 *
3290 * @see #putExtra(String, Parcelable)
3291 */
3292 public <T extends Parcelable> T getParcelableExtra(String name) {
3293 return mExtras == null ? null : mExtras.<T>getParcelable(name);
3294 }
3295
3296 /**
3297 * Retrieve extended data from the intent.
3298 *
3299 * @param name The name of the desired item.
3300 *
3301 * @return the value of an item that previously added with putExtra()
3302 * or null if no Parcelable[] value was found.
3303 *
3304 * @see #putExtra(String, Parcelable[])
3305 */
3306 public Parcelable[] getParcelableArrayExtra(String name) {
3307 return mExtras == null ? null : mExtras.getParcelableArray(name);
3308 }
3309
3310 /**
3311 * Retrieve extended data from the intent.
3312 *
3313 * @param name The name of the desired item.
3314 *
3315 * @return the value of an item that previously added with putExtra()
3316 * or null if no ArrayList<Parcelable> value was found.
3317 *
3318 * @see #putParcelableArrayListExtra(String, ArrayList)
3319 */
3320 public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
3321 return mExtras == null ? null : mExtras.<T>getParcelableArrayList(name);
3322 }
3323
3324 /**
3325 * Retrieve extended data from the intent.
3326 *
3327 * @param name The name of the desired item.
3328 *
3329 * @return the value of an item that previously added with putExtra()
3330 * or null if no Serializable value was found.
3331 *
3332 * @see #putExtra(String, Serializable)
3333 */
3334 public Serializable getSerializableExtra(String name) {
3335 return mExtras == null ? null : mExtras.getSerializable(name);
3336 }
3337
3338 /**
3339 * Retrieve extended data from the intent.
3340 *
3341 * @param name The name of the desired item.
3342 *
3343 * @return the value of an item that previously added with putExtra()
3344 * or null if no ArrayList<Integer> value was found.
3345 *
3346 * @see #putIntegerArrayListExtra(String, ArrayList)
3347 */
3348 public ArrayList<Integer> getIntegerArrayListExtra(String name) {
3349 return mExtras == null ? null : mExtras.getIntegerArrayList(name);
3350 }
3351
3352 /**
3353 * Retrieve extended data from the intent.
3354 *
3355 * @param name The name of the desired item.
3356 *
3357 * @return the value of an item that previously added with putExtra()
3358 * or null if no ArrayList<String> value was found.
3359 *
3360 * @see #putStringArrayListExtra(String, ArrayList)
3361 */
3362 public ArrayList<String> getStringArrayListExtra(String name) {
3363 return mExtras == null ? null : mExtras.getStringArrayList(name);
3364 }
3365
3366 /**
3367 * Retrieve extended data from the intent.
3368 *
3369 * @param name The name of the desired item.
3370 *
3371 * @return the value of an item that previously added with putExtra()
3372 * or null if no boolean array value was found.
3373 *
3374 * @see #putExtra(String, boolean[])
3375 */
3376 public boolean[] getBooleanArrayExtra(String name) {
3377 return mExtras == null ? null : mExtras.getBooleanArray(name);
3378 }
3379
3380 /**
3381 * Retrieve extended data from the intent.
3382 *
3383 * @param name The name of the desired item.
3384 *
3385 * @return the value of an item that previously added with putExtra()
3386 * or null if no byte array value was found.
3387 *
3388 * @see #putExtra(String, byte[])
3389 */
3390 public byte[] getByteArrayExtra(String name) {
3391 return mExtras == null ? null : mExtras.getByteArray(name);
3392 }
3393
3394 /**
3395 * Retrieve extended data from the intent.
3396 *
3397 * @param name The name of the desired item.
3398 *
3399 * @return the value of an item that previously added with putExtra()
3400 * or null if no short array value was found.
3401 *
3402 * @see #putExtra(String, short[])
3403 */
3404 public short[] getShortArrayExtra(String name) {
3405 return mExtras == null ? null : mExtras.getShortArray(name);
3406 }
3407
3408 /**
3409 * Retrieve extended data from the intent.
3410 *
3411 * @param name The name of the desired item.
3412 *
3413 * @return the value of an item that previously added with putExtra()
3414 * or null if no char array value was found.
3415 *
3416 * @see #putExtra(String, char[])
3417 */
3418 public char[] getCharArrayExtra(String name) {
3419 return mExtras == null ? null : mExtras.getCharArray(name);
3420 }
3421
3422 /**
3423 * Retrieve extended data from the intent.
3424 *
3425 * @param name The name of the desired item.
3426 *
3427 * @return the value of an item that previously added with putExtra()
3428 * or null if no int array value was found.
3429 *
3430 * @see #putExtra(String, int[])
3431 */
3432 public int[] getIntArrayExtra(String name) {
3433 return mExtras == null ? null : mExtras.getIntArray(name);
3434 }
3435
3436 /**
3437 * Retrieve extended data from the intent.
3438 *
3439 * @param name The name of the desired item.
3440 *
3441 * @return the value of an item that previously added with putExtra()
3442 * or null if no long array value was found.
3443 *
3444 * @see #putExtra(String, long[])
3445 */
3446 public long[] getLongArrayExtra(String name) {
3447 return mExtras == null ? null : mExtras.getLongArray(name);
3448 }
3449
3450 /**
3451 * Retrieve extended data from the intent.
3452 *
3453 * @param name The name of the desired item.
3454 *
3455 * @return the value of an item that previously added with putExtra()
3456 * or null if no float array value was found.
3457 *
3458 * @see #putExtra(String, float[])
3459 */
3460 public float[] getFloatArrayExtra(String name) {
3461 return mExtras == null ? null : mExtras.getFloatArray(name);
3462 }
3463
3464 /**
3465 * Retrieve extended data from the intent.
3466 *
3467 * @param name The name of the desired item.
3468 *
3469 * @return the value of an item that previously added with putExtra()
3470 * or null if no double array value was found.
3471 *
3472 * @see #putExtra(String, double[])
3473 */
3474 public double[] getDoubleArrayExtra(String name) {
3475 return mExtras == null ? null : mExtras.getDoubleArray(name);
3476 }
3477
3478 /**
3479 * Retrieve extended data from the intent.
3480 *
3481 * @param name The name of the desired item.
3482 *
3483 * @return the value of an item that previously added with putExtra()
3484 * or null if no String array value was found.
3485 *
3486 * @see #putExtra(String, String[])
3487 */
3488 public String[] getStringArrayExtra(String name) {
3489 return mExtras == null ? null : mExtras.getStringArray(name);
3490 }
3491
3492 /**
3493 * Retrieve extended data from the intent.
3494 *
3495 * @param name The name of the desired item.
3496 *
3497 * @return the value of an item that previously added with putExtra()
3498 * or null if no Bundle value was found.
3499 *
3500 * @see #putExtra(String, Bundle)
3501 */
3502 public Bundle getBundleExtra(String name) {
3503 return mExtras == null ? null : mExtras.getBundle(name);
3504 }
3505
3506 /**
3507 * Retrieve extended data from the intent.
3508 *
3509 * @param name The name of the desired item.
3510 *
3511 * @return the value of an item that previously added with putExtra()
3512 * or null if no IBinder value was found.
3513 *
3514 * @see #putExtra(String, IBinder)
3515 *
3516 * @deprecated
3517 * @hide
3518 */
3519 @Deprecated
3520 public IBinder getIBinderExtra(String name) {
3521 return mExtras == null ? null : mExtras.getIBinder(name);
3522 }
3523
3524 /**
3525 * Retrieve extended data from the intent.
3526 *
3527 * @param name The name of the desired item.
3528 * @param defaultValue The default value to return in case no item is
3529 * associated with the key 'name'
3530 *
3531 * @return the value of an item that previously added with putExtra()
3532 * or defaultValue if none was found.
3533 *
3534 * @see #putExtra
3535 *
3536 * @deprecated
3537 * @hide
3538 */
3539 @Deprecated
3540 public Object getExtra(String name, Object defaultValue) {
3541 Object result = defaultValue;
3542 if (mExtras != null) {
3543 Object result2 = mExtras.get(name);
3544 if (result2 != null) {
3545 result = result2;
3546 }
3547 }
3548
3549 return result;
3550 }
3551
3552 /**
3553 * Retrieves a map of extended data from the intent.
3554 *
3555 * @return the map of all extras previously added with putExtra(),
3556 * or null if none have been added.
3557 */
3558 public Bundle getExtras() {
3559 return (mExtras != null)
3560 ? new Bundle(mExtras)
3561 : null;
3562 }
3563
3564 /**
3565 * Retrieve any special flags associated with this intent. You will
3566 * normally just set them with {@link #setFlags} and let the system
3567 * take the appropriate action with them.
3568 *
3569 * @return int The currently set flags.
3570 *
3571 * @see #setFlags
3572 */
3573 public int getFlags() {
3574 return mFlags;
3575 }
3576
3577 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07003578 * Retrieve the application package name this Intent is limited to. When
3579 * resolving an Intent, if non-null this limits the resolution to only
3580 * components in the given application package.
3581 *
3582 * @return The name of the application package for the Intent.
3583 *
3584 * @see #resolveActivity
3585 * @see #setPackage
3586 */
3587 public String getPackage() {
3588 return mPackage;
3589 }
3590
3591 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003592 * Retrieve the concrete component associated with the intent. When receiving
3593 * an intent, this is the component that was found to best handle it (that is,
3594 * yourself) and will always be non-null; in all other cases it will be
3595 * null unless explicitly set.
3596 *
3597 * @return The name of the application component to handle the intent.
3598 *
3599 * @see #resolveActivity
3600 * @see #setComponent
3601 */
3602 public ComponentName getComponent() {
3603 return mComponent;
3604 }
3605
3606 /**
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08003607 * Get the bounds of the sender of this intent, in screen coordinates. This can be
3608 * used as a hint to the receiver for animations and the like. Null means that there
3609 * is no source bounds.
3610 */
3611 public Rect getSourceBounds() {
3612 return mSourceBounds;
3613 }
3614
3615 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003616 * Return the Activity component that should be used to handle this intent.
3617 * The appropriate component is determined based on the information in the
3618 * intent, evaluated as follows:
3619 *
3620 * <p>If {@link #getComponent} returns an explicit class, that is returned
3621 * without any further consideration.
3622 *
3623 * <p>The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent
3624 * category to be considered.
3625 *
3626 * <p>If {@link #getAction} is non-NULL, the activity must handle this
3627 * action.
3628 *
3629 * <p>If {@link #resolveType} returns non-NULL, the activity must handle
3630 * this type.
3631 *
3632 * <p>If {@link #addCategory} has added any categories, the activity must
3633 * handle ALL of the categories specified.
3634 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07003635 * <p>If {@link #getPackage} is non-NULL, only activity components in
3636 * that application package will be considered.
3637 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003638 * <p>If there are no activities that satisfy all of these conditions, a
3639 * null string is returned.
3640 *
3641 * <p>If multiple activities are found to satisfy the intent, the one with
3642 * the highest priority will be used. If there are multiple activities
3643 * with the same priority, the system will either pick the best activity
3644 * based on user preference, or resolve to a system class that will allow
3645 * the user to pick an activity and forward from there.
3646 *
3647 * <p>This method is implemented simply by calling
3648 * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter
3649 * true.</p>
3650 * <p> This API is called for you as part of starting an activity from an
3651 * intent. You do not normally need to call it yourself.</p>
3652 *
3653 * @param pm The package manager with which to resolve the Intent.
3654 *
3655 * @return Name of the component implementing an activity that can
3656 * display the intent.
3657 *
3658 * @see #setComponent
3659 * @see #getComponent
3660 * @see #resolveActivityInfo
3661 */
3662 public ComponentName resolveActivity(PackageManager pm) {
3663 if (mComponent != null) {
3664 return mComponent;
3665 }
3666
3667 ResolveInfo info = pm.resolveActivity(
3668 this, PackageManager.MATCH_DEFAULT_ONLY);
3669 if (info != null) {
3670 return new ComponentName(
3671 info.activityInfo.applicationInfo.packageName,
3672 info.activityInfo.name);
3673 }
3674
3675 return null;
3676 }
3677
3678 /**
3679 * Resolve the Intent into an {@link ActivityInfo}
3680 * describing the activity that should execute the intent. Resolution
3681 * follows the same rules as described for {@link #resolveActivity}, but
3682 * you get back the completely information about the resolved activity
3683 * instead of just its class name.
3684 *
3685 * @param pm The package manager with which to resolve the Intent.
3686 * @param flags Addition information to retrieve as per
3687 * {@link PackageManager#getActivityInfo(ComponentName, int)
3688 * PackageManager.getActivityInfo()}.
3689 *
3690 * @return PackageManager.ActivityInfo
3691 *
3692 * @see #resolveActivity
3693 */
3694 public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) {
3695 ActivityInfo ai = null;
3696 if (mComponent != null) {
3697 try {
3698 ai = pm.getActivityInfo(mComponent, flags);
3699 } catch (PackageManager.NameNotFoundException e) {
3700 // ignore
3701 }
3702 } else {
3703 ResolveInfo info = pm.resolveActivity(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003704 this, PackageManager.MATCH_DEFAULT_ONLY | flags);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003705 if (info != null) {
3706 ai = info.activityInfo;
3707 }
3708 }
3709
3710 return ai;
3711 }
3712
3713 /**
3714 * Set the general action to be performed.
3715 *
3716 * @param action An action name, such as ACTION_VIEW. Application-specific
3717 * actions should be prefixed with the vendor's package name.
3718 *
3719 * @return Returns the same Intent object, for chaining multiple calls
3720 * into a single statement.
3721 *
3722 * @see #getAction
3723 */
3724 public Intent setAction(String action) {
3725 mAction = action;
3726 return this;
3727 }
3728
3729 /**
3730 * Set the data this intent is operating on. This method automatically
3731 * clears any type that was previously set by {@link #setType}.
3732 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003733 * <p><em>Note: scheme and host name matching in the Android framework is
3734 * case-sensitive, unlike the formal RFC. As a result,
3735 * you should always ensure that you write your Uri with these elements
3736 * using lower case letters, and normalize any Uris you receive from
3737 * outside of Android to ensure the scheme and host is lower case.</em></p>
3738 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003739 * @param data The URI of the data this intent is now targeting.
3740 *
3741 * @return Returns the same Intent object, for chaining multiple calls
3742 * into a single statement.
3743 *
3744 * @see #getData
3745 * @see #setType
3746 * @see #setDataAndType
3747 */
3748 public Intent setData(Uri data) {
3749 mData = data;
3750 mType = null;
3751 return this;
3752 }
3753
3754 /**
3755 * Set an explicit MIME data type. This is used to create intents that
3756 * only specify a type and not data, for example to indicate the type of
3757 * data to return. This method automatically clears any data that was
3758 * previously set by {@link #setData}.
Romain Guy4969af72009-06-17 10:53:19 -07003759 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003760 * <p><em>Note: MIME type matching in the Android framework is
3761 * case-sensitive, unlike formal RFC MIME types. As a result,
3762 * you should always write your MIME types with lower case letters,
3763 * and any MIME types you receive from outside of Android should be
3764 * converted to lower case before supplying them here.</em></p>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003765 *
3766 * @param type The MIME type of the data being handled by this intent.
3767 *
3768 * @return Returns the same Intent object, for chaining multiple calls
3769 * into a single statement.
3770 *
3771 * @see #getType
3772 * @see #setData
3773 * @see #setDataAndType
3774 */
3775 public Intent setType(String type) {
3776 mData = null;
3777 mType = type;
3778 return this;
3779 }
3780
3781 /**
3782 * (Usually optional) Set the data for the intent along with an explicit
3783 * MIME data type. This method should very rarely be used -- it allows you
3784 * to override the MIME type that would ordinarily be inferred from the
3785 * data with your own type given here.
3786 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003787 * <p><em>Note: MIME type, Uri scheme, and host name matching in the
3788 * Android framework is case-sensitive, unlike the formal RFC definitions.
3789 * As a result, you should always write these elements with lower case letters,
3790 * and normalize any MIME types or Uris you receive from
3791 * outside of Android to ensure these elements are lower case before
3792 * supplying them here.</em></p>
3793 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003794 * @param data The URI of the data this intent is now targeting.
3795 * @param type The MIME type of the data being handled by this intent.
3796 *
3797 * @return Returns the same Intent object, for chaining multiple calls
3798 * into a single statement.
3799 *
3800 * @see #setData
3801 * @see #setType
3802 */
3803 public Intent setDataAndType(Uri data, String type) {
3804 mData = data;
3805 mType = type;
3806 return this;
3807 }
3808
3809 /**
3810 * Add a new category to the intent. Categories provide additional detail
3811 * about the action the intent is perform. When resolving an intent, only
3812 * activities that provide <em>all</em> of the requested categories will be
3813 * used.
3814 *
3815 * @param category The desired category. This can be either one of the
3816 * predefined Intent categories, or a custom category in your own
3817 * namespace.
3818 *
3819 * @return Returns the same Intent object, for chaining multiple calls
3820 * into a single statement.
3821 *
3822 * @see #hasCategory
3823 * @see #removeCategory
3824 */
3825 public Intent addCategory(String category) {
3826 if (mCategories == null) {
3827 mCategories = new HashSet<String>();
3828 }
3829 mCategories.add(category);
3830 return this;
3831 }
3832
3833 /**
3834 * Remove an category from an intent.
3835 *
3836 * @param category The category to remove.
3837 *
3838 * @see #addCategory
3839 */
3840 public void removeCategory(String category) {
3841 if (mCategories != null) {
3842 mCategories.remove(category);
3843 if (mCategories.size() == 0) {
3844 mCategories = null;
3845 }
3846 }
3847 }
3848
3849 /**
3850 * Add extended data to the intent. The name must include a package
3851 * prefix, for example the app com.android.contacts would use names
3852 * like "com.android.contacts.ShowAll".
3853 *
3854 * @param name The name of the extra data, with package prefix.
3855 * @param value The boolean data value.
3856 *
3857 * @return Returns the same Intent object, for chaining multiple calls
3858 * into a single statement.
3859 *
3860 * @see #putExtras
3861 * @see #removeExtra
3862 * @see #getBooleanExtra(String, boolean)
3863 */
3864 public Intent putExtra(String name, boolean value) {
3865 if (mExtras == null) {
3866 mExtras = new Bundle();
3867 }
3868 mExtras.putBoolean(name, value);
3869 return this;
3870 }
3871
3872 /**
3873 * Add extended data to the intent. The name must include a package
3874 * prefix, for example the app com.android.contacts would use names
3875 * like "com.android.contacts.ShowAll".
3876 *
3877 * @param name The name of the extra data, with package prefix.
3878 * @param value The byte data value.
3879 *
3880 * @return Returns the same Intent object, for chaining multiple calls
3881 * into a single statement.
3882 *
3883 * @see #putExtras
3884 * @see #removeExtra
3885 * @see #getByteExtra(String, byte)
3886 */
3887 public Intent putExtra(String name, byte value) {
3888 if (mExtras == null) {
3889 mExtras = new Bundle();
3890 }
3891 mExtras.putByte(name, value);
3892 return this;
3893 }
3894
3895 /**
3896 * Add extended data to the intent. The name must include a package
3897 * prefix, for example the app com.android.contacts would use names
3898 * like "com.android.contacts.ShowAll".
3899 *
3900 * @param name The name of the extra data, with package prefix.
3901 * @param value The char data value.
3902 *
3903 * @return Returns the same Intent object, for chaining multiple calls
3904 * into a single statement.
3905 *
3906 * @see #putExtras
3907 * @see #removeExtra
3908 * @see #getCharExtra(String, char)
3909 */
3910 public Intent putExtra(String name, char value) {
3911 if (mExtras == null) {
3912 mExtras = new Bundle();
3913 }
3914 mExtras.putChar(name, value);
3915 return this;
3916 }
3917
3918 /**
3919 * Add extended data to the intent. The name must include a package
3920 * prefix, for example the app com.android.contacts would use names
3921 * like "com.android.contacts.ShowAll".
3922 *
3923 * @param name The name of the extra data, with package prefix.
3924 * @param value The short data value.
3925 *
3926 * @return Returns the same Intent object, for chaining multiple calls
3927 * into a single statement.
3928 *
3929 * @see #putExtras
3930 * @see #removeExtra
3931 * @see #getShortExtra(String, short)
3932 */
3933 public Intent putExtra(String name, short value) {
3934 if (mExtras == null) {
3935 mExtras = new Bundle();
3936 }
3937 mExtras.putShort(name, value);
3938 return this;
3939 }
3940
3941 /**
3942 * Add extended data to the intent. The name must include a package
3943 * prefix, for example the app com.android.contacts would use names
3944 * like "com.android.contacts.ShowAll".
3945 *
3946 * @param name The name of the extra data, with package prefix.
3947 * @param value The integer data value.
3948 *
3949 * @return Returns the same Intent object, for chaining multiple calls
3950 * into a single statement.
3951 *
3952 * @see #putExtras
3953 * @see #removeExtra
3954 * @see #getIntExtra(String, int)
3955 */
3956 public Intent putExtra(String name, int value) {
3957 if (mExtras == null) {
3958 mExtras = new Bundle();
3959 }
3960 mExtras.putInt(name, value);
3961 return this;
3962 }
3963
3964 /**
3965 * Add extended data to the intent. The name must include a package
3966 * prefix, for example the app com.android.contacts would use names
3967 * like "com.android.contacts.ShowAll".
3968 *
3969 * @param name The name of the extra data, with package prefix.
3970 * @param value The long data value.
3971 *
3972 * @return Returns the same Intent object, for chaining multiple calls
3973 * into a single statement.
3974 *
3975 * @see #putExtras
3976 * @see #removeExtra
3977 * @see #getLongExtra(String, long)
3978 */
3979 public Intent putExtra(String name, long value) {
3980 if (mExtras == null) {
3981 mExtras = new Bundle();
3982 }
3983 mExtras.putLong(name, value);
3984 return this;
3985 }
3986
3987 /**
3988 * Add extended data to the intent. The name must include a package
3989 * prefix, for example the app com.android.contacts would use names
3990 * like "com.android.contacts.ShowAll".
3991 *
3992 * @param name The name of the extra data, with package prefix.
3993 * @param value The float data value.
3994 *
3995 * @return Returns the same Intent object, for chaining multiple calls
3996 * into a single statement.
3997 *
3998 * @see #putExtras
3999 * @see #removeExtra
4000 * @see #getFloatExtra(String, float)
4001 */
4002 public Intent putExtra(String name, float value) {
4003 if (mExtras == null) {
4004 mExtras = new Bundle();
4005 }
4006 mExtras.putFloat(name, value);
4007 return this;
4008 }
4009
4010 /**
4011 * Add extended data to the intent. The name must include a package
4012 * prefix, for example the app com.android.contacts would use names
4013 * like "com.android.contacts.ShowAll".
4014 *
4015 * @param name The name of the extra data, with package prefix.
4016 * @param value The double data value.
4017 *
4018 * @return Returns the same Intent object, for chaining multiple calls
4019 * into a single statement.
4020 *
4021 * @see #putExtras
4022 * @see #removeExtra
4023 * @see #getDoubleExtra(String, double)
4024 */
4025 public Intent putExtra(String name, double value) {
4026 if (mExtras == null) {
4027 mExtras = new Bundle();
4028 }
4029 mExtras.putDouble(name, value);
4030 return this;
4031 }
4032
4033 /**
4034 * Add extended data to the intent. The name must include a package
4035 * prefix, for example the app com.android.contacts would use names
4036 * like "com.android.contacts.ShowAll".
4037 *
4038 * @param name The name of the extra data, with package prefix.
4039 * @param value The String data value.
4040 *
4041 * @return Returns the same Intent object, for chaining multiple calls
4042 * into a single statement.
4043 *
4044 * @see #putExtras
4045 * @see #removeExtra
4046 * @see #getStringExtra(String)
4047 */
4048 public Intent putExtra(String name, String value) {
4049 if (mExtras == null) {
4050 mExtras = new Bundle();
4051 }
4052 mExtras.putString(name, value);
4053 return this;
4054 }
4055
4056 /**
4057 * Add extended data to the intent. The name must include a package
4058 * prefix, for example the app com.android.contacts would use names
4059 * like "com.android.contacts.ShowAll".
4060 *
4061 * @param name The name of the extra data, with package prefix.
4062 * @param value The CharSequence data value.
4063 *
4064 * @return Returns the same Intent object, for chaining multiple calls
4065 * into a single statement.
4066 *
4067 * @see #putExtras
4068 * @see #removeExtra
4069 * @see #getCharSequenceExtra(String)
4070 */
4071 public Intent putExtra(String name, CharSequence value) {
4072 if (mExtras == null) {
4073 mExtras = new Bundle();
4074 }
4075 mExtras.putCharSequence(name, value);
4076 return this;
4077 }
4078
4079 /**
4080 * Add extended data to the intent. The name must include a package
4081 * prefix, for example the app com.android.contacts would use names
4082 * like "com.android.contacts.ShowAll".
4083 *
4084 * @param name The name of the extra data, with package prefix.
4085 * @param value The Parcelable data value.
4086 *
4087 * @return Returns the same Intent object, for chaining multiple calls
4088 * into a single statement.
4089 *
4090 * @see #putExtras
4091 * @see #removeExtra
4092 * @see #getParcelableExtra(String)
4093 */
4094 public Intent putExtra(String name, Parcelable value) {
4095 if (mExtras == null) {
4096 mExtras = new Bundle();
4097 }
4098 mExtras.putParcelable(name, value);
4099 return this;
4100 }
4101
4102 /**
4103 * Add extended data to the intent. The name must include a package
4104 * prefix, for example the app com.android.contacts would use names
4105 * like "com.android.contacts.ShowAll".
4106 *
4107 * @param name The name of the extra data, with package prefix.
4108 * @param value The Parcelable[] data value.
4109 *
4110 * @return Returns the same Intent object, for chaining multiple calls
4111 * into a single statement.
4112 *
4113 * @see #putExtras
4114 * @see #removeExtra
4115 * @see #getParcelableArrayExtra(String)
4116 */
4117 public Intent putExtra(String name, Parcelable[] value) {
4118 if (mExtras == null) {
4119 mExtras = new Bundle();
4120 }
4121 mExtras.putParcelableArray(name, value);
4122 return this;
4123 }
4124
4125 /**
4126 * Add extended data to the intent. The name must include a package
4127 * prefix, for example the app com.android.contacts would use names
4128 * like "com.android.contacts.ShowAll".
4129 *
4130 * @param name The name of the extra data, with package prefix.
4131 * @param value The ArrayList<Parcelable> data value.
4132 *
4133 * @return Returns the same Intent object, for chaining multiple calls
4134 * into a single statement.
4135 *
4136 * @see #putExtras
4137 * @see #removeExtra
4138 * @see #getParcelableArrayListExtra(String)
4139 */
4140 public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
4141 if (mExtras == null) {
4142 mExtras = new Bundle();
4143 }
4144 mExtras.putParcelableArrayList(name, value);
4145 return this;
4146 }
4147
4148 /**
4149 * Add extended data to the intent. The name must include a package
4150 * prefix, for example the app com.android.contacts would use names
4151 * like "com.android.contacts.ShowAll".
4152 *
4153 * @param name The name of the extra data, with package prefix.
4154 * @param value The ArrayList<Integer> data value.
4155 *
4156 * @return Returns the same Intent object, for chaining multiple calls
4157 * into a single statement.
4158 *
4159 * @see #putExtras
4160 * @see #removeExtra
4161 * @see #getIntegerArrayListExtra(String)
4162 */
4163 public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
4164 if (mExtras == null) {
4165 mExtras = new Bundle();
4166 }
4167 mExtras.putIntegerArrayList(name, value);
4168 return this;
4169 }
4170
4171 /**
4172 * Add extended data to the intent. The name must include a package
4173 * prefix, for example the app com.android.contacts would use names
4174 * like "com.android.contacts.ShowAll".
4175 *
4176 * @param name The name of the extra data, with package prefix.
4177 * @param value The ArrayList<String> data value.
4178 *
4179 * @return Returns the same Intent object, for chaining multiple calls
4180 * into a single statement.
4181 *
4182 * @see #putExtras
4183 * @see #removeExtra
4184 * @see #getStringArrayListExtra(String)
4185 */
4186 public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
4187 if (mExtras == null) {
4188 mExtras = new Bundle();
4189 }
4190 mExtras.putStringArrayList(name, value);
4191 return this;
4192 }
4193
4194 /**
4195 * Add extended data to the intent. The name must include a package
4196 * prefix, for example the app com.android.contacts would use names
4197 * like "com.android.contacts.ShowAll".
4198 *
4199 * @param name The name of the extra data, with package prefix.
4200 * @param value The Serializable data value.
4201 *
4202 * @return Returns the same Intent object, for chaining multiple calls
4203 * into a single statement.
4204 *
4205 * @see #putExtras
4206 * @see #removeExtra
4207 * @see #getSerializableExtra(String)
4208 */
4209 public Intent putExtra(String name, Serializable value) {
4210 if (mExtras == null) {
4211 mExtras = new Bundle();
4212 }
4213 mExtras.putSerializable(name, value);
4214 return this;
4215 }
4216
4217 /**
4218 * Add extended data to the intent. The name must include a package
4219 * prefix, for example the app com.android.contacts would use names
4220 * like "com.android.contacts.ShowAll".
4221 *
4222 * @param name The name of the extra data, with package prefix.
4223 * @param value The boolean array data value.
4224 *
4225 * @return Returns the same Intent object, for chaining multiple calls
4226 * into a single statement.
4227 *
4228 * @see #putExtras
4229 * @see #removeExtra
4230 * @see #getBooleanArrayExtra(String)
4231 */
4232 public Intent putExtra(String name, boolean[] value) {
4233 if (mExtras == null) {
4234 mExtras = new Bundle();
4235 }
4236 mExtras.putBooleanArray(name, value);
4237 return this;
4238 }
4239
4240 /**
4241 * Add extended data to the intent. The name must include a package
4242 * prefix, for example the app com.android.contacts would use names
4243 * like "com.android.contacts.ShowAll".
4244 *
4245 * @param name The name of the extra data, with package prefix.
4246 * @param value The byte array data value.
4247 *
4248 * @return Returns the same Intent object, for chaining multiple calls
4249 * into a single statement.
4250 *
4251 * @see #putExtras
4252 * @see #removeExtra
4253 * @see #getByteArrayExtra(String)
4254 */
4255 public Intent putExtra(String name, byte[] value) {
4256 if (mExtras == null) {
4257 mExtras = new Bundle();
4258 }
4259 mExtras.putByteArray(name, value);
4260 return this;
4261 }
4262
4263 /**
4264 * Add extended data to the intent. The name must include a package
4265 * prefix, for example the app com.android.contacts would use names
4266 * like "com.android.contacts.ShowAll".
4267 *
4268 * @param name The name of the extra data, with package prefix.
4269 * @param value The short array data value.
4270 *
4271 * @return Returns the same Intent object, for chaining multiple calls
4272 * into a single statement.
4273 *
4274 * @see #putExtras
4275 * @see #removeExtra
4276 * @see #getShortArrayExtra(String)
4277 */
4278 public Intent putExtra(String name, short[] value) {
4279 if (mExtras == null) {
4280 mExtras = new Bundle();
4281 }
4282 mExtras.putShortArray(name, value);
4283 return this;
4284 }
4285
4286 /**
4287 * Add extended data to the intent. The name must include a package
4288 * prefix, for example the app com.android.contacts would use names
4289 * like "com.android.contacts.ShowAll".
4290 *
4291 * @param name The name of the extra data, with package prefix.
4292 * @param value The char array data value.
4293 *
4294 * @return Returns the same Intent object, for chaining multiple calls
4295 * into a single statement.
4296 *
4297 * @see #putExtras
4298 * @see #removeExtra
4299 * @see #getCharArrayExtra(String)
4300 */
4301 public Intent putExtra(String name, char[] value) {
4302 if (mExtras == null) {
4303 mExtras = new Bundle();
4304 }
4305 mExtras.putCharArray(name, value);
4306 return this;
4307 }
4308
4309 /**
4310 * Add extended data to the intent. The name must include a package
4311 * prefix, for example the app com.android.contacts would use names
4312 * like "com.android.contacts.ShowAll".
4313 *
4314 * @param name The name of the extra data, with package prefix.
4315 * @param value The int array data value.
4316 *
4317 * @return Returns the same Intent object, for chaining multiple calls
4318 * into a single statement.
4319 *
4320 * @see #putExtras
4321 * @see #removeExtra
4322 * @see #getIntArrayExtra(String)
4323 */
4324 public Intent putExtra(String name, int[] value) {
4325 if (mExtras == null) {
4326 mExtras = new Bundle();
4327 }
4328 mExtras.putIntArray(name, value);
4329 return this;
4330 }
4331
4332 /**
4333 * Add extended data to the intent. The name must include a package
4334 * prefix, for example the app com.android.contacts would use names
4335 * like "com.android.contacts.ShowAll".
4336 *
4337 * @param name The name of the extra data, with package prefix.
4338 * @param value The byte array data value.
4339 *
4340 * @return Returns the same Intent object, for chaining multiple calls
4341 * into a single statement.
4342 *
4343 * @see #putExtras
4344 * @see #removeExtra
4345 * @see #getLongArrayExtra(String)
4346 */
4347 public Intent putExtra(String name, long[] value) {
4348 if (mExtras == null) {
4349 mExtras = new Bundle();
4350 }
4351 mExtras.putLongArray(name, value);
4352 return this;
4353 }
4354
4355 /**
4356 * Add extended data to the intent. The name must include a package
4357 * prefix, for example the app com.android.contacts would use names
4358 * like "com.android.contacts.ShowAll".
4359 *
4360 * @param name The name of the extra data, with package prefix.
4361 * @param value The float array data value.
4362 *
4363 * @return Returns the same Intent object, for chaining multiple calls
4364 * into a single statement.
4365 *
4366 * @see #putExtras
4367 * @see #removeExtra
4368 * @see #getFloatArrayExtra(String)
4369 */
4370 public Intent putExtra(String name, float[] value) {
4371 if (mExtras == null) {
4372 mExtras = new Bundle();
4373 }
4374 mExtras.putFloatArray(name, value);
4375 return this;
4376 }
4377
4378 /**
4379 * Add extended data to the intent. The name must include a package
4380 * prefix, for example the app com.android.contacts would use names
4381 * like "com.android.contacts.ShowAll".
4382 *
4383 * @param name The name of the extra data, with package prefix.
4384 * @param value The double array data value.
4385 *
4386 * @return Returns the same Intent object, for chaining multiple calls
4387 * into a single statement.
4388 *
4389 * @see #putExtras
4390 * @see #removeExtra
4391 * @see #getDoubleArrayExtra(String)
4392 */
4393 public Intent putExtra(String name, double[] value) {
4394 if (mExtras == null) {
4395 mExtras = new Bundle();
4396 }
4397 mExtras.putDoubleArray(name, value);
4398 return this;
4399 }
4400
4401 /**
4402 * Add extended data to the intent. The name must include a package
4403 * prefix, for example the app com.android.contacts would use names
4404 * like "com.android.contacts.ShowAll".
4405 *
4406 * @param name The name of the extra data, with package prefix.
4407 * @param value The String array data value.
4408 *
4409 * @return Returns the same Intent object, for chaining multiple calls
4410 * into a single statement.
4411 *
4412 * @see #putExtras
4413 * @see #removeExtra
4414 * @see #getStringArrayExtra(String)
4415 */
4416 public Intent putExtra(String name, String[] value) {
4417 if (mExtras == null) {
4418 mExtras = new Bundle();
4419 }
4420 mExtras.putStringArray(name, value);
4421 return this;
4422 }
4423
4424 /**
4425 * Add extended data to the intent. The name must include a package
4426 * prefix, for example the app com.android.contacts would use names
4427 * like "com.android.contacts.ShowAll".
4428 *
4429 * @param name The name of the extra data, with package prefix.
4430 * @param value The Bundle data value.
4431 *
4432 * @return Returns the same Intent object, for chaining multiple calls
4433 * into a single statement.
4434 *
4435 * @see #putExtras
4436 * @see #removeExtra
4437 * @see #getBundleExtra(String)
4438 */
4439 public Intent putExtra(String name, Bundle value) {
4440 if (mExtras == null) {
4441 mExtras = new Bundle();
4442 }
4443 mExtras.putBundle(name, value);
4444 return this;
4445 }
4446
4447 /**
4448 * Add extended data to the intent. The name must include a package
4449 * prefix, for example the app com.android.contacts would use names
4450 * like "com.android.contacts.ShowAll".
4451 *
4452 * @param name The name of the extra data, with package prefix.
4453 * @param value The IBinder data value.
4454 *
4455 * @return Returns the same Intent object, for chaining multiple calls
4456 * into a single statement.
4457 *
4458 * @see #putExtras
4459 * @see #removeExtra
4460 * @see #getIBinderExtra(String)
4461 *
4462 * @deprecated
4463 * @hide
4464 */
4465 @Deprecated
4466 public Intent putExtra(String name, IBinder value) {
4467 if (mExtras == null) {
4468 mExtras = new Bundle();
4469 }
4470 mExtras.putIBinder(name, value);
4471 return this;
4472 }
4473
4474 /**
4475 * Copy all extras in 'src' in to this intent.
4476 *
4477 * @param src Contains the extras to copy.
4478 *
4479 * @see #putExtra
4480 */
4481 public Intent putExtras(Intent src) {
4482 if (src.mExtras != null) {
4483 if (mExtras == null) {
4484 mExtras = new Bundle(src.mExtras);
4485 } else {
4486 mExtras.putAll(src.mExtras);
4487 }
4488 }
4489 return this;
4490 }
4491
4492 /**
4493 * Add a set of extended data to the intent. The keys must include a package
4494 * prefix, for example the app com.android.contacts would use names
4495 * like "com.android.contacts.ShowAll".
4496 *
4497 * @param extras The Bundle of extras to add to this intent.
4498 *
4499 * @see #putExtra
4500 * @see #removeExtra
4501 */
4502 public Intent putExtras(Bundle extras) {
4503 if (mExtras == null) {
4504 mExtras = new Bundle();
4505 }
4506 mExtras.putAll(extras);
4507 return this;
4508 }
4509
4510 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004511 * Completely replace the extras in the Intent with the extras in the
4512 * given Intent.
The Android Open Source Project10592532009-03-18 17:39:46 -07004513 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004514 * @param src The exact extras contained in this Intent are copied
4515 * into the target intent, replacing any that were previously there.
4516 */
4517 public Intent replaceExtras(Intent src) {
4518 mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null;
4519 return this;
4520 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004521
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004522 /**
4523 * Completely replace the extras in the Intent with the given Bundle of
4524 * extras.
The Android Open Source Project10592532009-03-18 17:39:46 -07004525 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004526 * @param extras The new set of extras in the Intent, or null to erase
4527 * all extras.
4528 */
4529 public Intent replaceExtras(Bundle extras) {
4530 mExtras = extras != null ? new Bundle(extras) : null;
4531 return this;
4532 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004533
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004534 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004535 * Remove extended data from the intent.
4536 *
4537 * @see #putExtra
4538 */
4539 public void removeExtra(String name) {
4540 if (mExtras != null) {
4541 mExtras.remove(name);
4542 if (mExtras.size() == 0) {
4543 mExtras = null;
4544 }
4545 }
4546 }
4547
4548 /**
4549 * Set special flags controlling how this intent is handled. Most values
4550 * here depend on the type of component being executed by the Intent,
4551 * specifically the FLAG_ACTIVITY_* flags are all for use with
4552 * {@link Context#startActivity Context.startActivity()} and the
4553 * FLAG_RECEIVER_* flags are all for use with
4554 * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
4555 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004556 * <p>See the <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
4557 * Activities and Tasks</a> documentation for important information on how some of these options impact
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004558 * the behavior of your application.
4559 *
4560 * @param flags The desired flags.
4561 *
4562 * @return Returns the same Intent object, for chaining multiple calls
4563 * into a single statement.
4564 *
4565 * @see #getFlags
4566 * @see #addFlags
4567 *
4568 * @see #FLAG_GRANT_READ_URI_PERMISSION
4569 * @see #FLAG_GRANT_WRITE_URI_PERMISSION
4570 * @see #FLAG_DEBUG_LOG_RESOLUTION
4571 * @see #FLAG_FROM_BACKGROUND
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004572 * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004573 * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004574 * @see #FLAG_ACTIVITY_CLEAR_TOP
4575 * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
4576 * @see #FLAG_ACTIVITY_FORWARD_RESULT
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004577 * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004578 * @see #FLAG_ACTIVITY_MULTIPLE_TASK
4579 * @see #FLAG_ACTIVITY_NEW_TASK
4580 * @see #FLAG_ACTIVITY_NO_HISTORY
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08004581 * @see #FLAG_ACTIVITY_NO_USER_ACTION
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004582 * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP
4583 * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004584 * @see #FLAG_ACTIVITY_SINGLE_TOP
4585 * @see #FLAG_RECEIVER_REGISTERED_ONLY
4586 */
4587 public Intent setFlags(int flags) {
4588 mFlags = flags;
4589 return this;
4590 }
4591
4592 /**
4593 * Add additional flags to the intent (or with existing flags
4594 * value).
4595 *
4596 * @param flags The new flags to set.
4597 *
4598 * @return Returns the same Intent object, for chaining multiple calls
4599 * into a single statement.
4600 *
4601 * @see #setFlags
4602 */
4603 public Intent addFlags(int flags) {
4604 mFlags |= flags;
4605 return this;
4606 }
4607
4608 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004609 * (Usually optional) Set an explicit application package name that limits
4610 * the components this Intent will resolve to. If left to the default
4611 * value of null, all components in all applications will considered.
4612 * If non-null, the Intent can only match the components in the given
4613 * application package.
4614 *
4615 * @param packageName The name of the application package to handle the
4616 * intent, or null to allow any application package.
4617 *
4618 * @return Returns the same Intent object, for chaining multiple calls
4619 * into a single statement.
4620 *
4621 * @see #getPackage
4622 * @see #resolveActivity
4623 */
4624 public Intent setPackage(String packageName) {
4625 mPackage = packageName;
4626 return this;
4627 }
4628
4629 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004630 * (Usually optional) Explicitly set the component to handle the intent.
4631 * If left with the default value of null, the system will determine the
4632 * appropriate class to use based on the other fields (action, data,
4633 * type, categories) in the Intent. If this class is defined, the
4634 * specified class will always be used regardless of the other fields. You
4635 * should only set this value when you know you absolutely want a specific
4636 * class to be used; otherwise it is better to let the system find the
4637 * appropriate class so that you will respect the installed applications
4638 * and user preferences.
4639 *
4640 * @param component The name of the application component to handle the
4641 * intent, or null to let the system find one for you.
4642 *
4643 * @return Returns the same Intent object, for chaining multiple calls
4644 * into a single statement.
4645 *
4646 * @see #setClass
4647 * @see #setClassName(Context, String)
4648 * @see #setClassName(String, String)
4649 * @see #getComponent
4650 * @see #resolveActivity
4651 */
4652 public Intent setComponent(ComponentName component) {
4653 mComponent = component;
4654 return this;
4655 }
4656
4657 /**
4658 * Convenience for calling {@link #setComponent} with an
4659 * explicit class name.
4660 *
4661 * @param packageContext A Context of the application package implementing
4662 * this class.
4663 * @param className The name of a class inside of the application package
4664 * that will be used as the component for this Intent.
4665 *
4666 * @return Returns the same Intent object, for chaining multiple calls
4667 * into a single statement.
4668 *
4669 * @see #setComponent
4670 * @see #setClass
4671 */
4672 public Intent setClassName(Context packageContext, String className) {
4673 mComponent = new ComponentName(packageContext, className);
4674 return this;
4675 }
4676
4677 /**
4678 * Convenience for calling {@link #setComponent} with an
4679 * explicit application package name and class name.
4680 *
4681 * @param packageName The name of the package implementing the desired
4682 * component.
4683 * @param className The name of a class inside of the application package
4684 * that will be used as the component for this Intent.
4685 *
4686 * @return Returns the same Intent object, for chaining multiple calls
4687 * into a single statement.
4688 *
4689 * @see #setComponent
4690 * @see #setClass
4691 */
4692 public Intent setClassName(String packageName, String className) {
4693 mComponent = new ComponentName(packageName, className);
4694 return this;
4695 }
4696
4697 /**
4698 * Convenience for calling {@link #setComponent(ComponentName)} with the
4699 * name returned by a {@link Class} object.
4700 *
4701 * @param packageContext A Context of the application package implementing
4702 * this class.
4703 * @param cls The class name to set, equivalent to
4704 * <code>setClassName(context, cls.getName())</code>.
4705 *
4706 * @return Returns the same Intent object, for chaining multiple calls
4707 * into a single statement.
4708 *
4709 * @see #setComponent
4710 */
4711 public Intent setClass(Context packageContext, Class<?> cls) {
4712 mComponent = new ComponentName(packageContext, cls);
4713 return this;
4714 }
4715
4716 /**
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08004717 * Set the bounds of the sender of this intent, in screen coordinates. This can be
4718 * used as a hint to the receiver for animations and the like. Null means that there
4719 * is no source bounds.
4720 */
4721 public void setSourceBounds(Rect r) {
4722 if (r != null) {
4723 mSourceBounds = new Rect(r);
4724 } else {
4725 r = null;
4726 }
4727 }
4728
4729 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004730 * Use with {@link #fillIn} to allow the current action value to be
4731 * overwritten, even if it is already set.
4732 */
4733 public static final int FILL_IN_ACTION = 1<<0;
4734
4735 /**
4736 * Use with {@link #fillIn} to allow the current data or type value
4737 * overwritten, even if it is already set.
4738 */
4739 public static final int FILL_IN_DATA = 1<<1;
4740
4741 /**
4742 * Use with {@link #fillIn} to allow the current categories to be
4743 * overwritten, even if they are already set.
4744 */
4745 public static final int FILL_IN_CATEGORIES = 1<<2;
4746
4747 /**
4748 * Use with {@link #fillIn} to allow the current component value to be
4749 * overwritten, even if it is already set.
4750 */
4751 public static final int FILL_IN_COMPONENT = 1<<3;
4752
4753 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004754 * Use with {@link #fillIn} to allow the current package value to be
4755 * overwritten, even if it is already set.
4756 */
4757 public static final int FILL_IN_PACKAGE = 1<<4;
4758
4759 /**
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08004760 * Use with {@link #fillIn} to allow the current package value to be
4761 * overwritten, even if it is already set.
4762 */
4763 public static final int FILL_IN_SOURCE_BOUNDS = 1<<5;
4764
4765 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004766 * Copy the contents of <var>other</var> in to this object, but only
4767 * where fields are not defined by this object. For purposes of a field
4768 * being defined, the following pieces of data in the Intent are
4769 * considered to be separate fields:
4770 *
4771 * <ul>
4772 * <li> action, as set by {@link #setAction}.
4773 * <li> data URI and MIME type, as set by {@link #setData(Uri)},
4774 * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}.
4775 * <li> categories, as set by {@link #addCategory}.
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004776 * <li> package, as set by {@link #setPackage}.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004777 * <li> component, as set by {@link #setComponent(ComponentName)} or
4778 * related methods.
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08004779 * <li> source bounds, as set by {@link #setSourceBounds}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004780 * <li> each top-level name in the associated extras.
4781 * </ul>
4782 *
4783 * <p>In addition, you can use the {@link #FILL_IN_ACTION},
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004784 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
4785 * and {@link #FILL_IN_COMPONENT} to override the restriction where the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004786 * corresponding field will not be replaced if it is already set.
4787 *
Brett Chabot3e391752009-07-21 16:07:23 -07004788 * <p>Note: The component field will only be copied if {@link #FILL_IN_COMPONENT} is explicitly
4789 * specified.
4790 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004791 * <p>For example, consider Intent A with {data="foo", categories="bar"}
4792 * and Intent B with {action="gotit", data-type="some/thing",
4793 * categories="one","two"}.
4794 *
4795 * <p>Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now
4796 * containing: {action="gotit", data-type="some/thing",
4797 * categories="bar"}.
4798 *
4799 * @param other Another Intent whose values are to be used to fill in
4800 * the current one.
4801 * @param flags Options to control which fields can be filled in.
4802 *
4803 * @return Returns a bit mask of {@link #FILL_IN_ACTION},
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004804 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
4805 * and {@link #FILL_IN_COMPONENT} indicating which fields were changed.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004806 */
4807 public int fillIn(Intent other, int flags) {
4808 int changes = 0;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004809 if (other.mAction != null
4810 && (mAction == null || (flags&FILL_IN_ACTION) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004811 mAction = other.mAction;
4812 changes |= FILL_IN_ACTION;
4813 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004814 if ((other.mData != null || other.mType != null)
4815 && ((mData == null && mType == null)
4816 || (flags&FILL_IN_DATA) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004817 mData = other.mData;
4818 mType = other.mType;
4819 changes |= FILL_IN_DATA;
4820 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004821 if (other.mCategories != null
4822 && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004823 if (other.mCategories != null) {
4824 mCategories = new HashSet<String>(other.mCategories);
4825 }
4826 changes |= FILL_IN_CATEGORIES;
4827 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004828 if (other.mPackage != null
4829 && (mPackage == null || (flags&FILL_IN_PACKAGE) != 0)) {
4830 mPackage = other.mPackage;
4831 changes |= FILL_IN_PACKAGE;
4832 }
4833 // Component is special: it can -only- be set if explicitly allowed,
4834 // since otherwise the sender could force the intent somewhere the
4835 // originator didn't intend.
4836 if (other.mComponent != null && (flags&FILL_IN_COMPONENT) != 0) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004837 mComponent = other.mComponent;
4838 changes |= FILL_IN_COMPONENT;
4839 }
4840 mFlags |= other.mFlags;
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08004841 if (other.mSourceBounds != null
4842 && (mSourceBounds == null || (flags&FILL_IN_SOURCE_BOUNDS) != 0)) {
4843 mSourceBounds = new Rect(other.mSourceBounds);
4844 changes |= FILL_IN_SOURCE_BOUNDS;
4845 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004846 if (mExtras == null) {
4847 if (other.mExtras != null) {
4848 mExtras = new Bundle(other.mExtras);
4849 }
4850 } else if (other.mExtras != null) {
4851 try {
4852 Bundle newb = new Bundle(other.mExtras);
4853 newb.putAll(mExtras);
4854 mExtras = newb;
4855 } catch (RuntimeException e) {
4856 // Modifying the extras can cause us to unparcel the contents
4857 // of the bundle, and if we do this in the system process that
4858 // may fail. We really should handle this (i.e., the Bundle
4859 // impl shouldn't be on top of a plain map), but for now just
4860 // ignore it and keep the original contents. :(
4861 Log.w("Intent", "Failure filling in extras", e);
4862 }
4863 }
4864 return changes;
4865 }
4866
4867 /**
4868 * Wrapper class holding an Intent and implementing comparisons on it for
4869 * the purpose of filtering. The class implements its
4870 * {@link #equals equals()} and {@link #hashCode hashCode()} methods as
4871 * simple calls to {@link Intent#filterEquals(Intent)} filterEquals()} and
4872 * {@link android.content.Intent#filterHashCode()} filterHashCode()}
4873 * on the wrapped Intent.
4874 */
4875 public static final class FilterComparison {
4876 private final Intent mIntent;
4877 private final int mHashCode;
4878
4879 public FilterComparison(Intent intent) {
4880 mIntent = intent;
4881 mHashCode = intent.filterHashCode();
4882 }
4883
4884 /**
4885 * Return the Intent that this FilterComparison represents.
4886 * @return Returns the Intent held by the FilterComparison. Do
4887 * not modify!
4888 */
4889 public Intent getIntent() {
4890 return mIntent;
4891 }
4892
4893 @Override
4894 public boolean equals(Object obj) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 if (obj instanceof FilterComparison) {
4896 Intent other = ((FilterComparison)obj).mIntent;
4897 return mIntent.filterEquals(other);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004899 return false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004900 }
4901
4902 @Override
4903 public int hashCode() {
4904 return mHashCode;
4905 }
4906 }
4907
4908 /**
4909 * Determine if two intents are the same for the purposes of intent
4910 * resolution (filtering). That is, if their action, data, type,
4911 * class, and categories are the same. This does <em>not</em> compare
4912 * any extra data included in the intents.
4913 *
4914 * @param other The other Intent to compare against.
4915 *
4916 * @return Returns true if action, data, type, class, and categories
4917 * are the same.
4918 */
4919 public boolean filterEquals(Intent other) {
4920 if (other == null) {
4921 return false;
4922 }
4923 if (mAction != other.mAction) {
4924 if (mAction != null) {
4925 if (!mAction.equals(other.mAction)) {
4926 return false;
4927 }
4928 } else {
4929 if (!other.mAction.equals(mAction)) {
4930 return false;
4931 }
4932 }
4933 }
4934 if (mData != other.mData) {
4935 if (mData != null) {
4936 if (!mData.equals(other.mData)) {
4937 return false;
4938 }
4939 } else {
4940 if (!other.mData.equals(mData)) {
4941 return false;
4942 }
4943 }
4944 }
4945 if (mType != other.mType) {
4946 if (mType != null) {
4947 if (!mType.equals(other.mType)) {
4948 return false;
4949 }
4950 } else {
4951 if (!other.mType.equals(mType)) {
4952 return false;
4953 }
4954 }
4955 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004956 if (mPackage != other.mPackage) {
4957 if (mPackage != null) {
4958 if (!mPackage.equals(other.mPackage)) {
4959 return false;
4960 }
4961 } else {
4962 if (!other.mPackage.equals(mPackage)) {
4963 return false;
4964 }
4965 }
4966 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004967 if (mComponent != other.mComponent) {
4968 if (mComponent != null) {
4969 if (!mComponent.equals(other.mComponent)) {
4970 return false;
4971 }
4972 } else {
4973 if (!other.mComponent.equals(mComponent)) {
4974 return false;
4975 }
4976 }
4977 }
4978 if (mCategories != other.mCategories) {
4979 if (mCategories != null) {
4980 if (!mCategories.equals(other.mCategories)) {
4981 return false;
4982 }
4983 } else {
4984 if (!other.mCategories.equals(mCategories)) {
4985 return false;
4986 }
4987 }
4988 }
4989
4990 return true;
4991 }
4992
4993 /**
4994 * Generate hash code that matches semantics of filterEquals().
4995 *
4996 * @return Returns the hash value of the action, data, type, class, and
4997 * categories.
4998 *
4999 * @see #filterEquals
5000 */
5001 public int filterHashCode() {
5002 int code = 0;
5003 if (mAction != null) {
5004 code += mAction.hashCode();
5005 }
5006 if (mData != null) {
5007 code += mData.hashCode();
5008 }
5009 if (mType != null) {
5010 code += mType.hashCode();
5011 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005012 if (mPackage != null) {
5013 code += mPackage.hashCode();
5014 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005015 if (mComponent != null) {
5016 code += mComponent.hashCode();
5017 }
5018 if (mCategories != null) {
5019 code += mCategories.hashCode();
5020 }
5021 return code;
5022 }
5023
5024 @Override
5025 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005026 StringBuilder b = new StringBuilder(128);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005027
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005028 b.append("Intent { ");
5029 toShortString(b, true, true);
5030 b.append(" }");
5031
5032 return b.toString();
5033 }
5034
5035 /** @hide */
5036 public String toShortString(boolean comp, boolean extras) {
5037 StringBuilder b = new StringBuilder(128);
5038 toShortString(b, comp, extras);
5039 return b.toString();
5040 }
Romain Guy4969af72009-06-17 10:53:19 -07005041
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005042 /** @hide */
5043 public void toShortString(StringBuilder b, boolean comp, boolean extras) {
5044 boolean first = true;
5045 if (mAction != null) {
5046 b.append("act=").append(mAction);
5047 first = false;
5048 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005049 if (mCategories != null) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005050 if (!first) {
5051 b.append(' ');
5052 }
5053 first = false;
5054 b.append("cat=[");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005055 Iterator<String> i = mCategories.iterator();
5056 boolean didone = false;
5057 while (i.hasNext()) {
5058 if (didone) b.append(",");
5059 didone = true;
5060 b.append(i.next());
5061 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005062 b.append("]");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005063 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005064 if (mData != null) {
5065 if (!first) {
5066 b.append(' ');
5067 }
5068 first = false;
5069 b.append("dat=").append(mData);
5070 }
5071 if (mType != null) {
5072 if (!first) {
5073 b.append(' ');
5074 }
5075 first = false;
5076 b.append("typ=").append(mType);
5077 }
5078 if (mFlags != 0) {
5079 if (!first) {
5080 b.append(' ');
5081 }
5082 first = false;
5083 b.append("flg=0x").append(Integer.toHexString(mFlags));
5084 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005085 if (mPackage != null) {
5086 if (!first) {
5087 b.append(' ');
5088 }
5089 first = false;
5090 b.append("pkg=").append(mPackage);
5091 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005092 if (comp && mComponent != null) {
5093 if (!first) {
5094 b.append(' ');
5095 }
5096 first = false;
5097 b.append("cmp=").append(mComponent.flattenToShortString());
5098 }
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08005099 if (mSourceBounds != null) {
5100 if (!first) {
5101 b.append(' ');
5102 }
5103 first = false;
5104 b.append("bnds=").append(mSourceBounds.toShortString());
5105 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005106 if (extras && mExtras != null) {
5107 if (!first) {
5108 b.append(' ');
5109 }
5110 first = false;
5111 b.append("(has extras)");
5112 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005113 }
5114
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005115 /**
5116 * Call {@link #toUri} with 0 flags.
5117 * @deprecated Use {@link #toUri} instead.
5118 */
5119 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005120 public String toURI() {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005121 return toUri(0);
5122 }
5123
5124 /**
5125 * Convert this Intent into a String holding a URI representation of it.
5126 * The returned URI string has been properly URI encoded, so it can be
5127 * used with {@link Uri#parse Uri.parse(String)}. The URI contains the
5128 * Intent's data as the base URI, with an additional fragment describing
5129 * the action, categories, type, flags, package, component, and extras.
5130 *
5131 * <p>You can convert the returned string back to an Intent with
5132 * {@link #getIntent}.
5133 *
5134 * @param flags Additional operating flags. Either 0 or
5135 * {@link #URI_INTENT_SCHEME}.
5136 *
5137 * @return Returns a URI encoding URI string describing the entire contents
5138 * of the Intent.
5139 */
5140 public String toUri(int flags) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005141 StringBuilder uri = new StringBuilder(128);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005142 String scheme = null;
5143 if (mData != null) {
5144 String data = mData.toString();
5145 if ((flags&URI_INTENT_SCHEME) != 0) {
5146 final int N = data.length();
5147 for (int i=0; i<N; i++) {
5148 char c = data.charAt(i);
5149 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
5150 || c == '.' || c == '-') {
5151 continue;
5152 }
5153 if (c == ':' && i > 0) {
5154 // Valid scheme.
5155 scheme = data.substring(0, i);
5156 uri.append("intent:");
5157 data = data.substring(i+1);
5158 break;
5159 }
5160
5161 // No scheme.
5162 break;
5163 }
5164 }
5165 uri.append(data);
5166
5167 } else if ((flags&URI_INTENT_SCHEME) != 0) {
5168 uri.append("intent:");
5169 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005170
5171 uri.append("#Intent;");
5172
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005173 if (scheme != null) {
5174 uri.append("scheme=").append(scheme).append(';');
5175 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005176 if (mAction != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005177 uri.append("action=").append(Uri.encode(mAction)).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005178 }
5179 if (mCategories != null) {
5180 for (String category : mCategories) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005181 uri.append("category=").append(Uri.encode(category)).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005182 }
5183 }
5184 if (mType != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005185 uri.append("type=").append(Uri.encode(mType, "/")).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005186 }
5187 if (mFlags != 0) {
5188 uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
5189 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005190 if (mPackage != null) {
5191 uri.append("package=").append(Uri.encode(mPackage)).append(';');
5192 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005193 if (mComponent != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005194 uri.append("component=").append(Uri.encode(
5195 mComponent.flattenToShortString(), "/")).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005196 }
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08005197 if (mSourceBounds != null) {
5198 uri.append("sourceBounds=")
5199 .append(Uri.encode(mSourceBounds.flattenToString()))
5200 .append(';');
5201 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005202 if (mExtras != null) {
5203 for (String key : mExtras.keySet()) {
5204 final Object value = mExtras.get(key);
5205 char entryType =
5206 value instanceof String ? 'S' :
5207 value instanceof Boolean ? 'B' :
5208 value instanceof Byte ? 'b' :
5209 value instanceof Character ? 'c' :
5210 value instanceof Double ? 'd' :
5211 value instanceof Float ? 'f' :
5212 value instanceof Integer ? 'i' :
5213 value instanceof Long ? 'l' :
5214 value instanceof Short ? 's' :
5215 '\0';
5216
5217 if (entryType != '\0') {
5218 uri.append(entryType);
5219 uri.append('.');
5220 uri.append(Uri.encode(key));
5221 uri.append('=');
5222 uri.append(Uri.encode(value.toString()));
5223 uri.append(';');
5224 }
5225 }
5226 }
The Android Open Source Project10592532009-03-18 17:39:46 -07005227
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005228 uri.append("end");
5229
5230 return uri.toString();
5231 }
The Android Open Source Project10592532009-03-18 17:39:46 -07005232
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005233 public int describeContents() {
5234 return (mExtras != null) ? mExtras.describeContents() : 0;
5235 }
5236
5237 public void writeToParcel(Parcel out, int flags) {
5238 out.writeString(mAction);
5239 Uri.writeToParcel(out, mData);
5240 out.writeString(mType);
5241 out.writeInt(mFlags);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005242 out.writeString(mPackage);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005243 ComponentName.writeToParcel(mComponent, out);
5244
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08005245 if (mSourceBounds != null) {
5246 out.writeInt(1);
5247 mSourceBounds.writeToParcel(out, flags);
5248 } else {
5249 out.writeInt(0);
5250 }
5251
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005252 if (mCategories != null) {
5253 out.writeInt(mCategories.size());
5254 for (String category : mCategories) {
5255 out.writeString(category);
5256 }
5257 } else {
5258 out.writeInt(0);
5259 }
5260
5261 out.writeBundle(mExtras);
5262 }
5263
5264 public static final Parcelable.Creator<Intent> CREATOR
5265 = new Parcelable.Creator<Intent>() {
5266 public Intent createFromParcel(Parcel in) {
5267 return new Intent(in);
5268 }
5269 public Intent[] newArray(int size) {
5270 return new Intent[size];
5271 }
5272 };
5273
Dianne Hackborneb034652009-09-07 00:49:58 -07005274 /** @hide */
5275 protected Intent(Parcel in) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005276 readFromParcel(in);
5277 }
5278
5279 public void readFromParcel(Parcel in) {
5280 mAction = in.readString();
5281 mData = Uri.CREATOR.createFromParcel(in);
5282 mType = in.readString();
5283 mFlags = in.readInt();
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005284 mPackage = in.readString();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005285 mComponent = ComponentName.readFromParcel(in);
5286
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08005287 if (in.readInt() != 0) {
5288 mSourceBounds = Rect.CREATOR.createFromParcel(in);
5289 }
5290
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005291 int N = in.readInt();
5292 if (N > 0) {
5293 mCategories = new HashSet<String>();
5294 int i;
5295 for (i=0; i<N; i++) {
5296 mCategories.add(in.readString());
5297 }
5298 } else {
5299 mCategories = null;
5300 }
5301
5302 mExtras = in.readBundle();
5303 }
5304
5305 /**
5306 * Parses the "intent" element (and its children) from XML and instantiates
5307 * an Intent object. The given XML parser should be located at the tag
5308 * where parsing should start (often named "intent"), from which the
5309 * basic action, data, type, and package and class name will be
5310 * retrieved. The function will then parse in to any child elements,
5311 * looking for <category android:name="xxx"> tags to add categories and
5312 * <extra android:name="xxx" android:value="yyy"> to attach extra data
5313 * to the intent.
5314 *
5315 * @param resources The Resources to use when inflating resources.
5316 * @param parser The XML parser pointing at an "intent" tag.
5317 * @param attrs The AttributeSet interface for retrieving extended
5318 * attribute data at the current <var>parser</var> location.
5319 * @return An Intent object matching the XML data.
5320 * @throws XmlPullParserException If there was an XML parsing error.
5321 * @throws IOException If there was an I/O error.
5322 */
5323 public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
5324 throws XmlPullParserException, IOException {
5325 Intent intent = new Intent();
5326
5327 TypedArray sa = resources.obtainAttributes(attrs,
5328 com.android.internal.R.styleable.Intent);
5329
5330 intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action));
5331
5332 String data = sa.getString(com.android.internal.R.styleable.Intent_data);
5333 String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType);
5334 intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType);
5335
5336 String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage);
5337 String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass);
5338 if (packageName != null && className != null) {
5339 intent.setComponent(new ComponentName(packageName, className));
5340 }
5341
5342 sa.recycle();
5343
5344 int outerDepth = parser.getDepth();
5345 int type;
5346 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
5347 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
5348 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
5349 continue;
5350 }
5351
5352 String nodeName = parser.getName();
5353 if (nodeName.equals("category")) {
5354 sa = resources.obtainAttributes(attrs,
5355 com.android.internal.R.styleable.IntentCategory);
5356 String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name);
5357 sa.recycle();
5358
5359 if (cat != null) {
5360 intent.addCategory(cat);
5361 }
5362 XmlUtils.skipCurrentTag(parser);
5363
5364 } else if (nodeName.equals("extra")) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08005365 if (intent.mExtras == null) {
5366 intent.mExtras = new Bundle();
5367 }
5368 resources.parseBundleExtra("extra", attrs, intent.mExtras);
5369 XmlUtils.skipCurrentTag(parser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005370
5371 } else {
5372 XmlUtils.skipCurrentTag(parser);
5373 }
5374 }
5375
5376 return intent;
5377 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005378}