blob: e957e2019eac46e866517c0e15795ed942cab7a5 [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;
Tom Taylord4a47292009-12-21 13:59:18 -080037import com.android.common.XmlUtils;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070038
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 /**
1105 * Activity Action: The user pressed the "Report" button in the crash/ANR dialog.
1106 * This intent is delivered to the package which installed the application, usually
1107 * the Market.
1108 * <p>Input: No data is specified. The bug report is passed in using
1109 * an {@link #EXTRA_BUG_REPORT} field.
1110 * <p>Output: Nothing.
1111 * @hide
1112 */
1113 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1114 public static final String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
Dianne Hackborn3d74bb42009-06-19 10:35:21 -07001115
1116 /**
1117 * Activity Action: Show power usage information to the user.
1118 * <p>Input: Nothing.
1119 * <p>Output: Nothing.
1120 */
1121 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1122 public static final String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
Tom Taylord4a47292009-12-21 13:59:18 -08001123
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07001124 /**
1125 * Activity Action: Setup wizard to launch after a platform update. This
1126 * activity should have a string meta-data field associated with it,
1127 * {@link #METADATA_SETUP_VERSION}, which defines the current version of
1128 * the platform for setup. The activity will be launched only if
1129 * {@link android.provider.Settings.Secure#LAST_SETUP_SHOWN} is not the
1130 * same value.
1131 * <p>Input: Nothing.
1132 * <p>Output: Nothing.
1133 * @hide
1134 */
1135 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1136 public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
Tom Taylord4a47292009-12-21 13:59:18 -08001137
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07001138 /**
1139 * A string associated with a {@link #ACTION_UPGRADE_SETUP} activity
1140 * describing the last run version of the platform that was setup.
1141 * @hide
1142 */
1143 public static final String METADATA_SETUP_VERSION = "android.SETUP_VERSION";
1144
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001145 // ---------------------------------------------------------------------
1146 // ---------------------------------------------------------------------
1147 // Standard intent broadcast actions (see action variable).
1148
1149 /**
1150 * Broadcast Action: Sent after the screen turns off.
Tom Taylord4a47292009-12-21 13:59:18 -08001151 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001152 * <p class="note">This is a protected intent that can only be sent
1153 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001154 */
1155 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1156 public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
1157 /**
1158 * Broadcast Action: Sent after the screen turns on.
Tom Taylord4a47292009-12-21 13:59:18 -08001159 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001160 * <p class="note">This is a protected intent that can only be sent
1161 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001162 */
1163 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1164 public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001165
1166 /**
The Android Open Source Project10592532009-03-18 17:39:46 -07001167 * 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 -07001168 * keyguard is gone).
Tom Taylord4a47292009-12-21 13:59:18 -08001169 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001170 * <p class="note">This is a protected intent that can only be sent
1171 * by the system.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001172 */
1173 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001174 public static final String ACTION_USER_PRESENT = "android.intent.action.USER_PRESENT";
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001175
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001176 /**
1177 * Broadcast Action: The current time has changed. Sent every
1178 * minute. You can <em>not</em> receive this through components declared
1179 * in manifests, only by exlicitly registering for it with
1180 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1181 * Context.registerReceiver()}.
Tom Taylord4a47292009-12-21 13:59:18 -08001182 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001183 * <p class="note">This is a protected intent that can only be sent
1184 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001185 */
1186 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1187 public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
1188 /**
1189 * Broadcast Action: The time was set.
1190 */
1191 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1192 public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
1193 /**
1194 * Broadcast Action: The date has changed.
1195 */
1196 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1197 public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
1198 /**
1199 * Broadcast Action: The timezone has changed. The intent will have the following extra values:</p>
1200 * <ul>
1201 * <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time zone.</li>
1202 * </ul>
Tom Taylord4a47292009-12-21 13:59:18 -08001203 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001204 * <p class="note">This is a protected intent that can only be sent
1205 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001206 */
1207 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1208 public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
1209 /**
1210 * Alarm Changed Action: This is broadcast when the AlarmClock
1211 * application's alarm is set or unset. It is used by the
1212 * AlarmClock application and the StatusBar service.
1213 * @hide
1214 */
1215 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1216 public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
1217 /**
1218 * Sync State Changed Action: This is broadcast when the sync starts or stops or when one has
1219 * been failing for a long time. It is used by the SyncManager and the StatusBar service.
1220 * @hide
1221 */
1222 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1223 public static final String ACTION_SYNC_STATE_CHANGED
1224 = "android.intent.action.SYNC_STATE_CHANGED";
1225 /**
1226 * Broadcast Action: This is broadcast once, after the system has finished
1227 * booting. It can be used to perform application-specific initialization,
1228 * such as installing alarms. You must hold the
1229 * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
1230 * in order to receive this broadcast.
Tom Taylord4a47292009-12-21 13:59:18 -08001231 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001232 * <p class="note">This is a protected intent that can only be sent
1233 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001234 */
1235 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1236 public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
1237 /**
1238 * Broadcast Action: This is broadcast when a user action should request a
1239 * temporary system dialog to dismiss. Some examples of temporary system
1240 * dialogs are the notification window-shade and the recent tasks dialog.
1241 */
1242 public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
1243 /**
1244 * Broadcast Action: Trigger the download and eventual installation
1245 * of a package.
1246 * <p>Input: {@link #getData} is the URI of the package file to download.
Tom Taylord4a47292009-12-21 13:59:18 -08001247 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001248 * <p class="note">This is a protected intent that can only be sent
1249 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001250 */
1251 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1252 public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
1253 /**
1254 * Broadcast Action: A new application package has been installed on the
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001255 * device. The data contains the name of the package. Note that the
1256 * newly installed package does <em>not</em> receive this broadcast.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 * <p>My include the following extras:
1258 * <ul>
1259 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1260 * <li> {@link #EXTRA_REPLACING} is set to true if this is following
1261 * an {@link #ACTION_PACKAGE_REMOVED} broadcast for the same package.
1262 * </ul>
Tom Taylord4a47292009-12-21 13:59:18 -08001263 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001264 * <p class="note">This is a protected intent that can only be sent
1265 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001266 */
1267 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1268 public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
1269 /**
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001270 * Broadcast Action: A new version of an application package has been
1271 * installed, replacing an existing version that was previously installed.
1272 * The data contains the name of the package.
1273 * <p>My include the following extras:
1274 * <ul>
1275 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1276 * </ul>
Tom Taylord4a47292009-12-21 13:59:18 -08001277 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001278 * <p class="note">This is a protected intent that can only be sent
1279 * by the system.
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001280 */
1281 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1282 public static final String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
1283 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001284 * Broadcast Action: An existing application package has been removed from
1285 * the device. The data contains the name of the package. The package
1286 * that is being installed does <em>not</em> receive this Intent.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 * <ul>
1288 * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1289 * to the package.
1290 * <li> {@link #EXTRA_DATA_REMOVED} is set to true if the entire
1291 * application -- data and code -- is being removed.
1292 * <li> {@link #EXTRA_REPLACING} is set to true if this will be followed
1293 * by an {@link #ACTION_PACKAGE_ADDED} broadcast for the same package.
1294 * </ul>
Tom Taylord4a47292009-12-21 13:59:18 -08001295 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001296 * <p class="note">This is a protected intent that can only be sent
1297 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001298 */
1299 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1300 public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
1301 /**
Dianne Hackborn86a72da2009-11-11 20:12:41 -08001302 * Broadcast Action: An existing application package has been changed (e.g.
1303 * a component has been enabled or disabled). The data contains the name of
1304 * the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 * <ul>
1306 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
Dianne Hackborn86a72da2009-11-11 20:12:41 -08001307 * <li> {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST} containing the class name
1308 * of the changed components.
1309 * <li> {@link #EXTRA_DONT_KILL_APP} containing boolean field to override the
1310 * default action of restarting the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 * </ul>
Tom Taylord4a47292009-12-21 13:59:18 -08001312 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001313 * <p class="note">This is a protected intent that can only be sent
1314 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001315 */
1316 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1317 public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
1318 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 * Broadcast Action: The user has restarted a package, and all of its
1320 * processes have been killed. All runtime state
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001321 * associated with it (processes, alarms, notifications, etc) should
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001322 * be removed. Note that the restarted package does <em>not</em>
1323 * receive this broadcast.
1324 * The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 * <ul>
1326 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1327 * </ul>
Tom Taylord4a47292009-12-21 13:59:18 -08001328 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001329 * <p class="note">This is a protected intent that can only be sent
1330 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001331 */
1332 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1333 public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
1334 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 * Broadcast Action: The user has cleared the data of a package. This should
1336 * be preceded by {@link #ACTION_PACKAGE_RESTARTED}, after which all of
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001337 * its persistent data is erased and this broadcast sent.
1338 * Note that the cleared package does <em>not</em>
1339 * receive this broadcast. The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 * <ul>
1341 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1342 * </ul>
Tom Taylord4a47292009-12-21 13:59:18 -08001343 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001344 * <p class="note">This is a protected intent that can only be sent
1345 * by the system.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 */
1347 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1348 public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
1349 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001350 * Broadcast Action: A user ID has been removed from the system. The user
1351 * ID number is stored in the extra data under {@link #EXTRA_UID}.
Tom Taylord4a47292009-12-21 13:59:18 -08001352 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001353 * <p class="note">This is a protected intent that can only be sent
1354 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001355 */
1356 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1357 public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001358
1359 /**
1360 * Broadcast Action: Resources for a set of packages (which were
1361 * previously unavailable) are currently
1362 * available since the media on which they exist is available.
1363 * The extra data {@link #EXTRA_CHANGED_PACKAGE_LIST} contains a
1364 * list of packages whose availability changed.
1365 * The extra data {@link #EXTRA_CHANGED_UID_LIST} contains a
1366 * list of uids of packages whose availability changed.
1367 * Note that the
1368 * packages in this list do <em>not</em> receive this broadcast.
1369 * The specified set of packages are now available on the system.
1370 * <p>Includes the following extras:
1371 * <ul>
1372 * <li> {@link #EXTRA_CHANGED_PACKAGE_LIST} is the set of packages
1373 * whose resources(were previously unavailable) are currently available.
1374 * {@link #EXTRA_CHANGED_UID_LIST} is the set of uids of the
1375 * packages whose resources(were previously unavailable)
1376 * are currently available.
1377 * </ul>
1378 *
1379 * <p class="note">This is a protected intent that can only be sent
1380 * by the system.
1381 * @hide
1382 */
1383 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1384 public static final String ACTION_MEDIA_RESOURCES_AVAILABLE =
1385 "android.intent.action.MEDIA_RESOURCES_AVAILABILE";
1386
1387 /**
1388 * Broadcast Action: Resources for a set of packages are currently
1389 * unavailable since the media on which they exist is unavailable.
1390 * The extra data {@link #EXTRA_CHANGED_PACKAGE_LIST} contains a
1391 * list of packages whose availability changed.
1392 * The extra data {@link #EXTRA_CHANGED_UID_LIST} contains a
1393 * list of uids of packages whose availability changed.
1394 * The specified set of packages can no longer be
1395 * launched and are practically unavailable on the system.
1396 * <p>Inclues the following extras:
1397 * <ul>
1398 * <li> {@link #EXTRA_CHANGED_PACKAGE_LIST} is the set of packages
1399 * whose resources are no longer available.
1400 * {@link #EXTRA_CHANGED_UID_LIST} is the set of packages
1401 * whose resources are no longer available.
1402 * </ul>
1403 *
1404 * <p class="note">This is a protected intent that can only be sent
1405 * by the system.
1406 * @hide
1407 */
1408 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1409 public static final String ACTION_MEDIA_RESOURCES_UNAVAILABLE =
1410 "android.intent.action.MEDIA_RESOURCES_UNAVAILABILE";
1411
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001412 /**
1413 * Broadcast Action: The current system wallpaper has changed. See
Scott Main8b2e0002009-09-29 18:17:31 -07001414 * {@link android.app.WallpaperManager} for retrieving the new wallpaper.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001415 */
1416 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1417 public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
1418 /**
1419 * Broadcast Action: The current device {@link android.content.res.Configuration}
1420 * (orientation, locale, etc) has changed. When such a change happens, the
1421 * UIs (view hierarchy) will need to be rebuilt based on this new
1422 * information; for the most part, applications don't need to worry about
1423 * this, because the system will take care of stopping and restarting the
1424 * application to make sure it sees the new changes. Some system code that
1425 * can not be restarted will need to watch for this action and handle it
1426 * appropriately.
Tom Taylord4a47292009-12-21 13:59:18 -08001427 *
Dianne Hackborn362d5b92009-11-11 18:04:39 -08001428 * <p class="note">
1429 * You can <em>not</em> receive this through components declared
1430 * in manifests, only by explicitly registering for it with
1431 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1432 * Context.registerReceiver()}.
Tom Taylord4a47292009-12-21 13:59:18 -08001433 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001434 * <p class="note">This is a protected intent that can only be sent
1435 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001436 *
1437 * @see android.content.res.Configuration
1438 */
1439 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1440 public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
1441 /**
Dianne Hackborn362d5b92009-11-11 18:04:39 -08001442 * Broadcast Action: The current device's locale has changed.
Tom Taylord4a47292009-12-21 13:59:18 -08001443 *
Dianne Hackborn362d5b92009-11-11 18:04:39 -08001444 * <p class="note">This is a protected intent that can only be sent
1445 * by the system.
1446 */
1447 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1448 public static final String ACTION_LOCALE_CHANGED = "android.intent.action.LOCALE_CHANGED";
1449 /**
Dianne Hackbornedd93162009-09-19 14:03:05 -07001450 * Broadcast Action: This is a <em>sticky broadcast</em> containing the
1451 * charging state, level, and other information about the battery.
1452 * See {@link android.os.BatteryManager} for documentation on the
1453 * contents of the Intent.
The Android Open Source Project10592532009-03-18 17:39:46 -07001454 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001455 * <p class="note">
1456 * You can <em>not</em> receive this through components declared
Dianne Hackborn854060af2009-07-09 18:14:31 -07001457 * in manifests, only by explicitly registering for it with
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001458 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
Dianne Hackbornedd93162009-09-19 14:03:05 -07001459 * Context.registerReceiver()}. See {@link #ACTION_BATTERY_LOW},
1460 * {@link #ACTION_BATTERY_OKAY}, {@link #ACTION_POWER_CONNECTED},
1461 * and {@link #ACTION_POWER_DISCONNECTED} for distinct battery-related
1462 * broadcasts that are sent and can be received through manifest
1463 * receivers.
Tom Taylord4a47292009-12-21 13:59:18 -08001464 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001465 * <p class="note">This is a protected intent that can only be sent
1466 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001467 */
1468 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1469 public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
1470 /**
1471 * Broadcast Action: Indicates low battery condition on the device.
1472 * This broadcast corresponds to the "Low battery warning" system dialog.
Tom Taylord4a47292009-12-21 13:59:18 -08001473 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001474 * <p class="note">This is a protected intent that can only be sent
1475 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001476 */
1477 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1478 public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
1479 /**
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001480 * Broadcast Action: Indicates the battery is now okay after being low.
1481 * This will be sent after {@link #ACTION_BATTERY_LOW} once the battery has
1482 * gone back up to an okay state.
Tom Taylord4a47292009-12-21 13:59:18 -08001483 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001484 * <p class="note">This is a protected intent that can only be sent
1485 * by the system.
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001486 */
1487 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1488 public static final String ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";
1489 /**
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001490 * Broadcast Action: External power has been connected to the device.
1491 * This is intended for applications that wish to register specifically to this notification.
1492 * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1493 * stay active to receive this notification. This action can be used to implement actions
1494 * that wait until power is available to trigger.
Tom Taylord4a47292009-12-21 13:59:18 -08001495 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001496 * <p class="note">This is a protected intent that can only be sent
1497 * by the system.
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001498 */
1499 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001500 public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001501 /**
1502 * Broadcast Action: External power has been removed from the device.
1503 * This is intended for applications that wish to register specifically to this notification.
1504 * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1505 * stay active to receive this notification. This action can be used to implement actions
Romain Guy4969af72009-06-17 10:53:19 -07001506 * that wait until power is available to trigger.
Tom Taylord4a47292009-12-21 13:59:18 -08001507 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001508 * <p class="note">This is a protected intent that can only be sent
1509 * by the system.
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001510 */
1511 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jean-Baptiste Queru1ef45642008-10-24 11:49:25 -07001512 public static final String ACTION_POWER_DISCONNECTED =
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001513 "android.intent.action.ACTION_POWER_DISCONNECTED";
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001514 /**
Dianne Hackborn55280a92009-05-07 15:53:46 -07001515 * Broadcast Action: Device is shutting down.
1516 * This is broadcast when the device is being shut down (completely turned
1517 * off, not sleeping). Once the broadcast is complete, the final shutdown
1518 * will proceed and all unsaved data lost. Apps will not normally need
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001519 * to handle this, since the foreground activity will be paused as well.
Tom Taylord4a47292009-12-21 13:59:18 -08001520 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001521 * <p class="note">This is a protected intent that can only be sent
1522 * by the system.
Dianne Hackborn55280a92009-05-07 15:53:46 -07001523 */
1524 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Romain Guy4969af72009-06-17 10:53:19 -07001525 public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
Dianne Hackborn55280a92009-05-07 15:53:46 -07001526 /**
Mike Lockwoodbad80e02009-07-30 01:21:08 -07001527 * Activity Action: Start this activity to request system shutdown.
1528 * The optional boolean extra field {@link #EXTRA_KEY_CONFIRM} can be set to true
1529 * to request confirmation from the user before shutting down.
1530 *
1531 * <p class="note">This is a protected intent that can only be sent
1532 * by the system.
1533 *
1534 * {@hide}
1535 */
1536 public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
1537 /**
Dianne Hackbornedd93162009-09-19 14:03:05 -07001538 * Broadcast Action: A sticky broadcast that indicates low memory
1539 * condition on the device
Tom Taylord4a47292009-12-21 13:59:18 -08001540 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001541 * <p class="note">This is a protected intent that can only be sent
1542 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001543 */
1544 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1545 public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
1546 /**
1547 * Broadcast Action: Indicates low memory condition on the device no longer exists
Tom Taylord4a47292009-12-21 13:59:18 -08001548 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001549 * <p class="note">This is a protected intent that can only be sent
1550 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001551 */
1552 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1553 public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
1554 /**
1555 * Broadcast Action: Indicates low memory condition notification acknowledged by user
1556 * and package management should be started.
1557 * This is triggered by the user from the ACTION_DEVICE_STORAGE_LOW
1558 * notification.
1559 */
1560 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1561 public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
1562 /**
1563 * Broadcast Action: The device has entered USB Mass Storage mode.
1564 * This is used mainly for the USB Settings panel.
1565 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1566 * when the SD card file system is mounted or unmounted
1567 */
1568 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1569 public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
1570
1571 /**
1572 * Broadcast Action: The device has exited USB Mass Storage mode.
1573 * This is used mainly for the USB Settings panel.
1574 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1575 * when the SD card file system is mounted or unmounted
1576 */
1577 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1578 public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
1579
1580 /**
1581 * Broadcast Action: External media has been removed.
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_REMOVED = "android.intent.action.MEDIA_REMOVED";
1586
1587 /**
1588 * Broadcast Action: External media is present, but not mounted at its mount point.
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_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
1593
1594 /**
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08001595 * Broadcast Action: External media is present, and being disk-checked
1596 * 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 -08001597 */
1598 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1599 public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
1600
1601 /**
1602 * Broadcast Action: External media is present, but is using an incompatible fs (or is blank)
1603 * 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 -08001604 */
1605 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1606 public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
1607
1608 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001609 * Broadcast Action: External media is present and mounted at its mount point.
1610 * The path to the mount point for the removed media is contained in the Intent.mData field.
1611 * The Intent contains an extra with name "read-only" and Boolean value to indicate if the
1612 * media was mounted read only.
1613 */
1614 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1615 public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
1616
1617 /**
1618 * Broadcast Action: External media is unmounted because it is being shared via USB mass storage.
1619 * The path to the mount point for the removed media is contained in the Intent.mData field.
1620 */
1621 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1622 public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
1623
1624 /**
1625 * Broadcast Action: External media was removed from SD card slot, but mount point was not unmounted.
1626 * The path to the mount point for the removed media is contained in the Intent.mData field.
1627 */
1628 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1629 public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
1630
1631 /**
1632 * Broadcast Action: External media is present but cannot be mounted.
1633 * The path to the mount point for the removed media is contained in the Intent.mData field.
1634 */
1635 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1636 public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
1637
1638 /**
1639 * Broadcast Action: User has expressed the desire to remove the external storage media.
1640 * Applications should close all files they have open within the mount point when they receive this intent.
1641 * The path to the mount point for the media to be ejected is contained in the Intent.mData field.
1642 */
1643 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1644 public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
1645
1646 /**
1647 * Broadcast Action: The media scanner has started scanning a directory.
1648 * The path to the directory being scanned is contained in the Intent.mData field.
1649 */
1650 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1651 public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
1652
1653 /**
1654 * Broadcast Action: The media scanner has finished scanning a directory.
1655 * The path to the scanned directory is contained in the Intent.mData field.
1656 */
1657 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1658 public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
1659
1660 /**
1661 * Broadcast Action: Request the media scanner to scan a file and add it to the media database.
1662 * The path to the file is contained in the Intent.mData field.
1663 */
1664 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1665 public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
1666
1667 /**
1668 * Broadcast Action: The "Media Button" was pressed. Includes a single
1669 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1670 * caused the broadcast.
1671 */
1672 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1673 public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
1674
1675 /**
1676 * Broadcast Action: The "Camera Button" was pressed. Includes a single
1677 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1678 * caused the broadcast.
1679 */
1680 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1681 public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
1682
1683 // *** NOTE: @todo(*) The following really should go into a more domain-specific
1684 // location; they are not general-purpose actions.
1685
1686 /**
1687 * Broadcast Action: An GTalk connection has been established.
1688 */
1689 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1690 public static final String ACTION_GTALK_SERVICE_CONNECTED =
1691 "android.intent.action.GTALK_CONNECTED";
1692
1693 /**
1694 * Broadcast Action: An GTalk connection has been disconnected.
1695 */
1696 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1697 public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
1698 "android.intent.action.GTALK_DISCONNECTED";
The Android Open Source Project10592532009-03-18 17:39:46 -07001699
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001700 /**
1701 * Broadcast Action: An input method has been changed.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001702 */
1703 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1704 public static final String ACTION_INPUT_METHOD_CHANGED =
1705 "android.intent.action.INPUT_METHOD_CHANGED";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001706
1707 /**
1708 * <p>Broadcast Action: The user has switched the phone into or out of Airplane Mode. One or
1709 * more radios have been turned off or on. The intent will have the following extra value:</p>
1710 * <ul>
1711 * <li><em>state</em> - A boolean value indicating whether Airplane Mode is on. If true,
1712 * then cell radio and possibly other radios such as bluetooth or WiFi may have also been
1713 * turned off</li>
1714 * </ul>
Tom Taylord4a47292009-12-21 13:59:18 -08001715 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001716 * <p class="note">This is a protected intent that can only be sent
1717 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001718 */
1719 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1720 public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
1721
1722 /**
1723 * Broadcast Action: Some content providers have parts of their namespace
1724 * where they publish new events or items that the user may be especially
1725 * interested in. For these things, they may broadcast this action when the
1726 * set of interesting items change.
1727 *
1728 * For example, GmailProvider sends this notification when the set of unread
1729 * mail in the inbox changes.
1730 *
1731 * <p>The data of the intent identifies which part of which provider
1732 * changed. When queried through the content resolver, the data URI will
1733 * return the data set in question.
1734 *
1735 * <p>The intent will have the following extra values:
1736 * <ul>
1737 * <li><em>count</em> - The number of items in the data set. This is the
1738 * same as the number of items in the cursor returned by querying the
1739 * data URI. </li>
1740 * </ul>
1741 *
1742 * This intent will be sent at boot (if the count is non-zero) and when the
1743 * data set changes. It is possible for the data set to change without the
1744 * count changing (for example, if a new unread message arrives in the same
1745 * sync operation in which a message is archived). The phone should still
1746 * ring/vibrate/etc as normal in this case.
1747 */
1748 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1749 public static final String ACTION_PROVIDER_CHANGED =
1750 "android.intent.action.PROVIDER_CHANGED";
1751
1752 /**
1753 * Broadcast Action: Wired Headset plugged in or unplugged.
1754 *
1755 * <p>The intent will have the following extra values:
1756 * <ul>
1757 * <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
1758 * <li><em>name</em> - Headset type, human readable string </li>
Eric Laurent923d7d72009-11-12 12:09:06 -08001759 * <li><em>microphone</em> - 1 if headset has a microphone, 0 otherwise </li>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001760 * </ul>
1761 * </ul>
1762 */
1763 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1764 public static final String ACTION_HEADSET_PLUG =
1765 "android.intent.action.HEADSET_PLUG";
1766
1767 /**
1768 * Broadcast Action: An outgoing call is about to be placed.
1769 *
1770 * <p>The Intent will have the following extra value:
1771 * <ul>
The Android Open Source Project10592532009-03-18 17:39:46 -07001772 * <li><em>{@link android.content.Intent#EXTRA_PHONE_NUMBER}</em> -
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001773 * the phone number originally intended to be dialed.</li>
1774 * </ul>
1775 * <p>Once the broadcast is finished, the resultData is used as the actual
1776 * number to call. If <code>null</code>, no call will be placed.</p>
The Android Open Source Project10592532009-03-18 17:39:46 -07001777 * <p>It is perfectly acceptable for multiple receivers to process the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001778 * outgoing call in turn: for example, a parental control application
1779 * might verify that the user is authorized to place the call at that
1780 * time, then a number-rewriting application might add an area code if
1781 * one was not specified.</p>
1782 * <p>For consistency, any receiver whose purpose is to prohibit phone
1783 * calls should have a priority of 0, to ensure it will see the final
1784 * phone number to be dialed.
The Android Open Source Project10592532009-03-18 17:39:46 -07001785 * Any receiver whose purpose is to rewrite phone numbers to be called
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001786 * should have a positive priority.
1787 * Negative priorities are reserved for the system for this broadcast;
1788 * using them may cause problems.</p>
1789 * <p>Any BroadcastReceiver receiving this Intent <em>must not</em>
1790 * abort the broadcast.</p>
1791 * <p>Emergency calls cannot be intercepted using this mechanism, and
1792 * other calls cannot be modified to call emergency numbers using this
1793 * mechanism.
The Android Open Source Project10592532009-03-18 17:39:46 -07001794 * <p>You must hold the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001795 * {@link android.Manifest.permission#PROCESS_OUTGOING_CALLS}
1796 * permission to receive this Intent.</p>
Tom Taylord4a47292009-12-21 13:59:18 -08001797 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001798 * <p class="note">This is a protected intent that can only be sent
1799 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001800 */
1801 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1802 public static final String ACTION_NEW_OUTGOING_CALL =
1803 "android.intent.action.NEW_OUTGOING_CALL";
1804
1805 /**
1806 * Broadcast Action: Have the device reboot. This is only for use by
1807 * system code.
Tom Taylord4a47292009-12-21 13:59:18 -08001808 *
Dianne Hackborn854060af2009-07-09 18:14:31 -07001809 * <p class="note">This is a protected intent that can only be sent
1810 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001811 */
1812 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1813 public static final String ACTION_REBOOT =
1814 "android.intent.action.REBOOT";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815
Wei Huang97ecc9c2009-05-11 17:44:20 -07001816 /**
Dianne Hackbornedd93162009-09-19 14:03:05 -07001817 * Broadcast Action: A sticky broadcast indicating the phone was docked
1818 * or undocked. Includes the extra
1819 * field {@link #EXTRA_DOCK_STATE}, containing the current dock state.
1820 * This is intended for monitoring the current dock state.
1821 * To launch an activity from a dock state change, use {@link #CATEGORY_CAR_DOCK}
1822 * or {@link #CATEGORY_DESK_DOCK} instead.
1823 */
1824 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1825 public static final String ACTION_DOCK_EVENT =
1826 "android.intent.action.DOCK_EVENT";
1827
1828 /**
Wei Huang97ecc9c2009-05-11 17:44:20 -07001829 * Broadcast Action: a remote intent is to be broadcasted.
1830 *
1831 * A remote intent is used for remote RPC between devices. The remote intent
1832 * is serialized and sent from one device to another device. The receiving
1833 * device parses the remote intent and broadcasts it. Note that anyone can
1834 * broadcast a remote intent. However, if the intent receiver of the remote intent
1835 * does not trust intent broadcasts from arbitrary intent senders, it should require
1836 * the sender to hold certain permissions so only trusted sender's broadcast will be
1837 * let through.
Dianne Hackbornedd93162009-09-19 14:03:05 -07001838 * @hide
Wei Huang97ecc9c2009-05-11 17:44:20 -07001839 */
1840 public static final String ACTION_REMOTE_INTENT =
1841 "android.intent.action.REMOTE_INTENT";
1842
Dianne Hackborn9acc0302009-08-25 00:27:12 -07001843 /**
1844 * Broadcast Action: hook for permforming cleanup after a system update.
1845 *
1846 * The broadcast is sent when the system is booting, before the
1847 * BOOT_COMPLETED broadcast. It is only sent to receivers in the system
1848 * image. A receiver for this should do its work and then disable itself
1849 * so that it does not get run again at the next boot.
1850 * @hide
1851 */
1852 public static final String ACTION_PRE_BOOT_COMPLETED =
1853 "android.intent.action.PRE_BOOT_COMPLETED";
1854
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001855 // ---------------------------------------------------------------------
1856 // ---------------------------------------------------------------------
1857 // Standard intent categories (see addCategory()).
1858
1859 /**
1860 * Set if the activity should be an option for the default action
1861 * (center press) to perform on a piece of data. Setting this will
1862 * hide from the user any activities without it set when performing an
1863 * action on some data. Note that this is normal -not- set in the
1864 * Intent when initiating an action -- it is for use in intent filters
1865 * specified in packages.
1866 */
1867 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1868 public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
1869 /**
1870 * Activities that can be safely invoked from a browser must support this
1871 * category. For example, if the user is viewing a web page or an e-mail
1872 * and clicks on a link in the text, the Intent generated execute that
1873 * link will require the BROWSABLE category, so that only activities
1874 * supporting this category will be considered as possible actions. By
1875 * supporting this category, you are promising that there is nothing
1876 * damaging (without user intervention) that can happen by invoking any
1877 * matching Intent.
1878 */
1879 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1880 public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
1881 /**
1882 * Set if the activity should be considered as an alternative action to
1883 * the data the user is currently viewing. See also
1884 * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
1885 * applies to the selection in a list of items.
1886 *
1887 * <p>Supporting this category means that you would like your activity to be
1888 * displayed in the set of alternative things the user can do, usually as
1889 * part of the current activity's options menu. You will usually want to
1890 * include a specific label in the &lt;intent-filter&gt; of this action
1891 * describing to the user what it does.
1892 *
1893 * <p>The action of IntentFilter with this category is important in that it
1894 * describes the specific action the target will perform. This generally
1895 * should not be a generic action (such as {@link #ACTION_VIEW}, but rather
1896 * a specific name such as "com.android.camera.action.CROP. Only one
1897 * alternative of any particular action will be shown to the user, so using
1898 * a specific action like this makes sure that your alternative will be
1899 * displayed while also allowing other applications to provide their own
1900 * overrides of that particular action.
1901 */
1902 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1903 public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
1904 /**
1905 * Set if the activity should be considered as an alternative selection
1906 * action to the data the user has currently selected. This is like
1907 * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list
1908 * of items from which the user can select, giving them alternatives to the
1909 * default action that will be performed on it.
1910 */
1911 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1912 public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
1913 /**
1914 * Intended to be used as a tab inside of an containing TabActivity.
1915 */
1916 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1917 public static final String CATEGORY_TAB = "android.intent.category.TAB";
1918 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001919 * Should be displayed in the top-level launcher.
1920 */
1921 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1922 public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
1923 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 * Provides information about the package it is in; typically used if
1925 * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
1926 * a front-door to the user without having to be shown in the all apps list.
1927 */
1928 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1929 public static final String CATEGORY_INFO = "android.intent.category.INFO";
1930 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001931 * This is the home activity, that is the first activity that is displayed
1932 * when the device boots.
1933 */
1934 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1935 public static final String CATEGORY_HOME = "android.intent.category.HOME";
1936 /**
1937 * This activity is a preference panel.
1938 */
1939 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1940 public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
1941 /**
1942 * This activity is a development preference panel.
1943 */
1944 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1945 public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
1946 /**
1947 * Capable of running inside a parent activity container.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001948 */
1949 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1950 public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
1951 /**
1952 * This activity may be exercised by the monkey or other automated test tools.
1953 */
1954 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1955 public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
1956 /**
1957 * To be used as a test (not part of the normal user experience).
1958 */
1959 public static final String CATEGORY_TEST = "android.intent.category.TEST";
1960 /**
1961 * To be used as a unit test (run through the Test Harness).
1962 */
1963 public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
1964 /**
1965 * To be used as an sample code example (not part of the normal user
1966 * experience).
1967 */
1968 public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
1969 /**
1970 * Used to indicate that a GET_CONTENT intent only wants URIs that can be opened with
1971 * ContentResolver.openInputStream. Openable URIs must support the columns in OpenableColumns
1972 * when queried, though it is allowable for those columns to be blank.
1973 */
1974 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1975 public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
1976
1977 /**
1978 * To be used as code under test for framework instrumentation tests.
1979 */
1980 public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
1981 "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
Mike Lockwood9092ab42009-09-16 13:01:32 -04001982 /**
1983 * An activity to run when device is inserted into a car dock.
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001984 * Used with {@link #ACTION_MAIN} to launch an activity.
Mike Lockwood9092ab42009-09-16 13:01:32 -04001985 * To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
1986 */
1987 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1988 public static final String CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
1989 /**
1990 * An activity to run when device is inserted into a car dock.
1991 * Used with {@link #ACTION_MAIN} to launch an activity.
1992 * To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
1993 */
1994 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1995 public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05001996
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001997 // ---------------------------------------------------------------------
1998 // ---------------------------------------------------------------------
1999 // Standard extra data keys.
2000
2001 /**
2002 * The initial data to place in a newly created record. Use with
2003 * {@link #ACTION_INSERT}. The data here is a Map containing the same
2004 * fields as would be given to the underlying ContentProvider.insert()
2005 * call.
2006 */
2007 public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
2008
2009 /**
2010 * A constant CharSequence that is associated with the Intent, used with
2011 * {@link #ACTION_SEND} to supply the literal data to be sent. Note that
2012 * this may be a styled CharSequence, so you must use
2013 * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to
2014 * retrieve it.
2015 */
2016 public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
2017
2018 /**
2019 * A content: URI holding a stream of data associated with the Intent,
2020 * used with {@link #ACTION_SEND} to supply the data being sent.
2021 */
2022 public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
2023
2024 /**
2025 * A String[] holding e-mail addresses that should be delivered to.
2026 */
2027 public static final String EXTRA_EMAIL = "android.intent.extra.EMAIL";
2028
2029 /**
2030 * A String[] holding e-mail addresses that should be carbon copied.
2031 */
2032 public static final String EXTRA_CC = "android.intent.extra.CC";
2033
2034 /**
2035 * A String[] holding e-mail addresses that should be blind carbon copied.
2036 */
2037 public static final String EXTRA_BCC = "android.intent.extra.BCC";
2038
2039 /**
2040 * A constant string holding the desired subject line of a message.
2041 */
2042 public static final String EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
2043
2044 /**
2045 * An Intent describing the choices you would like shown with
2046 * {@link #ACTION_PICK_ACTIVITY}.
2047 */
2048 public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
2049
2050 /**
2051 * A CharSequence dialog title to provide to the user when used with a
2052 * {@link #ACTION_CHOOSER}.
2053 */
2054 public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
2055
2056 /**
Dianne Hackborneb034652009-09-07 00:49:58 -07002057 * A Parcelable[] of {@link Intent} or
2058 * {@link android.content.pm.LabeledIntent} objects as set with
2059 * {@link #putExtra(String, Parcelable[])} of additional activities to place
2060 * a the front of the list of choices, when shown to the user with a
2061 * {@link #ACTION_CHOOSER}.
2062 */
2063 public static final String EXTRA_INITIAL_INTENTS = "android.intent.extra.INITIAL_INTENTS";
2064
2065 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002066 * A {@link android.view.KeyEvent} object containing the event that
2067 * triggered the creation of the Intent it is in.
2068 */
2069 public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
2070
2071 /**
Mike Lockwoodbad80e02009-07-30 01:21:08 -07002072 * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to request confirmation from the user
2073 * before shutting down.
2074 *
2075 * {@hide}
2076 */
2077 public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";
2078
2079 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002080 * Used as an boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
2081 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
2082 * of restarting the application.
2083 */
2084 public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
2085
2086 /**
2087 * A String holding the phone number originally entered in
2088 * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual
2089 * number to call in a {@link android.content.Intent#ACTION_CALL}.
2090 */
2091 public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
2092 /**
2093 * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED}
2094 * intents to supply the uid the package had been assigned. Also an optional
2095 * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
2096 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same
2097 * purpose.
2098 */
2099 public static final String EXTRA_UID = "android.intent.extra.UID";
2100
2101 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
2103 * intents to indicate whether this represents a full uninstall (removing
2104 * both the code and its data) or a partial uninstall (leaving its data,
2105 * implying that this is an update).
2106 */
2107 public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
The Android Open Source Project10592532009-03-18 17:39:46 -07002108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 /**
2110 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
2111 * intents to indicate that this is a replacement of the package, so this
2112 * broadcast will immediately be followed by an add broadcast for a
2113 * different version of the same package.
2114 */
2115 public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
The Android Open Source Project10592532009-03-18 17:39:46 -07002116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002118 * Used as an int extra field in {@link android.app.AlarmManager} intents
2119 * to tell the application being invoked how many pending alarms are being
2120 * delievered with the intent. For one-shot alarms this will always be 1.
2121 * For recurring alarms, this might be greater than 1 if the device was
2122 * asleep or powered off at the time an earlier alarm would have been
2123 * delivered.
2124 */
2125 public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
Romain Guy4969af72009-06-17 10:53:19 -07002126
Jacek Surazski86b6c532009-05-13 14:38:28 +02002127 /**
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002128 * Used as an int extra field in {@link android.content.Intent#ACTION_DOCK_EVENT}
2129 * intents to request the dock state. Possible values are
Mike Lockwood725fcbf2009-08-24 13:09:20 -07002130 * {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
2131 * {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
2132 * {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002133 */
2134 public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
2135
2136 /**
2137 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2138 * to represent that the phone is not in any dock.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002139 */
2140 public static final int EXTRA_DOCK_STATE_UNDOCKED = 0;
2141
2142 /**
2143 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2144 * to represent that the phone is in a desk dock.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002145 */
2146 public static final int EXTRA_DOCK_STATE_DESK = 1;
2147
2148 /**
2149 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2150 * to represent that the phone is in a car dock.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05002151 */
2152 public static final int EXTRA_DOCK_STATE_CAR = 2;
2153
2154 /**
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002155 * Boolean that can be supplied as meta-data with a dock activity, to
2156 * indicate that the dock should take over the home key when it is active.
2157 */
2158 public static final String METADATA_DOCK_HOME = "android.dock_home";
Tom Taylord4a47292009-12-21 13:59:18 -08002159
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002160 /**
Jacek Surazski86b6c532009-05-13 14:38:28 +02002161 * Used as a parcelable extra field in {@link #ACTION_APP_ERROR}, containing
2162 * the bug report.
Romain Guy4969af72009-06-17 10:53:19 -07002163 *
Jacek Surazski86b6c532009-05-13 14:38:28 +02002164 * @hide
2165 */
2166 public static final String EXTRA_BUG_REPORT = "android.intent.extra.BUG_REPORT";
2167
2168 /**
Romain Guy4969af72009-06-17 10:53:19 -07002169 * Used as a string extra field when sending an intent to PackageInstaller to install a
Jacek Surazski86b6c532009-05-13 14:38:28 +02002170 * package. Specifies the installer package name; this package will receive the
2171 * {@link #ACTION_APP_ERROR} intent.
Romain Guy4969af72009-06-17 10:53:19 -07002172 *
Jacek Surazski86b6c532009-05-13 14:38:28 +02002173 * @hide
2174 */
Romain Guy4969af72009-06-17 10:53:19 -07002175 public static final String EXTRA_INSTALLER_PACKAGE_NAME
Jacek Surazski86b6c532009-05-13 14:38:28 +02002176 = "android.intent.extra.INSTALLER_PACKAGE_NAME";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002177
Wei Huang97ecc9c2009-05-11 17:44:20 -07002178 /**
2179 * Used in the extra field in the remote intent. It's astring token passed with the
2180 * remote intent.
2181 */
2182 public static final String EXTRA_REMOTE_INTENT_TOKEN =
2183 "android.intent.extra.remote_intent_token";
2184
Suchi Amalapurapu0214e942009-09-02 11:03:18 -07002185 /**
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08002186 * @deprecated See {@link #EXTRA_CHANGED_COMPONENT_NAME_LIST}; this field
Dianne Hackborn86a72da2009-11-11 20:12:41 -08002187 * will contain only the first name in the list.
Suchi Amalapurapu0214e942009-09-02 11:03:18 -07002188 */
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08002189 @Deprecated public static final String EXTRA_CHANGED_COMPONENT_NAME =
Suchi Amalapurapu0214e942009-09-02 11:03:18 -07002190 "android.intent.extra.changed_component_name";
2191
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002192 /**
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08002193 * This field is part of {@link android.content.Intent#ACTION_PACKAGE_CHANGED},
Dianne Hackborn86a72da2009-11-11 20:12:41 -08002194 * and contains a string array of all of the components that have changed.
2195 */
2196 public static final String EXTRA_CHANGED_COMPONENT_NAME_LIST =
2197 "android.intent.extra.changed_component_name_list";
2198
2199 /**
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08002200 * This field is part of
2201 * {@link android.content.Intent#ACTION_MEDIA_RESOURCES_AVAILABLE},
2202 * {@link android.content.Intent#ACTION_MEDIA_RESOURCES_UNAVAILABLE}
2203 * and contains a string array of all of the components that have changed.
2204 * @hide
2205 */
2206 public static final String EXTRA_CHANGED_PACKAGE_LIST =
2207 "android.intent.extra.changed_package_list";
2208
2209 /**
2210 * This field is part of
2211 * {@link android.content.Intent#ACTION_MEDIA_RESOURCES_AVAILABLE},
2212 * {@link android.content.Intent#ACTION_MEDIA_RESOURCES_UNAVAILABLE}
2213 * and contains an integer array of uids of all of the components
2214 * that have changed.
2215 * @hide
2216 */
2217 public static final String EXTRA_CHANGED_UID_LIST =
2218 "android.intent.extra.changed_uid_list";
2219
2220 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002221 * @hide
2222 * Magic extra system code can use when binding, to give a label for
2223 * who it is that has bound to a service. This is an integer giving
2224 * a framework string resource that can be displayed to the user.
2225 */
2226 public static final String EXTRA_CLIENT_LABEL =
2227 "android.intent.extra.client_label";
2228
2229 /**
2230 * @hide
2231 * Magic extra system code can use when binding, to give a PendingIntent object
2232 * that can be launched for the user to disable the system's use of this
2233 * service.
2234 */
2235 public static final String EXTRA_CLIENT_INTENT =
2236 "android.intent.extra.client_intent";
2237
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002238 // ---------------------------------------------------------------------
2239 // ---------------------------------------------------------------------
2240 // Intent flags (see mFlags variable).
2241
2242 /**
2243 * If set, the recipient of this Intent will be granted permission to
2244 * perform read operations on the Uri in the Intent's data.
2245 */
2246 public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
2247 /**
2248 * If set, the recipient of this Intent will be granted permission to
2249 * perform write operations on the Uri in the Intent's data.
2250 */
2251 public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
2252 /**
2253 * Can be set by the caller to indicate that this Intent is coming from
2254 * a background operation, not from direct user interaction.
2255 */
2256 public static final int FLAG_FROM_BACKGROUND = 0x00000004;
2257 /**
2258 * A flag you can enable for debugging: when set, log messages will be
2259 * printed during the resolution of this intent to show you what has
2260 * been found to create the final resolved list.
2261 */
2262 public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
2263
2264 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002265 * If set, the new activity is not kept in the history stack. As soon as
2266 * the user navigates away from it, the activity is finished. This may also
2267 * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
2268 * noHistory} attribute.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002269 */
2270 public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
2271 /**
2272 * If set, the activity will not be launched if it is already running
2273 * at the top of the history stack.
2274 */
2275 public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
2276 /**
2277 * If set, this activity will become the start of a new task on this
2278 * history stack. A task (from the activity that started it to the
2279 * next task activity) defines an atomic group of activities that the
2280 * user can move to. Tasks can be moved to the foreground and background;
2281 * all of the activities inside of a particular task always remain in
The Android Open Source Project10592532009-03-18 17:39:46 -07002282 * the same order. See
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 * <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 * <p>This flag is generally used by activities that want
2287 * to present a "launcher" style behavior: they give the user a list of
2288 * separate things that can be done, which otherwise run completely
2289 * independently of the activity launching them.
2290 *
2291 * <p>When using this flag, if a task is already running for the activity
2292 * you are now starting, then a new activity will not be started; instead,
2293 * the current task will simply be brought to the front of the screen with
2294 * the state it was last in. See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
2295 * to disable this behavior.
2296 *
2297 * <p>This flag can not be used when the caller is requesting a result from
2298 * the activity being launched.
2299 */
2300 public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
2301 /**
2302 * <strong>Do not use this flag unless you are implementing your own
2303 * top-level application launcher.</strong> Used in conjunction with
2304 * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the
2305 * behavior of bringing an existing task to the foreground. When set,
2306 * a new task is <em>always</em> started to host the Activity for the
2307 * Intent, regardless of whether there is already an existing task running
2308 * the same thing.
2309 *
2310 * <p><strong>Because the default system does not include graphical task management,
2311 * you should not use this flag unless you provide some way for a user to
2312 * return back to the tasks you have launched.</strong>
The Android Open Source Project10592532009-03-18 17:39:46 -07002313 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002314 * <p>This flag is ignored if
2315 * {@link #FLAG_ACTIVITY_NEW_TASK} is not set.
2316 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2318 * Activities and Tasks</a> for more details on tasks.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002319 */
2320 public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
2321 /**
2322 * If set, and the activity being launched is already running in the
2323 * current task, then instead of launching a new instance of that activity,
2324 * all of the other activities on top of it will be closed and this Intent
2325 * will be delivered to the (now on top) old activity as a new Intent.
2326 *
2327 * <p>For example, consider a task consisting of the activities: A, B, C, D.
2328 * If D calls startActivity() with an Intent that resolves to the component
2329 * of activity B, then C and D will be finished and B receive the given
2330 * Intent, resulting in the stack now being: A, B.
2331 *
Dianne Hackbornaa52f9a2009-08-25 16:01:15 -07002332 * <p>The currently running instance of activity B in the above example will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002333 * either receive the new intent you are starting here in its
2334 * onNewIntent() method, or be itself finished and restarted with the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002335 * new intent. If it has declared its launch mode to be "multiple" (the
Dianne Hackbornaa52f9a2009-08-25 16:01:15 -07002336 * default) and you have not set {@link #FLAG_ACTIVITY_SINGLE_TOP} in
2337 * the same intent, then it will be finished and re-created; for all other
2338 * launch modes or if {@link #FLAG_ACTIVITY_SINGLE_TOP} is set then this
2339 * Intent will be delivered to the current instance's onNewIntent().
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002340 *
2341 * <p>This launch mode can also be used to good effect in conjunction with
2342 * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity
2343 * of a task, it will bring any currently running instance of that task
2344 * to the foreground, and then clear it to its root state. This is
2345 * especially useful, for example, when launching an activity from the
2346 * notification manager.
2347 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2349 * Activities and Tasks</a> for more details on tasks.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002350 */
2351 public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
2352 /**
2353 * If set and this intent is being used to launch a new activity from an
2354 * existing one, then the reply target of the existing activity will be
2355 * transfered to the new activity. This way the new activity can call
2356 * {@link android.app.Activity#setResult} and have that result sent back to
2357 * the reply target of the original activity.
2358 */
2359 public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
2360 /**
2361 * If set and this intent is being used to launch a new activity from an
2362 * existing one, the current activity will not be counted as the top
2363 * activity for deciding whether the new intent should be delivered to
2364 * the top instead of starting a new one. The previous activity will
2365 * be used as the top, with the assumption being that the current activity
2366 * will finish itself immediately.
2367 */
2368 public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
2369 /**
2370 * If set, the new activity is not kept in the list of recently launched
2371 * activities.
2372 */
2373 public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
2374 /**
2375 * This flag is not normally set by application code, but set for you by
2376 * the system as described in the
2377 * {@link android.R.styleable#AndroidManifestActivity_launchMode
2378 * launchMode} documentation for the singleTask mode.
2379 */
2380 public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
2381 /**
2382 * If set, and this activity is either being started in a new task or
2383 * bringing to the top an existing task, then it will be launched as
2384 * the front door of the task. This will result in the application of
2385 * any affinities needed to have that task in the proper state (either
2386 * moving activities to or from it), or simply resetting that task to
2387 * its initial state if needed.
2388 */
2389 public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
2390 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002391 * This flag is not normally set by application code, but set for you by
2392 * the system if this activity is being launched from history
2393 * (longpress home key).
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002394 */
2395 public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002396 /**
2397 * If set, this marks a point in the task's activity stack that should
2398 * be cleared when the task is reset. That is, the next time the task
Marco Nelissenc53fc4e2009-05-11 12:15:31 -07002399 * is brought to the foreground with
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002400 * {@link #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED} (typically as a result of
2401 * the user re-launching it from home), this activity and all on top of
2402 * it will be finished so that the user does not return to them, but
2403 * instead returns to whatever activity preceeded it.
The Android Open Source Project10592532009-03-18 17:39:46 -07002404 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002405 * <p>This is useful for cases where you have a logical break in your
2406 * application. For example, an e-mail application may have a command
2407 * to view an attachment, which launches an image view activity to
2408 * display it. This activity should be part of the e-mail application's
2409 * task, since it is a part of the task the user is involved in. However,
2410 * if the user leaves that task, and later selects the e-mail app from
2411 * home, we may like them to return to the conversation they were
2412 * viewing, not the picture attachment, since that is confusing. By
2413 * setting this flag when launching the image viewer, that viewer and
2414 * any activities it starts will be removed the next time the user returns
2415 * to mail.
2416 */
2417 public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002418 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint}
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002420 * callback from occurring on the current frontmost activity before it is
2421 * paused as the newly-started activity is brought to the front.
The Android Open Source Project10592532009-03-18 17:39:46 -07002422 *
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002423 * <p>Typically, an activity can rely on that callback to indicate that an
2424 * explicit user action has caused their activity to be moved out of the
2425 * foreground. The callback marks an appropriate point in the activity's
2426 * lifecycle for it to dismiss any notifications that it intends to display
2427 * "until the user has seen them," such as a blinking LED.
The Android Open Source Project10592532009-03-18 17:39:46 -07002428 *
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002429 * <p>If an activity is ever started via any non-user-driven events such as
2430 * phone-call receipt or an alarm handler, this flag should be passed to {@link
2431 * Context#startActivity Context.startActivity}, ensuring that the pausing
The Android Open Source Project10592532009-03-18 17:39:46 -07002432 * activity does not think the user has acknowledged its notification.
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002433 */
2434 public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 /**
2436 * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
2437 * this flag will cause the launched activity to be brought to the front of its
2438 * task's history stack if it is already running.
The Android Open Source Project10592532009-03-18 17:39:46 -07002439 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 * <p>For example, consider a task consisting of four activities: A, B, C, D.
2441 * If D calls startActivity() with an Intent that resolves to the component
2442 * of activity B, then B will be brought to the front of the history stack,
2443 * with this resulting order: A, C, D, B.
The Android Open Source Project10592532009-03-18 17:39:46 -07002444 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also
The Android Open Source Project10592532009-03-18 17:39:46 -07002446 * specified.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 */
2448 public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002449 /**
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002450 * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
2451 * this flag will prevent the system from applying an activity transition
2452 * animation to go to the next activity state. This doesn't mean an
2453 * animation will never run -- if another activity change happens that doesn't
2454 * specify this flag before the activity started here is displayed, then
2455 * that transition will be used. This this flag can be put to good use
2456 * when you are going to do a series of activity operations but the
2457 * animation seen by the user shouldn't be driven by the first activity
2458 * change but rather a later one.
2459 */
2460 public static final int FLAG_ACTIVITY_NO_ANIMATION = 0X00010000;
2461 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002462 * If set, when sending a broadcast only registered receivers will be
2463 * called -- no BroadcastReceiver components will be launched.
2464 */
2465 public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 /**
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08002467 * If set, when sending a broadcast the new broadcast will replace
2468 * any existing pending broadcast that matches it. Matching is defined
2469 * by {@link Intent#filterEquals(Intent) Intent.filterEquals} returning
2470 * true for the intents of the two broadcasts. When a match is found,
2471 * the new broadcast (and receivers associated with it) will replace the
2472 * existing one in the pending broadcast list, remaining at the same
2473 * position in the list.
Tom Taylord4a47292009-12-21 13:59:18 -08002474 *
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08002475 * <p>This flag is most typically used with sticky broadcasts, which
2476 * only care about delivering the most recent values of the broadcast
2477 * to their receivers.
2478 */
2479 public static final int FLAG_RECEIVER_REPLACE_PENDING = 0x20000000;
2480 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 * If set, when sending a broadcast <i>before boot has completed</i> only
2482 * registered receivers will be called -- no BroadcastReceiver components
2483 * will be launched. Sticky intent state will be recorded properly even
2484 * if no receivers wind up being called. If {@link #FLAG_RECEIVER_REGISTERED_ONLY}
2485 * is specified in the broadcast intent, this flag is unnecessary.
The Android Open Source Project10592532009-03-18 17:39:46 -07002486 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 * <p>This flag is only for use by system sevices as a convenience to
2488 * avoid having to implement a more complex mechanism around detection
2489 * of boot completion.
The Android Open Source Project10592532009-03-18 17:39:46 -07002490 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 * @hide
2492 */
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08002493 public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x10000000;
Dianne Hackborn9acc0302009-08-25 00:27:12 -07002494 /**
2495 * Set when this broadcast is for a boot upgrade, a special mode that
2496 * allows the broadcast to be sent before the system is ready and launches
2497 * the app process with no providers running in it.
2498 * @hide
2499 */
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08002500 public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x08000000;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002501
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002502 /**
2503 * @hide Flags that can't be changed with PendingIntent.
2504 */
2505 public static final int IMMUTABLE_FLAGS =
2506 FLAG_GRANT_READ_URI_PERMISSION
2507 | FLAG_GRANT_WRITE_URI_PERMISSION;
Tom Taylord4a47292009-12-21 13:59:18 -08002508
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002509 // ---------------------------------------------------------------------
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002510 // ---------------------------------------------------------------------
2511 // toUri() and parseUri() options.
2512
2513 /**
2514 * Flag for use with {@link #toUri} and {@link #parseUri}: the URI string
2515 * always has the "intent:" scheme. This syntax can be used when you want
2516 * to later disambiguate between URIs that are intended to describe an
2517 * Intent vs. all others that should be treated as raw URIs. When used
2518 * with {@link #parseUri}, any other scheme will result in a generic
2519 * VIEW action for that raw URI.
2520 */
2521 public static final int URI_INTENT_SCHEME = 1<<0;
Tom Taylord4a47292009-12-21 13:59:18 -08002522
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002523 // ---------------------------------------------------------------------
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002524
2525 private String mAction;
2526 private Uri mData;
2527 private String mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002528 private String mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002529 private ComponentName mComponent;
2530 private int mFlags;
2531 private HashSet<String> mCategories;
2532 private Bundle mExtras;
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08002533 private Rect mSourceBounds;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002534
2535 // ---------------------------------------------------------------------
2536
2537 /**
2538 * Create an empty intent.
2539 */
2540 public Intent() {
2541 }
2542
2543 /**
2544 * Copy constructor.
2545 */
2546 public Intent(Intent o) {
2547 this.mAction = o.mAction;
2548 this.mData = o.mData;
2549 this.mType = o.mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002550 this.mPackage = o.mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002551 this.mComponent = o.mComponent;
2552 this.mFlags = o.mFlags;
2553 if (o.mCategories != null) {
2554 this.mCategories = new HashSet<String>(o.mCategories);
2555 }
2556 if (o.mExtras != null) {
2557 this.mExtras = new Bundle(o.mExtras);
2558 }
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08002559 if (o.mSourceBounds != null) {
2560 this.mSourceBounds = new Rect(o.mSourceBounds);
2561 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002562 }
2563
2564 @Override
2565 public Object clone() {
2566 return new Intent(this);
2567 }
2568
2569 private Intent(Intent o, boolean all) {
2570 this.mAction = o.mAction;
2571 this.mData = o.mData;
2572 this.mType = o.mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002573 this.mPackage = o.mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002574 this.mComponent = o.mComponent;
2575 if (o.mCategories != null) {
2576 this.mCategories = new HashSet<String>(o.mCategories);
2577 }
2578 }
2579
2580 /**
2581 * Make a clone of only the parts of the Intent that are relevant for
2582 * filter matching: the action, data, type, component, and categories.
2583 */
2584 public Intent cloneFilter() {
2585 return new Intent(this, false);
2586 }
2587
2588 /**
2589 * Create an intent with a given action. All other fields (data, type,
2590 * class) are null. Note that the action <em>must</em> be in a
2591 * namespace because Intents are used globally in the system -- for
2592 * example the system VIEW action is android.intent.action.VIEW; an
2593 * application's custom action would be something like
2594 * com.google.app.myapp.CUSTOM_ACTION.
2595 *
2596 * @param action The Intent action, such as ACTION_VIEW.
2597 */
2598 public Intent(String action) {
2599 mAction = action;
2600 }
2601
2602 /**
2603 * Create an intent with a given action and for a given data url. Note
2604 * that the action <em>must</em> be in a namespace because Intents are
2605 * used globally in the system -- for example the system VIEW action is
2606 * android.intent.action.VIEW; an application's custom action would be
2607 * something like com.google.app.myapp.CUSTOM_ACTION.
2608 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07002609 * <p><em>Note: scheme and host name matching in the Android framework is
2610 * case-sensitive, unlike the formal RFC. As a result,
2611 * you should always ensure that you write your Uri with these elements
2612 * using lower case letters, and normalize any Uris you receive from
2613 * outside of Android to ensure the scheme and host is lower case.</em></p>
2614 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002615 * @param action The Intent action, such as ACTION_VIEW.
2616 * @param uri The Intent data URI.
2617 */
2618 public Intent(String action, Uri uri) {
2619 mAction = action;
2620 mData = uri;
2621 }
2622
2623 /**
2624 * Create an intent for a specific component. All other fields (action, data,
2625 * type, class) are null, though they can be modified later with explicit
2626 * calls. This provides a convenient way to create an intent that is
2627 * intended to execute a hard-coded class name, rather than relying on the
2628 * system to find an appropriate class for you; see {@link #setComponent}
2629 * for more information on the repercussions of this.
2630 *
2631 * @param packageContext A Context of the application package implementing
2632 * this class.
2633 * @param cls The component class that is to be used for the intent.
2634 *
2635 * @see #setClass
2636 * @see #setComponent
2637 * @see #Intent(String, android.net.Uri , Context, Class)
2638 */
2639 public Intent(Context packageContext, Class<?> cls) {
2640 mComponent = new ComponentName(packageContext, cls);
2641 }
2642
2643 /**
2644 * Create an intent for a specific component with a specified action and data.
2645 * This is equivalent using {@link #Intent(String, android.net.Uri)} to
2646 * construct the Intent and then calling {@link #setClass} to set its
2647 * class.
2648 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07002649 * <p><em>Note: scheme and host name matching in the Android framework is
2650 * case-sensitive, unlike the formal RFC. As a result,
2651 * you should always ensure that you write your Uri with these elements
2652 * using lower case letters, and normalize any Uris you receive from
2653 * outside of Android to ensure the scheme and host is lower case.</em></p>
2654 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002655 * @param action The Intent action, such as ACTION_VIEW.
2656 * @param uri The Intent data URI.
2657 * @param packageContext A Context of the application package implementing
2658 * this class.
2659 * @param cls The component class that is to be used for the intent.
2660 *
2661 * @see #Intent(String, android.net.Uri)
2662 * @see #Intent(Context, Class)
2663 * @see #setClass
2664 * @see #setComponent
2665 */
2666 public Intent(String action, Uri uri,
2667 Context packageContext, Class<?> cls) {
2668 mAction = action;
2669 mData = uri;
2670 mComponent = new ComponentName(packageContext, cls);
2671 }
2672
2673 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002674 * Call {@link #parseUri} with 0 flags.
2675 * @deprecated Use {@link #parseUri} instead.
2676 */
2677 @Deprecated
2678 public static Intent getIntent(String uri) throws URISyntaxException {
2679 return parseUri(uri, 0);
2680 }
Tom Taylord4a47292009-12-21 13:59:18 -08002681
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002682 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002683 * Create an intent from a URI. This URI may encode the action,
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002684 * category, and other intent fields, if it was returned by
Dianne Hackborn7f205432009-07-28 00:13:47 -07002685 * {@link #toUri}. If the Intent was not generate by toUri(), its data
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002686 * will be the entire URI and its action will be ACTION_VIEW.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002687 *
2688 * <p>The URI given here must not be relative -- that is, it must include
2689 * the scheme and full path.
2690 *
2691 * @param uri The URI to turn into an Intent.
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002692 * @param flags Additional processing flags. Either 0 or
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002693 * {@link #URI_INTENT_SCHEME}.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002694 *
2695 * @return Intent The newly created Intent object.
2696 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002697 * @throws URISyntaxException Throws URISyntaxError if the basic URI syntax
2698 * it bad (as parsed by the Uri class) or the Intent data within the
2699 * URI is invalid.
Tom Taylord4a47292009-12-21 13:59:18 -08002700 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002701 * @see #toUri
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002702 */
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002703 public static Intent parseUri(String uri, int flags) throws URISyntaxException {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002704 int i = 0;
2705 try {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002706 // Validate intent scheme for if requested.
2707 if ((flags&URI_INTENT_SCHEME) != 0) {
2708 if (!uri.startsWith("intent:")) {
2709 Intent intent = new Intent(ACTION_VIEW);
2710 try {
2711 intent.setData(Uri.parse(uri));
2712 } catch (IllegalArgumentException e) {
2713 throw new URISyntaxException(uri, e.getMessage());
2714 }
2715 return intent;
2716 }
2717 }
Tom Taylord4a47292009-12-21 13:59:18 -08002718
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002719 // simple case
2720 i = uri.lastIndexOf("#");
2721 if (i == -1) return new Intent(ACTION_VIEW, Uri.parse(uri));
2722
2723 // old format Intent URI
2724 if (!uri.startsWith("#Intent;", i)) return getIntentOld(uri);
The Android Open Source Project10592532009-03-18 17:39:46 -07002725
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002726 // new format
2727 Intent intent = new Intent(ACTION_VIEW);
2728
2729 // fetch data part, if present
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002730 String data = i >= 0 ? uri.substring(0, i) : null;
2731 String scheme = null;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002732 i += "#Intent;".length();
The Android Open Source Project10592532009-03-18 17:39:46 -07002733
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002734 // loop over contents of Intent, all name=value;
2735 while (!uri.startsWith("end", i)) {
2736 int eq = uri.indexOf('=', i);
2737 int semi = uri.indexOf(';', eq);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002738 String value = Uri.decode(uri.substring(eq + 1, semi));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002739
2740 // action
2741 if (uri.startsWith("action=", i)) {
2742 intent.mAction = value;
2743 }
2744
2745 // categories
2746 else if (uri.startsWith("category=", i)) {
2747 intent.addCategory(value);
2748 }
2749
2750 // type
2751 else if (uri.startsWith("type=", i)) {
2752 intent.mType = value;
2753 }
2754
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08002755 // launch flags
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002756 else if (uri.startsWith("launchFlags=", i)) {
2757 intent.mFlags = Integer.decode(value).intValue();
2758 }
2759
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002760 // package
2761 else if (uri.startsWith("package=", i)) {
2762 intent.mPackage = value;
2763 }
2764
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002765 // component
2766 else if (uri.startsWith("component=", i)) {
2767 intent.mComponent = ComponentName.unflattenFromString(value);
2768 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002769
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002770 // scheme
2771 else if (uri.startsWith("scheme=", i)) {
2772 scheme = value;
2773 }
2774
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08002775 // source bounds
2776 else if (uri.startsWith("sourceBounds=", i)) {
2777 intent.mSourceBounds = Rect.unflattenFromString(value);
2778 }
2779
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002780 // extra
2781 else {
2782 String key = Uri.decode(uri.substring(i + 2, eq));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002783 // create Bundle if it doesn't already exist
2784 if (intent.mExtras == null) intent.mExtras = new Bundle();
2785 Bundle b = intent.mExtras;
2786 // add EXTRA
2787 if (uri.startsWith("S.", i)) b.putString(key, value);
2788 else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
2789 else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
2790 else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
2791 else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
2792 else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
2793 else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
2794 else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
2795 else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
2796 else throw new URISyntaxException(uri, "unknown EXTRA type", i);
2797 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002798
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002799 // move to the next item
2800 i = semi + 1;
2801 }
2802
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002803 if (data != null) {
2804 if (data.startsWith("intent:")) {
2805 data = data.substring(7);
2806 if (scheme != null) {
2807 data = scheme + ':' + data;
2808 }
2809 }
Tom Taylord4a47292009-12-21 13:59:18 -08002810
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002811 if (data.length() > 0) {
2812 try {
2813 intent.mData = Uri.parse(data);
2814 } catch (IllegalArgumentException e) {
2815 throw new URISyntaxException(uri, e.getMessage());
2816 }
2817 }
2818 }
Tom Taylord4a47292009-12-21 13:59:18 -08002819
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002820 return intent;
The Android Open Source Project10592532009-03-18 17:39:46 -07002821
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002822 } catch (IndexOutOfBoundsException e) {
2823 throw new URISyntaxException(uri, "illegal Intent URI format", i);
2824 }
2825 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002826
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002827 public static Intent getIntentOld(String uri) throws URISyntaxException {
2828 Intent intent;
2829
2830 int i = uri.lastIndexOf('#');
2831 if (i >= 0) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002832 String action = null;
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002833 final int intentFragmentStart = i;
2834 boolean isIntentFragment = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002835
2836 i++;
2837
2838 if (uri.regionMatches(i, "action(", 0, 7)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002839 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002840 i += 7;
2841 int j = uri.indexOf(')', i);
2842 action = uri.substring(i, j);
2843 i = j + 1;
2844 }
2845
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002846 intent = new Intent(action);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002847
2848 if (uri.regionMatches(i, "categories(", 0, 11)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002849 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002850 i += 11;
2851 int j = uri.indexOf(')', i);
2852 while (i < j) {
2853 int sep = uri.indexOf('!', i);
2854 if (sep < 0) sep = j;
2855 if (i < sep) {
2856 intent.addCategory(uri.substring(i, sep));
2857 }
2858 i = sep + 1;
2859 }
2860 i = j + 1;
2861 }
2862
2863 if (uri.regionMatches(i, "type(", 0, 5)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002864 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002865 i += 5;
2866 int j = uri.indexOf(')', i);
2867 intent.mType = uri.substring(i, j);
2868 i = j + 1;
2869 }
2870
2871 if (uri.regionMatches(i, "launchFlags(", 0, 12)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002872 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002873 i += 12;
2874 int j = uri.indexOf(')', i);
2875 intent.mFlags = Integer.decode(uri.substring(i, j)).intValue();
2876 i = j + 1;
2877 }
2878
2879 if (uri.regionMatches(i, "component(", 0, 10)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002880 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002881 i += 10;
2882 int j = uri.indexOf(')', i);
2883 int sep = uri.indexOf('!', i);
2884 if (sep >= 0 && sep < j) {
2885 String pkg = uri.substring(i, sep);
2886 String cls = uri.substring(sep + 1, j);
2887 intent.mComponent = new ComponentName(pkg, cls);
2888 }
2889 i = j + 1;
2890 }
2891
2892 if (uri.regionMatches(i, "extras(", 0, 7)) {
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002893 isIntentFragment = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002894 i += 7;
The Android Open Source Project10592532009-03-18 17:39:46 -07002895
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002896 final int closeParen = uri.indexOf(')', i);
2897 if (closeParen == -1) throw new URISyntaxException(uri,
2898 "EXTRA missing trailing ')'", i);
2899
2900 while (i < closeParen) {
2901 // fetch the key value
2902 int j = uri.indexOf('=', i);
2903 if (j <= i + 1 || i >= closeParen) {
2904 throw new URISyntaxException(uri, "EXTRA missing '='", i);
2905 }
2906 char type = uri.charAt(i);
2907 i++;
2908 String key = uri.substring(i, j);
2909 i = j + 1;
The Android Open Source Project10592532009-03-18 17:39:46 -07002910
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002911 // get type-value
2912 j = uri.indexOf('!', i);
2913 if (j == -1 || j >= closeParen) j = closeParen;
2914 if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2915 String value = uri.substring(i, j);
2916 i = j;
2917
2918 // create Bundle if it doesn't already exist
2919 if (intent.mExtras == null) intent.mExtras = new Bundle();
The Android Open Source Project10592532009-03-18 17:39:46 -07002920
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002921 // add item to bundle
2922 try {
2923 switch (type) {
2924 case 'S':
2925 intent.mExtras.putString(key, Uri.decode(value));
2926 break;
2927 case 'B':
2928 intent.mExtras.putBoolean(key, Boolean.parseBoolean(value));
2929 break;
2930 case 'b':
2931 intent.mExtras.putByte(key, Byte.parseByte(value));
2932 break;
2933 case 'c':
2934 intent.mExtras.putChar(key, Uri.decode(value).charAt(0));
2935 break;
2936 case 'd':
2937 intent.mExtras.putDouble(key, Double.parseDouble(value));
2938 break;
2939 case 'f':
2940 intent.mExtras.putFloat(key, Float.parseFloat(value));
2941 break;
2942 case 'i':
2943 intent.mExtras.putInt(key, Integer.parseInt(value));
2944 break;
2945 case 'l':
2946 intent.mExtras.putLong(key, Long.parseLong(value));
2947 break;
2948 case 's':
2949 intent.mExtras.putShort(key, Short.parseShort(value));
2950 break;
2951 default:
2952 throw new URISyntaxException(uri, "EXTRA has unknown type", i);
2953 }
2954 } catch (NumberFormatException e) {
2955 throw new URISyntaxException(uri, "EXTRA value can't be parsed", i);
2956 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002957
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002958 char ch = uri.charAt(i);
2959 if (ch == ')') break;
2960 if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2961 i++;
2962 }
2963 }
2964
Dianne Hackborn6cca1592009-09-20 12:40:03 -07002965 if (isIntentFragment) {
2966 intent.mData = Uri.parse(uri.substring(0, intentFragmentStart));
2967 } else {
2968 intent.mData = Uri.parse(uri);
2969 }
Tom Taylord4a47292009-12-21 13:59:18 -08002970
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002971 if (intent.mAction == null) {
2972 // By default, if no action is specified, then use VIEW.
2973 intent.mAction = ACTION_VIEW;
2974 }
2975
2976 } else {
2977 intent = new Intent(ACTION_VIEW, Uri.parse(uri));
2978 }
2979
2980 return intent;
2981 }
2982
2983 /**
2984 * Retrieve the general action to be performed, such as
2985 * {@link #ACTION_VIEW}. The action describes the general way the rest of
2986 * the information in the intent should be interpreted -- most importantly,
2987 * what to do with the data returned by {@link #getData}.
2988 *
2989 * @return The action of this intent or null if none is specified.
2990 *
2991 * @see #setAction
2992 */
2993 public String getAction() {
2994 return mAction;
2995 }
2996
2997 /**
2998 * Retrieve data this intent is operating on. This URI specifies the name
2999 * of the data; often it uses the content: scheme, specifying data in a
3000 * content provider. Other schemes may be handled by specific activities,
3001 * such as http: by the web browser.
3002 *
3003 * @return The URI of the data this intent is targeting or null.
3004 *
3005 * @see #getScheme
3006 * @see #setData
3007 */
3008 public Uri getData() {
3009 return mData;
3010 }
3011
3012 /**
3013 * The same as {@link #getData()}, but returns the URI as an encoded
3014 * String.
3015 */
3016 public String getDataString() {
3017 return mData != null ? mData.toString() : null;
3018 }
3019
3020 /**
3021 * Return the scheme portion of the intent's data. If the data is null or
3022 * does not include a scheme, null is returned. Otherwise, the scheme
3023 * prefix without the final ':' is returned, i.e. "http".
3024 *
3025 * <p>This is the same as calling getData().getScheme() (and checking for
3026 * null data).
3027 *
3028 * @return The scheme of this intent.
3029 *
3030 * @see #getData
3031 */
3032 public String getScheme() {
3033 return mData != null ? mData.getScheme() : null;
3034 }
3035
3036 /**
3037 * Retrieve any explicit MIME type included in the intent. This is usually
3038 * null, as the type is determined by the intent data.
3039 *
3040 * @return If a type was manually set, it is returned; else null is
3041 * returned.
3042 *
3043 * @see #resolveType(ContentResolver)
3044 * @see #setType
3045 */
3046 public String getType() {
3047 return mType;
3048 }
3049
3050 /**
3051 * Return the MIME data type of this intent. If the type field is
3052 * explicitly set, that is simply returned. Otherwise, if the data is set,
3053 * the type of that data is returned. If neither fields are set, a null is
3054 * returned.
3055 *
3056 * @return The MIME type of this intent.
3057 *
3058 * @see #getType
3059 * @see #resolveType(ContentResolver)
3060 */
3061 public String resolveType(Context context) {
3062 return resolveType(context.getContentResolver());
3063 }
3064
3065 /**
3066 * Return the MIME data type of this intent. If the type field is
3067 * explicitly set, that is simply returned. Otherwise, if the data is set,
3068 * the type of that data is returned. If neither fields are set, a null is
3069 * returned.
3070 *
3071 * @param resolver A ContentResolver that can be used to determine the MIME
3072 * type of the intent's data.
3073 *
3074 * @return The MIME type of this intent.
3075 *
3076 * @see #getType
3077 * @see #resolveType(Context)
3078 */
3079 public String resolveType(ContentResolver resolver) {
3080 if (mType != null) {
3081 return mType;
3082 }
3083 if (mData != null) {
3084 if ("content".equals(mData.getScheme())) {
3085 return resolver.getType(mData);
3086 }
3087 }
3088 return null;
3089 }
3090
3091 /**
3092 * Return the MIME data type of this intent, only if it will be needed for
3093 * intent resolution. This is not generally useful for application code;
3094 * it is used by the frameworks for communicating with back-end system
3095 * services.
3096 *
3097 * @param resolver A ContentResolver that can be used to determine the MIME
3098 * type of the intent's data.
3099 *
3100 * @return The MIME type of this intent, or null if it is unknown or not
3101 * needed.
3102 */
3103 public String resolveTypeIfNeeded(ContentResolver resolver) {
3104 if (mComponent != null) {
3105 return mType;
3106 }
3107 return resolveType(resolver);
3108 }
3109
3110 /**
3111 * Check if an category exists in the intent.
3112 *
3113 * @param category The category to check.
3114 *
3115 * @return boolean True if the intent contains the category, else false.
3116 *
3117 * @see #getCategories
3118 * @see #addCategory
3119 */
3120 public boolean hasCategory(String category) {
3121 return mCategories != null && mCategories.contains(category);
3122 }
3123
3124 /**
3125 * Return the set of all categories in the intent. If there are no categories,
3126 * returns NULL.
3127 *
3128 * @return Set The set of categories you can examine. Do not modify!
3129 *
3130 * @see #hasCategory
3131 * @see #addCategory
3132 */
3133 public Set<String> getCategories() {
3134 return mCategories;
3135 }
3136
3137 /**
3138 * Sets the ClassLoader that will be used when unmarshalling
3139 * any Parcelable values from the extras of this Intent.
3140 *
3141 * @param loader a ClassLoader, or null to use the default loader
3142 * at the time of unmarshalling.
3143 */
3144 public void setExtrasClassLoader(ClassLoader loader) {
3145 if (mExtras != null) {
3146 mExtras.setClassLoader(loader);
3147 }
3148 }
3149
3150 /**
3151 * Returns true if an extra value is associated with the given name.
3152 * @param name the extra's name
3153 * @return true if the given extra is present.
3154 */
3155 public boolean hasExtra(String name) {
3156 return mExtras != null && mExtras.containsKey(name);
3157 }
3158
3159 /**
3160 * Returns true if the Intent's extras contain a parcelled file descriptor.
3161 * @return true if the Intent contains a parcelled file descriptor.
3162 */
3163 public boolean hasFileDescriptors() {
3164 return mExtras != null && mExtras.hasFileDescriptors();
3165 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003166
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003167 /**
3168 * Retrieve extended data from the intent.
3169 *
3170 * @param name The name of the desired item.
3171 *
3172 * @return the value of an item that previously added with putExtra()
3173 * or null if none was found.
3174 *
3175 * @deprecated
3176 * @hide
3177 */
3178 @Deprecated
3179 public Object getExtra(String name) {
3180 return getExtra(name, null);
3181 }
3182
3183 /**
3184 * Retrieve extended data from the intent.
3185 *
3186 * @param name The name of the desired item.
3187 * @param defaultValue the value to be returned if no value of the desired
3188 * type is stored with the given name.
3189 *
3190 * @return the value of an item that previously added with putExtra()
3191 * or the default value if none was found.
3192 *
3193 * @see #putExtra(String, boolean)
3194 */
3195 public boolean getBooleanExtra(String name, boolean defaultValue) {
3196 return mExtras == null ? defaultValue :
3197 mExtras.getBoolean(name, defaultValue);
3198 }
3199
3200 /**
3201 * Retrieve extended data from the intent.
3202 *
3203 * @param name The name of the desired item.
3204 * @param defaultValue the value to be returned if no value of the desired
3205 * type is stored with the given name.
3206 *
3207 * @return the value of an item that previously added with putExtra()
3208 * or the default value if none was found.
3209 *
3210 * @see #putExtra(String, byte)
3211 */
3212 public byte getByteExtra(String name, byte defaultValue) {
3213 return mExtras == null ? defaultValue :
3214 mExtras.getByte(name, defaultValue);
3215 }
3216
3217 /**
3218 * Retrieve extended data from the intent.
3219 *
3220 * @param name The name of the desired item.
3221 * @param defaultValue the value to be returned if no value of the desired
3222 * type is stored with the given name.
3223 *
3224 * @return the value of an item that previously added with putExtra()
3225 * or the default value if none was found.
3226 *
3227 * @see #putExtra(String, short)
3228 */
3229 public short getShortExtra(String name, short defaultValue) {
3230 return mExtras == null ? defaultValue :
3231 mExtras.getShort(name, defaultValue);
3232 }
3233
3234 /**
3235 * Retrieve extended data from the intent.
3236 *
3237 * @param name The name of the desired item.
3238 * @param defaultValue the value to be returned if no value of the desired
3239 * type is stored with the given name.
3240 *
3241 * @return the value of an item that previously added with putExtra()
3242 * or the default value if none was found.
3243 *
3244 * @see #putExtra(String, char)
3245 */
3246 public char getCharExtra(String name, char defaultValue) {
3247 return mExtras == null ? defaultValue :
3248 mExtras.getChar(name, defaultValue);
3249 }
3250
3251 /**
3252 * Retrieve extended data from the intent.
3253 *
3254 * @param name The name of the desired item.
3255 * @param defaultValue the value to be returned if no value of the desired
3256 * type is stored with the given name.
3257 *
3258 * @return the value of an item that previously added with putExtra()
3259 * or the default value if none was found.
3260 *
3261 * @see #putExtra(String, int)
3262 */
3263 public int getIntExtra(String name, int defaultValue) {
3264 return mExtras == null ? defaultValue :
3265 mExtras.getInt(name, defaultValue);
3266 }
3267
3268 /**
3269 * Retrieve extended data from the intent.
3270 *
3271 * @param name The name of the desired item.
3272 * @param defaultValue the value to be returned if no value of the desired
3273 * type is stored with the given name.
3274 *
3275 * @return the value of an item that previously added with putExtra()
3276 * or the default value if none was found.
3277 *
3278 * @see #putExtra(String, long)
3279 */
3280 public long getLongExtra(String name, long defaultValue) {
3281 return mExtras == null ? defaultValue :
3282 mExtras.getLong(name, defaultValue);
3283 }
3284
3285 /**
3286 * Retrieve extended data from the intent.
3287 *
3288 * @param name The name of the desired item.
3289 * @param defaultValue the value to be returned if no value of the desired
3290 * type is stored with the given name.
3291 *
3292 * @return the value of an item that previously added with putExtra(),
3293 * or the default value if no such item is present
3294 *
3295 * @see #putExtra(String, float)
3296 */
3297 public float getFloatExtra(String name, float defaultValue) {
3298 return mExtras == null ? defaultValue :
3299 mExtras.getFloat(name, defaultValue);
3300 }
3301
3302 /**
3303 * Retrieve extended data from the intent.
3304 *
3305 * @param name The name of the desired item.
3306 * @param defaultValue the value to be returned if no value of the desired
3307 * type is stored with the given name.
3308 *
3309 * @return the value of an item that previously added with putExtra()
3310 * or the default value if none was found.
3311 *
3312 * @see #putExtra(String, double)
3313 */
3314 public double getDoubleExtra(String name, double defaultValue) {
3315 return mExtras == null ? defaultValue :
3316 mExtras.getDouble(name, defaultValue);
3317 }
3318
3319 /**
3320 * Retrieve extended data from the intent.
3321 *
3322 * @param name The name of the desired item.
3323 *
3324 * @return the value of an item that previously added with putExtra()
3325 * or null if no String value was found.
3326 *
3327 * @see #putExtra(String, String)
3328 */
3329 public String getStringExtra(String name) {
3330 return mExtras == null ? null : mExtras.getString(name);
3331 }
3332
3333 /**
3334 * Retrieve extended data from the intent.
3335 *
3336 * @param name The name of the desired item.
3337 *
3338 * @return the value of an item that previously added with putExtra()
3339 * or null if no CharSequence value was found.
3340 *
3341 * @see #putExtra(String, CharSequence)
3342 */
3343 public CharSequence getCharSequenceExtra(String name) {
3344 return mExtras == null ? null : mExtras.getCharSequence(name);
3345 }
3346
3347 /**
3348 * Retrieve extended data from the intent.
3349 *
3350 * @param name The name of the desired item.
3351 *
3352 * @return the value of an item that previously added with putExtra()
3353 * or null if no Parcelable value was found.
3354 *
3355 * @see #putExtra(String, Parcelable)
3356 */
3357 public <T extends Parcelable> T getParcelableExtra(String name) {
3358 return mExtras == null ? null : mExtras.<T>getParcelable(name);
3359 }
3360
3361 /**
3362 * Retrieve extended data from the intent.
3363 *
3364 * @param name The name of the desired item.
3365 *
3366 * @return the value of an item that previously added with putExtra()
3367 * or null if no Parcelable[] value was found.
3368 *
3369 * @see #putExtra(String, Parcelable[])
3370 */
3371 public Parcelable[] getParcelableArrayExtra(String name) {
3372 return mExtras == null ? null : mExtras.getParcelableArray(name);
3373 }
3374
3375 /**
3376 * Retrieve extended data from the intent.
3377 *
3378 * @param name The name of the desired item.
3379 *
3380 * @return the value of an item that previously added with putExtra()
3381 * or null if no ArrayList<Parcelable> value was found.
3382 *
3383 * @see #putParcelableArrayListExtra(String, ArrayList)
3384 */
3385 public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
3386 return mExtras == null ? null : mExtras.<T>getParcelableArrayList(name);
3387 }
3388
3389 /**
3390 * Retrieve extended data from the intent.
3391 *
3392 * @param name The name of the desired item.
3393 *
3394 * @return the value of an item that previously added with putExtra()
3395 * or null if no Serializable value was found.
3396 *
3397 * @see #putExtra(String, Serializable)
3398 */
3399 public Serializable getSerializableExtra(String name) {
3400 return mExtras == null ? null : mExtras.getSerializable(name);
3401 }
3402
3403 /**
3404 * Retrieve extended data from the intent.
3405 *
3406 * @param name The name of the desired item.
3407 *
3408 * @return the value of an item that previously added with putExtra()
3409 * or null if no ArrayList<Integer> value was found.
3410 *
3411 * @see #putIntegerArrayListExtra(String, ArrayList)
3412 */
3413 public ArrayList<Integer> getIntegerArrayListExtra(String name) {
3414 return mExtras == null ? null : mExtras.getIntegerArrayList(name);
3415 }
3416
3417 /**
3418 * Retrieve extended data from the intent.
3419 *
3420 * @param name The name of the desired item.
3421 *
3422 * @return the value of an item that previously added with putExtra()
3423 * or null if no ArrayList<String> value was found.
3424 *
3425 * @see #putStringArrayListExtra(String, ArrayList)
3426 */
3427 public ArrayList<String> getStringArrayListExtra(String name) {
3428 return mExtras == null ? null : mExtras.getStringArrayList(name);
3429 }
3430
3431 /**
3432 * Retrieve extended data from the intent.
3433 *
3434 * @param name The name of the desired item.
3435 *
3436 * @return the value of an item that previously added with putExtra()
3437 * or null if no boolean array value was found.
3438 *
3439 * @see #putExtra(String, boolean[])
3440 */
3441 public boolean[] getBooleanArrayExtra(String name) {
3442 return mExtras == null ? null : mExtras.getBooleanArray(name);
3443 }
3444
3445 /**
3446 * Retrieve extended data from the intent.
3447 *
3448 * @param name The name of the desired item.
3449 *
3450 * @return the value of an item that previously added with putExtra()
3451 * or null if no byte array value was found.
3452 *
3453 * @see #putExtra(String, byte[])
3454 */
3455 public byte[] getByteArrayExtra(String name) {
3456 return mExtras == null ? null : mExtras.getByteArray(name);
3457 }
3458
3459 /**
3460 * Retrieve extended data from the intent.
3461 *
3462 * @param name The name of the desired item.
3463 *
3464 * @return the value of an item that previously added with putExtra()
3465 * or null if no short array value was found.
3466 *
3467 * @see #putExtra(String, short[])
3468 */
3469 public short[] getShortArrayExtra(String name) {
3470 return mExtras == null ? null : mExtras.getShortArray(name);
3471 }
3472
3473 /**
3474 * Retrieve extended data from the intent.
3475 *
3476 * @param name The name of the desired item.
3477 *
3478 * @return the value of an item that previously added with putExtra()
3479 * or null if no char array value was found.
3480 *
3481 * @see #putExtra(String, char[])
3482 */
3483 public char[] getCharArrayExtra(String name) {
3484 return mExtras == null ? null : mExtras.getCharArray(name);
3485 }
3486
3487 /**
3488 * Retrieve extended data from the intent.
3489 *
3490 * @param name The name of the desired item.
3491 *
3492 * @return the value of an item that previously added with putExtra()
3493 * or null if no int array value was found.
3494 *
3495 * @see #putExtra(String, int[])
3496 */
3497 public int[] getIntArrayExtra(String name) {
3498 return mExtras == null ? null : mExtras.getIntArray(name);
3499 }
3500
3501 /**
3502 * Retrieve extended data from the intent.
3503 *
3504 * @param name The name of the desired item.
3505 *
3506 * @return the value of an item that previously added with putExtra()
3507 * or null if no long array value was found.
3508 *
3509 * @see #putExtra(String, long[])
3510 */
3511 public long[] getLongArrayExtra(String name) {
3512 return mExtras == null ? null : mExtras.getLongArray(name);
3513 }
3514
3515 /**
3516 * Retrieve extended data from the intent.
3517 *
3518 * @param name The name of the desired item.
3519 *
3520 * @return the value of an item that previously added with putExtra()
3521 * or null if no float array value was found.
3522 *
3523 * @see #putExtra(String, float[])
3524 */
3525 public float[] getFloatArrayExtra(String name) {
3526 return mExtras == null ? null : mExtras.getFloatArray(name);
3527 }
3528
3529 /**
3530 * Retrieve extended data from the intent.
3531 *
3532 * @param name The name of the desired item.
3533 *
3534 * @return the value of an item that previously added with putExtra()
3535 * or null if no double array value was found.
3536 *
3537 * @see #putExtra(String, double[])
3538 */
3539 public double[] getDoubleArrayExtra(String name) {
3540 return mExtras == null ? null : mExtras.getDoubleArray(name);
3541 }
3542
3543 /**
3544 * Retrieve extended data from the intent.
3545 *
3546 * @param name The name of the desired item.
3547 *
3548 * @return the value of an item that previously added with putExtra()
3549 * or null if no String array value was found.
3550 *
3551 * @see #putExtra(String, String[])
3552 */
3553 public String[] getStringArrayExtra(String name) {
3554 return mExtras == null ? null : mExtras.getStringArray(name);
3555 }
3556
3557 /**
3558 * Retrieve extended data from the intent.
3559 *
3560 * @param name The name of the desired item.
3561 *
3562 * @return the value of an item that previously added with putExtra()
3563 * or null if no Bundle value was found.
3564 *
3565 * @see #putExtra(String, Bundle)
3566 */
3567 public Bundle getBundleExtra(String name) {
3568 return mExtras == null ? null : mExtras.getBundle(name);
3569 }
3570
3571 /**
3572 * Retrieve extended data from the intent.
3573 *
3574 * @param name The name of the desired item.
3575 *
3576 * @return the value of an item that previously added with putExtra()
3577 * or null if no IBinder value was found.
3578 *
3579 * @see #putExtra(String, IBinder)
3580 *
3581 * @deprecated
3582 * @hide
3583 */
3584 @Deprecated
3585 public IBinder getIBinderExtra(String name) {
3586 return mExtras == null ? null : mExtras.getIBinder(name);
3587 }
3588
3589 /**
3590 * Retrieve extended data from the intent.
3591 *
3592 * @param name The name of the desired item.
3593 * @param defaultValue The default value to return in case no item is
3594 * associated with the key 'name'
3595 *
3596 * @return the value of an item that previously added with putExtra()
3597 * or defaultValue if none was found.
3598 *
3599 * @see #putExtra
3600 *
3601 * @deprecated
3602 * @hide
3603 */
3604 @Deprecated
3605 public Object getExtra(String name, Object defaultValue) {
3606 Object result = defaultValue;
3607 if (mExtras != null) {
3608 Object result2 = mExtras.get(name);
3609 if (result2 != null) {
3610 result = result2;
3611 }
3612 }
3613
3614 return result;
3615 }
3616
3617 /**
3618 * Retrieves a map of extended data from the intent.
3619 *
3620 * @return the map of all extras previously added with putExtra(),
3621 * or null if none have been added.
3622 */
3623 public Bundle getExtras() {
3624 return (mExtras != null)
3625 ? new Bundle(mExtras)
3626 : null;
3627 }
3628
3629 /**
3630 * Retrieve any special flags associated with this intent. You will
3631 * normally just set them with {@link #setFlags} and let the system
3632 * take the appropriate action with them.
3633 *
3634 * @return int The currently set flags.
3635 *
3636 * @see #setFlags
3637 */
3638 public int getFlags() {
3639 return mFlags;
3640 }
3641
3642 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07003643 * Retrieve the application package name this Intent is limited to. When
3644 * resolving an Intent, if non-null this limits the resolution to only
3645 * components in the given application package.
3646 *
3647 * @return The name of the application package for the Intent.
3648 *
3649 * @see #resolveActivity
3650 * @see #setPackage
3651 */
3652 public String getPackage() {
3653 return mPackage;
3654 }
3655
3656 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003657 * Retrieve the concrete component associated with the intent. When receiving
3658 * an intent, this is the component that was found to best handle it (that is,
3659 * yourself) and will always be non-null; in all other cases it will be
3660 * null unless explicitly set.
3661 *
3662 * @return The name of the application component to handle the intent.
3663 *
3664 * @see #resolveActivity
3665 * @see #setComponent
3666 */
3667 public ComponentName getComponent() {
3668 return mComponent;
3669 }
3670
3671 /**
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08003672 * Get the bounds of the sender of this intent, in screen coordinates. This can be
3673 * used as a hint to the receiver for animations and the like. Null means that there
3674 * is no source bounds.
3675 */
3676 public Rect getSourceBounds() {
3677 return mSourceBounds;
3678 }
3679
3680 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003681 * Return the Activity component that should be used to handle this intent.
3682 * The appropriate component is determined based on the information in the
3683 * intent, evaluated as follows:
3684 *
3685 * <p>If {@link #getComponent} returns an explicit class, that is returned
3686 * without any further consideration.
3687 *
3688 * <p>The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent
3689 * category to be considered.
3690 *
3691 * <p>If {@link #getAction} is non-NULL, the activity must handle this
3692 * action.
3693 *
3694 * <p>If {@link #resolveType} returns non-NULL, the activity must handle
3695 * this type.
3696 *
3697 * <p>If {@link #addCategory} has added any categories, the activity must
3698 * handle ALL of the categories specified.
3699 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07003700 * <p>If {@link #getPackage} is non-NULL, only activity components in
3701 * that application package will be considered.
3702 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003703 * <p>If there are no activities that satisfy all of these conditions, a
3704 * null string is returned.
3705 *
3706 * <p>If multiple activities are found to satisfy the intent, the one with
3707 * the highest priority will be used. If there are multiple activities
3708 * with the same priority, the system will either pick the best activity
3709 * based on user preference, or resolve to a system class that will allow
3710 * the user to pick an activity and forward from there.
3711 *
3712 * <p>This method is implemented simply by calling
3713 * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter
3714 * true.</p>
3715 * <p> This API is called for you as part of starting an activity from an
3716 * intent. You do not normally need to call it yourself.</p>
3717 *
3718 * @param pm The package manager with which to resolve the Intent.
3719 *
3720 * @return Name of the component implementing an activity that can
3721 * display the intent.
3722 *
3723 * @see #setComponent
3724 * @see #getComponent
3725 * @see #resolveActivityInfo
3726 */
3727 public ComponentName resolveActivity(PackageManager pm) {
3728 if (mComponent != null) {
3729 return mComponent;
3730 }
3731
3732 ResolveInfo info = pm.resolveActivity(
3733 this, PackageManager.MATCH_DEFAULT_ONLY);
3734 if (info != null) {
3735 return new ComponentName(
3736 info.activityInfo.applicationInfo.packageName,
3737 info.activityInfo.name);
3738 }
3739
3740 return null;
3741 }
3742
3743 /**
3744 * Resolve the Intent into an {@link ActivityInfo}
3745 * describing the activity that should execute the intent. Resolution
3746 * follows the same rules as described for {@link #resolveActivity}, but
3747 * you get back the completely information about the resolved activity
3748 * instead of just its class name.
3749 *
3750 * @param pm The package manager with which to resolve the Intent.
3751 * @param flags Addition information to retrieve as per
3752 * {@link PackageManager#getActivityInfo(ComponentName, int)
3753 * PackageManager.getActivityInfo()}.
3754 *
3755 * @return PackageManager.ActivityInfo
3756 *
3757 * @see #resolveActivity
3758 */
3759 public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) {
3760 ActivityInfo ai = null;
3761 if (mComponent != null) {
3762 try {
3763 ai = pm.getActivityInfo(mComponent, flags);
3764 } catch (PackageManager.NameNotFoundException e) {
3765 // ignore
3766 }
3767 } else {
3768 ResolveInfo info = pm.resolveActivity(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003769 this, PackageManager.MATCH_DEFAULT_ONLY | flags);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003770 if (info != null) {
3771 ai = info.activityInfo;
3772 }
3773 }
3774
3775 return ai;
3776 }
3777
3778 /**
3779 * Set the general action to be performed.
3780 *
3781 * @param action An action name, such as ACTION_VIEW. Application-specific
3782 * actions should be prefixed with the vendor's package name.
3783 *
3784 * @return Returns the same Intent object, for chaining multiple calls
3785 * into a single statement.
3786 *
3787 * @see #getAction
3788 */
3789 public Intent setAction(String action) {
3790 mAction = action;
3791 return this;
3792 }
3793
3794 /**
3795 * Set the data this intent is operating on. This method automatically
3796 * clears any type that was previously set by {@link #setType}.
3797 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003798 * <p><em>Note: scheme and host name matching in the Android framework is
3799 * case-sensitive, unlike the formal RFC. As a result,
3800 * you should always ensure that you write your Uri with these elements
3801 * using lower case letters, and normalize any Uris you receive from
3802 * outside of Android to ensure the scheme and host is lower case.</em></p>
3803 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003804 * @param data The URI of the data this intent is now targeting.
3805 *
3806 * @return Returns the same Intent object, for chaining multiple calls
3807 * into a single statement.
3808 *
3809 * @see #getData
3810 * @see #setType
3811 * @see #setDataAndType
3812 */
3813 public Intent setData(Uri data) {
3814 mData = data;
3815 mType = null;
3816 return this;
3817 }
3818
3819 /**
3820 * Set an explicit MIME data type. This is used to create intents that
3821 * only specify a type and not data, for example to indicate the type of
3822 * data to return. This method automatically clears any data that was
3823 * previously set by {@link #setData}.
Romain Guy4969af72009-06-17 10:53:19 -07003824 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003825 * <p><em>Note: MIME type matching in the Android framework is
3826 * case-sensitive, unlike formal RFC MIME types. As a result,
3827 * you should always write your MIME types with lower case letters,
3828 * and any MIME types you receive from outside of Android should be
3829 * converted to lower case before supplying them here.</em></p>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003830 *
3831 * @param type The MIME type of the data being handled by this intent.
3832 *
3833 * @return Returns the same Intent object, for chaining multiple calls
3834 * into a single statement.
3835 *
3836 * @see #getType
3837 * @see #setData
3838 * @see #setDataAndType
3839 */
3840 public Intent setType(String type) {
3841 mData = null;
3842 mType = type;
3843 return this;
3844 }
3845
3846 /**
3847 * (Usually optional) Set the data for the intent along with an explicit
3848 * MIME data type. This method should very rarely be used -- it allows you
3849 * to override the MIME type that would ordinarily be inferred from the
3850 * data with your own type given here.
3851 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003852 * <p><em>Note: MIME type, Uri scheme, and host name matching in the
3853 * Android framework is case-sensitive, unlike the formal RFC definitions.
3854 * As a result, you should always write these elements with lower case letters,
3855 * and normalize any MIME types or Uris you receive from
3856 * outside of Android to ensure these elements are lower case before
3857 * supplying them here.</em></p>
3858 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003859 * @param data The URI of the data this intent is now targeting.
3860 * @param type The MIME type of the data being handled by this intent.
3861 *
3862 * @return Returns the same Intent object, for chaining multiple calls
3863 * into a single statement.
3864 *
3865 * @see #setData
3866 * @see #setType
3867 */
3868 public Intent setDataAndType(Uri data, String type) {
3869 mData = data;
3870 mType = type;
3871 return this;
3872 }
3873
3874 /**
3875 * Add a new category to the intent. Categories provide additional detail
3876 * about the action the intent is perform. When resolving an intent, only
3877 * activities that provide <em>all</em> of the requested categories will be
3878 * used.
3879 *
3880 * @param category The desired category. This can be either one of the
3881 * predefined Intent categories, or a custom category in your own
3882 * namespace.
3883 *
3884 * @return Returns the same Intent object, for chaining multiple calls
3885 * into a single statement.
3886 *
3887 * @see #hasCategory
3888 * @see #removeCategory
3889 */
3890 public Intent addCategory(String category) {
3891 if (mCategories == null) {
3892 mCategories = new HashSet<String>();
3893 }
3894 mCategories.add(category);
3895 return this;
3896 }
3897
3898 /**
3899 * Remove an category from an intent.
3900 *
3901 * @param category The category to remove.
3902 *
3903 * @see #addCategory
3904 */
3905 public void removeCategory(String category) {
3906 if (mCategories != null) {
3907 mCategories.remove(category);
3908 if (mCategories.size() == 0) {
3909 mCategories = null;
3910 }
3911 }
3912 }
3913
3914 /**
3915 * Add extended data to the intent. The name must include a package
3916 * prefix, for example the app com.android.contacts would use names
3917 * like "com.android.contacts.ShowAll".
3918 *
3919 * @param name The name of the extra data, with package prefix.
3920 * @param value The boolean data value.
3921 *
3922 * @return Returns the same Intent object, for chaining multiple calls
3923 * into a single statement.
3924 *
3925 * @see #putExtras
3926 * @see #removeExtra
3927 * @see #getBooleanExtra(String, boolean)
3928 */
3929 public Intent putExtra(String name, boolean value) {
3930 if (mExtras == null) {
3931 mExtras = new Bundle();
3932 }
3933 mExtras.putBoolean(name, value);
3934 return this;
3935 }
3936
3937 /**
3938 * Add extended data to the intent. The name must include a package
3939 * prefix, for example the app com.android.contacts would use names
3940 * like "com.android.contacts.ShowAll".
3941 *
3942 * @param name The name of the extra data, with package prefix.
3943 * @param value The byte data value.
3944 *
3945 * @return Returns the same Intent object, for chaining multiple calls
3946 * into a single statement.
3947 *
3948 * @see #putExtras
3949 * @see #removeExtra
3950 * @see #getByteExtra(String, byte)
3951 */
3952 public Intent putExtra(String name, byte value) {
3953 if (mExtras == null) {
3954 mExtras = new Bundle();
3955 }
3956 mExtras.putByte(name, value);
3957 return this;
3958 }
3959
3960 /**
3961 * Add extended data to the intent. The name must include a package
3962 * prefix, for example the app com.android.contacts would use names
3963 * like "com.android.contacts.ShowAll".
3964 *
3965 * @param name The name of the extra data, with package prefix.
3966 * @param value The char data value.
3967 *
3968 * @return Returns the same Intent object, for chaining multiple calls
3969 * into a single statement.
3970 *
3971 * @see #putExtras
3972 * @see #removeExtra
3973 * @see #getCharExtra(String, char)
3974 */
3975 public Intent putExtra(String name, char value) {
3976 if (mExtras == null) {
3977 mExtras = new Bundle();
3978 }
3979 mExtras.putChar(name, value);
3980 return this;
3981 }
3982
3983 /**
3984 * Add extended data to the intent. The name must include a package
3985 * prefix, for example the app com.android.contacts would use names
3986 * like "com.android.contacts.ShowAll".
3987 *
3988 * @param name The name of the extra data, with package prefix.
3989 * @param value The short data value.
3990 *
3991 * @return Returns the same Intent object, for chaining multiple calls
3992 * into a single statement.
3993 *
3994 * @see #putExtras
3995 * @see #removeExtra
3996 * @see #getShortExtra(String, short)
3997 */
3998 public Intent putExtra(String name, short value) {
3999 if (mExtras == null) {
4000 mExtras = new Bundle();
4001 }
4002 mExtras.putShort(name, value);
4003 return this;
4004 }
4005
4006 /**
4007 * Add extended data to the intent. The name must include a package
4008 * prefix, for example the app com.android.contacts would use names
4009 * like "com.android.contacts.ShowAll".
4010 *
4011 * @param name The name of the extra data, with package prefix.
4012 * @param value The integer data value.
4013 *
4014 * @return Returns the same Intent object, for chaining multiple calls
4015 * into a single statement.
4016 *
4017 * @see #putExtras
4018 * @see #removeExtra
4019 * @see #getIntExtra(String, int)
4020 */
4021 public Intent putExtra(String name, int value) {
4022 if (mExtras == null) {
4023 mExtras = new Bundle();
4024 }
4025 mExtras.putInt(name, value);
4026 return this;
4027 }
4028
4029 /**
4030 * Add extended data to the intent. The name must include a package
4031 * prefix, for example the app com.android.contacts would use names
4032 * like "com.android.contacts.ShowAll".
4033 *
4034 * @param name The name of the extra data, with package prefix.
4035 * @param value The long data value.
4036 *
4037 * @return Returns the same Intent object, for chaining multiple calls
4038 * into a single statement.
4039 *
4040 * @see #putExtras
4041 * @see #removeExtra
4042 * @see #getLongExtra(String, long)
4043 */
4044 public Intent putExtra(String name, long value) {
4045 if (mExtras == null) {
4046 mExtras = new Bundle();
4047 }
4048 mExtras.putLong(name, value);
4049 return this;
4050 }
4051
4052 /**
4053 * Add extended data to the intent. The name must include a package
4054 * prefix, for example the app com.android.contacts would use names
4055 * like "com.android.contacts.ShowAll".
4056 *
4057 * @param name The name of the extra data, with package prefix.
4058 * @param value The float data value.
4059 *
4060 * @return Returns the same Intent object, for chaining multiple calls
4061 * into a single statement.
4062 *
4063 * @see #putExtras
4064 * @see #removeExtra
4065 * @see #getFloatExtra(String, float)
4066 */
4067 public Intent putExtra(String name, float value) {
4068 if (mExtras == null) {
4069 mExtras = new Bundle();
4070 }
4071 mExtras.putFloat(name, value);
4072 return this;
4073 }
4074
4075 /**
4076 * Add extended data to the intent. The name must include a package
4077 * prefix, for example the app com.android.contacts would use names
4078 * like "com.android.contacts.ShowAll".
4079 *
4080 * @param name The name of the extra data, with package prefix.
4081 * @param value The double data value.
4082 *
4083 * @return Returns the same Intent object, for chaining multiple calls
4084 * into a single statement.
4085 *
4086 * @see #putExtras
4087 * @see #removeExtra
4088 * @see #getDoubleExtra(String, double)
4089 */
4090 public Intent putExtra(String name, double value) {
4091 if (mExtras == null) {
4092 mExtras = new Bundle();
4093 }
4094 mExtras.putDouble(name, value);
4095 return this;
4096 }
4097
4098 /**
4099 * Add extended data to the intent. The name must include a package
4100 * prefix, for example the app com.android.contacts would use names
4101 * like "com.android.contacts.ShowAll".
4102 *
4103 * @param name The name of the extra data, with package prefix.
4104 * @param value The String data value.
4105 *
4106 * @return Returns the same Intent object, for chaining multiple calls
4107 * into a single statement.
4108 *
4109 * @see #putExtras
4110 * @see #removeExtra
4111 * @see #getStringExtra(String)
4112 */
4113 public Intent putExtra(String name, String value) {
4114 if (mExtras == null) {
4115 mExtras = new Bundle();
4116 }
4117 mExtras.putString(name, value);
4118 return this;
4119 }
4120
4121 /**
4122 * Add extended data to the intent. The name must include a package
4123 * prefix, for example the app com.android.contacts would use names
4124 * like "com.android.contacts.ShowAll".
4125 *
4126 * @param name The name of the extra data, with package prefix.
4127 * @param value The CharSequence data value.
4128 *
4129 * @return Returns the same Intent object, for chaining multiple calls
4130 * into a single statement.
4131 *
4132 * @see #putExtras
4133 * @see #removeExtra
4134 * @see #getCharSequenceExtra(String)
4135 */
4136 public Intent putExtra(String name, CharSequence value) {
4137 if (mExtras == null) {
4138 mExtras = new Bundle();
4139 }
4140 mExtras.putCharSequence(name, value);
4141 return this;
4142 }
4143
4144 /**
4145 * Add extended data to the intent. The name must include a package
4146 * prefix, for example the app com.android.contacts would use names
4147 * like "com.android.contacts.ShowAll".
4148 *
4149 * @param name The name of the extra data, with package prefix.
4150 * @param value The Parcelable data value.
4151 *
4152 * @return Returns the same Intent object, for chaining multiple calls
4153 * into a single statement.
4154 *
4155 * @see #putExtras
4156 * @see #removeExtra
4157 * @see #getParcelableExtra(String)
4158 */
4159 public Intent putExtra(String name, Parcelable value) {
4160 if (mExtras == null) {
4161 mExtras = new Bundle();
4162 }
4163 mExtras.putParcelable(name, value);
4164 return this;
4165 }
4166
4167 /**
4168 * Add extended data to the intent. The name must include a package
4169 * prefix, for example the app com.android.contacts would use names
4170 * like "com.android.contacts.ShowAll".
4171 *
4172 * @param name The name of the extra data, with package prefix.
4173 * @param value The Parcelable[] data value.
4174 *
4175 * @return Returns the same Intent object, for chaining multiple calls
4176 * into a single statement.
4177 *
4178 * @see #putExtras
4179 * @see #removeExtra
4180 * @see #getParcelableArrayExtra(String)
4181 */
4182 public Intent putExtra(String name, Parcelable[] value) {
4183 if (mExtras == null) {
4184 mExtras = new Bundle();
4185 }
4186 mExtras.putParcelableArray(name, value);
4187 return this;
4188 }
4189
4190 /**
4191 * Add extended data to the intent. The name must include a package
4192 * prefix, for example the app com.android.contacts would use names
4193 * like "com.android.contacts.ShowAll".
4194 *
4195 * @param name The name of the extra data, with package prefix.
4196 * @param value The ArrayList<Parcelable> data value.
4197 *
4198 * @return Returns the same Intent object, for chaining multiple calls
4199 * into a single statement.
4200 *
4201 * @see #putExtras
4202 * @see #removeExtra
4203 * @see #getParcelableArrayListExtra(String)
4204 */
4205 public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
4206 if (mExtras == null) {
4207 mExtras = new Bundle();
4208 }
4209 mExtras.putParcelableArrayList(name, value);
4210 return this;
4211 }
4212
4213 /**
4214 * Add extended data to the intent. The name must include a package
4215 * prefix, for example the app com.android.contacts would use names
4216 * like "com.android.contacts.ShowAll".
4217 *
4218 * @param name The name of the extra data, with package prefix.
4219 * @param value The ArrayList<Integer> data value.
4220 *
4221 * @return Returns the same Intent object, for chaining multiple calls
4222 * into a single statement.
4223 *
4224 * @see #putExtras
4225 * @see #removeExtra
4226 * @see #getIntegerArrayListExtra(String)
4227 */
4228 public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
4229 if (mExtras == null) {
4230 mExtras = new Bundle();
4231 }
4232 mExtras.putIntegerArrayList(name, value);
4233 return this;
4234 }
4235
4236 /**
4237 * Add extended data to the intent. The name must include a package
4238 * prefix, for example the app com.android.contacts would use names
4239 * like "com.android.contacts.ShowAll".
4240 *
4241 * @param name The name of the extra data, with package prefix.
4242 * @param value The ArrayList<String> data value.
4243 *
4244 * @return Returns the same Intent object, for chaining multiple calls
4245 * into a single statement.
4246 *
4247 * @see #putExtras
4248 * @see #removeExtra
4249 * @see #getStringArrayListExtra(String)
4250 */
4251 public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
4252 if (mExtras == null) {
4253 mExtras = new Bundle();
4254 }
4255 mExtras.putStringArrayList(name, value);
4256 return this;
4257 }
4258
4259 /**
4260 * Add extended data to the intent. The name must include a package
4261 * prefix, for example the app com.android.contacts would use names
4262 * like "com.android.contacts.ShowAll".
4263 *
4264 * @param name The name of the extra data, with package prefix.
4265 * @param value The Serializable data value.
4266 *
4267 * @return Returns the same Intent object, for chaining multiple calls
4268 * into a single statement.
4269 *
4270 * @see #putExtras
4271 * @see #removeExtra
4272 * @see #getSerializableExtra(String)
4273 */
4274 public Intent putExtra(String name, Serializable value) {
4275 if (mExtras == null) {
4276 mExtras = new Bundle();
4277 }
4278 mExtras.putSerializable(name, value);
4279 return this;
4280 }
4281
4282 /**
4283 * Add extended data to the intent. The name must include a package
4284 * prefix, for example the app com.android.contacts would use names
4285 * like "com.android.contacts.ShowAll".
4286 *
4287 * @param name The name of the extra data, with package prefix.
4288 * @param value The boolean array data value.
4289 *
4290 * @return Returns the same Intent object, for chaining multiple calls
4291 * into a single statement.
4292 *
4293 * @see #putExtras
4294 * @see #removeExtra
4295 * @see #getBooleanArrayExtra(String)
4296 */
4297 public Intent putExtra(String name, boolean[] value) {
4298 if (mExtras == null) {
4299 mExtras = new Bundle();
4300 }
4301 mExtras.putBooleanArray(name, value);
4302 return this;
4303 }
4304
4305 /**
4306 * Add extended data to the intent. The name must include a package
4307 * prefix, for example the app com.android.contacts would use names
4308 * like "com.android.contacts.ShowAll".
4309 *
4310 * @param name The name of the extra data, with package prefix.
4311 * @param value The byte array data value.
4312 *
4313 * @return Returns the same Intent object, for chaining multiple calls
4314 * into a single statement.
4315 *
4316 * @see #putExtras
4317 * @see #removeExtra
4318 * @see #getByteArrayExtra(String)
4319 */
4320 public Intent putExtra(String name, byte[] value) {
4321 if (mExtras == null) {
4322 mExtras = new Bundle();
4323 }
4324 mExtras.putByteArray(name, value);
4325 return this;
4326 }
4327
4328 /**
4329 * Add extended data to the intent. The name must include a package
4330 * prefix, for example the app com.android.contacts would use names
4331 * like "com.android.contacts.ShowAll".
4332 *
4333 * @param name The name of the extra data, with package prefix.
4334 * @param value The short array data value.
4335 *
4336 * @return Returns the same Intent object, for chaining multiple calls
4337 * into a single statement.
4338 *
4339 * @see #putExtras
4340 * @see #removeExtra
4341 * @see #getShortArrayExtra(String)
4342 */
4343 public Intent putExtra(String name, short[] value) {
4344 if (mExtras == null) {
4345 mExtras = new Bundle();
4346 }
4347 mExtras.putShortArray(name, value);
4348 return this;
4349 }
4350
4351 /**
4352 * Add extended data to the intent. The name must include a package
4353 * prefix, for example the app com.android.contacts would use names
4354 * like "com.android.contacts.ShowAll".
4355 *
4356 * @param name The name of the extra data, with package prefix.
4357 * @param value The char array data value.
4358 *
4359 * @return Returns the same Intent object, for chaining multiple calls
4360 * into a single statement.
4361 *
4362 * @see #putExtras
4363 * @see #removeExtra
4364 * @see #getCharArrayExtra(String)
4365 */
4366 public Intent putExtra(String name, char[] value) {
4367 if (mExtras == null) {
4368 mExtras = new Bundle();
4369 }
4370 mExtras.putCharArray(name, value);
4371 return this;
4372 }
4373
4374 /**
4375 * Add extended data to the intent. The name must include a package
4376 * prefix, for example the app com.android.contacts would use names
4377 * like "com.android.contacts.ShowAll".
4378 *
4379 * @param name The name of the extra data, with package prefix.
4380 * @param value The int array data value.
4381 *
4382 * @return Returns the same Intent object, for chaining multiple calls
4383 * into a single statement.
4384 *
4385 * @see #putExtras
4386 * @see #removeExtra
4387 * @see #getIntArrayExtra(String)
4388 */
4389 public Intent putExtra(String name, int[] value) {
4390 if (mExtras == null) {
4391 mExtras = new Bundle();
4392 }
4393 mExtras.putIntArray(name, value);
4394 return this;
4395 }
4396
4397 /**
4398 * Add extended data to the intent. The name must include a package
4399 * prefix, for example the app com.android.contacts would use names
4400 * like "com.android.contacts.ShowAll".
4401 *
4402 * @param name The name of the extra data, with package prefix.
4403 * @param value The byte array data value.
4404 *
4405 * @return Returns the same Intent object, for chaining multiple calls
4406 * into a single statement.
4407 *
4408 * @see #putExtras
4409 * @see #removeExtra
4410 * @see #getLongArrayExtra(String)
4411 */
4412 public Intent putExtra(String name, long[] value) {
4413 if (mExtras == null) {
4414 mExtras = new Bundle();
4415 }
4416 mExtras.putLongArray(name, value);
4417 return this;
4418 }
4419
4420 /**
4421 * Add extended data to the intent. The name must include a package
4422 * prefix, for example the app com.android.contacts would use names
4423 * like "com.android.contacts.ShowAll".
4424 *
4425 * @param name The name of the extra data, with package prefix.
4426 * @param value The float array data value.
4427 *
4428 * @return Returns the same Intent object, for chaining multiple calls
4429 * into a single statement.
4430 *
4431 * @see #putExtras
4432 * @see #removeExtra
4433 * @see #getFloatArrayExtra(String)
4434 */
4435 public Intent putExtra(String name, float[] value) {
4436 if (mExtras == null) {
4437 mExtras = new Bundle();
4438 }
4439 mExtras.putFloatArray(name, value);
4440 return this;
4441 }
4442
4443 /**
4444 * Add extended data to the intent. The name must include a package
4445 * prefix, for example the app com.android.contacts would use names
4446 * like "com.android.contacts.ShowAll".
4447 *
4448 * @param name The name of the extra data, with package prefix.
4449 * @param value The double array data value.
4450 *
4451 * @return Returns the same Intent object, for chaining multiple calls
4452 * into a single statement.
4453 *
4454 * @see #putExtras
4455 * @see #removeExtra
4456 * @see #getDoubleArrayExtra(String)
4457 */
4458 public Intent putExtra(String name, double[] value) {
4459 if (mExtras == null) {
4460 mExtras = new Bundle();
4461 }
4462 mExtras.putDoubleArray(name, value);
4463 return this;
4464 }
4465
4466 /**
4467 * Add extended data to the intent. The name must include a package
4468 * prefix, for example the app com.android.contacts would use names
4469 * like "com.android.contacts.ShowAll".
4470 *
4471 * @param name The name of the extra data, with package prefix.
4472 * @param value The String array data value.
4473 *
4474 * @return Returns the same Intent object, for chaining multiple calls
4475 * into a single statement.
4476 *
4477 * @see #putExtras
4478 * @see #removeExtra
4479 * @see #getStringArrayExtra(String)
4480 */
4481 public Intent putExtra(String name, String[] value) {
4482 if (mExtras == null) {
4483 mExtras = new Bundle();
4484 }
4485 mExtras.putStringArray(name, value);
4486 return this;
4487 }
4488
4489 /**
4490 * Add extended data to the intent. The name must include a package
4491 * prefix, for example the app com.android.contacts would use names
4492 * like "com.android.contacts.ShowAll".
4493 *
4494 * @param name The name of the extra data, with package prefix.
4495 * @param value The Bundle data value.
4496 *
4497 * @return Returns the same Intent object, for chaining multiple calls
4498 * into a single statement.
4499 *
4500 * @see #putExtras
4501 * @see #removeExtra
4502 * @see #getBundleExtra(String)
4503 */
4504 public Intent putExtra(String name, Bundle value) {
4505 if (mExtras == null) {
4506 mExtras = new Bundle();
4507 }
4508 mExtras.putBundle(name, value);
4509 return this;
4510 }
4511
4512 /**
4513 * Add extended data to the intent. The name must include a package
4514 * prefix, for example the app com.android.contacts would use names
4515 * like "com.android.contacts.ShowAll".
4516 *
4517 * @param name The name of the extra data, with package prefix.
4518 * @param value The IBinder data value.
4519 *
4520 * @return Returns the same Intent object, for chaining multiple calls
4521 * into a single statement.
4522 *
4523 * @see #putExtras
4524 * @see #removeExtra
4525 * @see #getIBinderExtra(String)
4526 *
4527 * @deprecated
4528 * @hide
4529 */
4530 @Deprecated
4531 public Intent putExtra(String name, IBinder value) {
4532 if (mExtras == null) {
4533 mExtras = new Bundle();
4534 }
4535 mExtras.putIBinder(name, value);
4536 return this;
4537 }
4538
4539 /**
4540 * Copy all extras in 'src' in to this intent.
4541 *
4542 * @param src Contains the extras to copy.
4543 *
4544 * @see #putExtra
4545 */
4546 public Intent putExtras(Intent src) {
4547 if (src.mExtras != null) {
4548 if (mExtras == null) {
4549 mExtras = new Bundle(src.mExtras);
4550 } else {
4551 mExtras.putAll(src.mExtras);
4552 }
4553 }
4554 return this;
4555 }
4556
4557 /**
4558 * Add a set of extended data to the intent. The keys must include a package
4559 * prefix, for example the app com.android.contacts would use names
4560 * like "com.android.contacts.ShowAll".
4561 *
4562 * @param extras The Bundle of extras to add to this intent.
4563 *
4564 * @see #putExtra
4565 * @see #removeExtra
4566 */
4567 public Intent putExtras(Bundle extras) {
4568 if (mExtras == null) {
4569 mExtras = new Bundle();
4570 }
4571 mExtras.putAll(extras);
4572 return this;
4573 }
4574
4575 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004576 * Completely replace the extras in the Intent with the extras in the
4577 * given Intent.
The Android Open Source Project10592532009-03-18 17:39:46 -07004578 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004579 * @param src The exact extras contained in this Intent are copied
4580 * into the target intent, replacing any that were previously there.
4581 */
4582 public Intent replaceExtras(Intent src) {
4583 mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null;
4584 return this;
4585 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004586
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004587 /**
4588 * Completely replace the extras in the Intent with the given Bundle of
4589 * extras.
The Android Open Source Project10592532009-03-18 17:39:46 -07004590 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004591 * @param extras The new set of extras in the Intent, or null to erase
4592 * all extras.
4593 */
4594 public Intent replaceExtras(Bundle extras) {
4595 mExtras = extras != null ? new Bundle(extras) : null;
4596 return this;
4597 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004598
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004599 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004600 * Remove extended data from the intent.
4601 *
4602 * @see #putExtra
4603 */
4604 public void removeExtra(String name) {
4605 if (mExtras != null) {
4606 mExtras.remove(name);
4607 if (mExtras.size() == 0) {
4608 mExtras = null;
4609 }
4610 }
4611 }
4612
4613 /**
4614 * Set special flags controlling how this intent is handled. Most values
4615 * here depend on the type of component being executed by the Intent,
4616 * specifically the FLAG_ACTIVITY_* flags are all for use with
4617 * {@link Context#startActivity Context.startActivity()} and the
4618 * FLAG_RECEIVER_* flags are all for use with
4619 * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
4620 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 * <p>See the <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
4622 * 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 -07004623 * the behavior of your application.
4624 *
4625 * @param flags The desired flags.
4626 *
4627 * @return Returns the same Intent object, for chaining multiple calls
4628 * into a single statement.
4629 *
4630 * @see #getFlags
4631 * @see #addFlags
4632 *
4633 * @see #FLAG_GRANT_READ_URI_PERMISSION
4634 * @see #FLAG_GRANT_WRITE_URI_PERMISSION
4635 * @see #FLAG_DEBUG_LOG_RESOLUTION
4636 * @see #FLAG_FROM_BACKGROUND
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004637 * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004638 * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004639 * @see #FLAG_ACTIVITY_CLEAR_TOP
4640 * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
4641 * @see #FLAG_ACTIVITY_FORWARD_RESULT
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004642 * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004643 * @see #FLAG_ACTIVITY_MULTIPLE_TASK
4644 * @see #FLAG_ACTIVITY_NEW_TASK
4645 * @see #FLAG_ACTIVITY_NO_HISTORY
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08004646 * @see #FLAG_ACTIVITY_NO_USER_ACTION
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004647 * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP
4648 * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004649 * @see #FLAG_ACTIVITY_SINGLE_TOP
4650 * @see #FLAG_RECEIVER_REGISTERED_ONLY
4651 */
4652 public Intent setFlags(int flags) {
4653 mFlags = flags;
4654 return this;
4655 }
4656
4657 /**
4658 * Add additional flags to the intent (or with existing flags
4659 * value).
4660 *
4661 * @param flags The new flags to set.
4662 *
4663 * @return Returns the same Intent object, for chaining multiple calls
4664 * into a single statement.
4665 *
4666 * @see #setFlags
4667 */
4668 public Intent addFlags(int flags) {
4669 mFlags |= flags;
4670 return this;
4671 }
4672
4673 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004674 * (Usually optional) Set an explicit application package name that limits
4675 * the components this Intent will resolve to. If left to the default
4676 * value of null, all components in all applications will considered.
4677 * If non-null, the Intent can only match the components in the given
4678 * application package.
4679 *
4680 * @param packageName The name of the application package to handle the
4681 * intent, or null to allow any application package.
4682 *
4683 * @return Returns the same Intent object, for chaining multiple calls
4684 * into a single statement.
4685 *
4686 * @see #getPackage
4687 * @see #resolveActivity
4688 */
4689 public Intent setPackage(String packageName) {
4690 mPackage = packageName;
4691 return this;
4692 }
4693
4694 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004695 * (Usually optional) Explicitly set the component to handle the intent.
4696 * If left with the default value of null, the system will determine the
4697 * appropriate class to use based on the other fields (action, data,
4698 * type, categories) in the Intent. If this class is defined, the
4699 * specified class will always be used regardless of the other fields. You
4700 * should only set this value when you know you absolutely want a specific
4701 * class to be used; otherwise it is better to let the system find the
4702 * appropriate class so that you will respect the installed applications
4703 * and user preferences.
4704 *
4705 * @param component The name of the application component to handle the
4706 * intent, or null to let the system find one for you.
4707 *
4708 * @return Returns the same Intent object, for chaining multiple calls
4709 * into a single statement.
4710 *
4711 * @see #setClass
4712 * @see #setClassName(Context, String)
4713 * @see #setClassName(String, String)
4714 * @see #getComponent
4715 * @see #resolveActivity
4716 */
4717 public Intent setComponent(ComponentName component) {
4718 mComponent = component;
4719 return this;
4720 }
4721
4722 /**
4723 * Convenience for calling {@link #setComponent} with an
4724 * explicit class name.
4725 *
4726 * @param packageContext A Context of the application package implementing
4727 * this class.
4728 * @param className The name of a class inside of the application package
4729 * that will be used as the component for this Intent.
4730 *
4731 * @return Returns the same Intent object, for chaining multiple calls
4732 * into a single statement.
4733 *
4734 * @see #setComponent
4735 * @see #setClass
4736 */
4737 public Intent setClassName(Context packageContext, String className) {
4738 mComponent = new ComponentName(packageContext, className);
4739 return this;
4740 }
4741
4742 /**
4743 * Convenience for calling {@link #setComponent} with an
4744 * explicit application package name and class name.
4745 *
4746 * @param packageName The name of the package implementing the desired
4747 * component.
4748 * @param className The name of a class inside of the application package
4749 * that will be used as the component for this Intent.
4750 *
4751 * @return Returns the same Intent object, for chaining multiple calls
4752 * into a single statement.
4753 *
4754 * @see #setComponent
4755 * @see #setClass
4756 */
4757 public Intent setClassName(String packageName, String className) {
4758 mComponent = new ComponentName(packageName, className);
4759 return this;
4760 }
4761
4762 /**
4763 * Convenience for calling {@link #setComponent(ComponentName)} with the
4764 * name returned by a {@link Class} object.
4765 *
4766 * @param packageContext A Context of the application package implementing
4767 * this class.
4768 * @param cls The class name to set, equivalent to
4769 * <code>setClassName(context, cls.getName())</code>.
4770 *
4771 * @return Returns the same Intent object, for chaining multiple calls
4772 * into a single statement.
4773 *
4774 * @see #setComponent
4775 */
4776 public Intent setClass(Context packageContext, Class<?> cls) {
4777 mComponent = new ComponentName(packageContext, cls);
4778 return this;
4779 }
4780
4781 /**
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08004782 * Set the bounds of the sender of this intent, in screen coordinates. This can be
4783 * used as a hint to the receiver for animations and the like. Null means that there
4784 * is no source bounds.
4785 */
4786 public void setSourceBounds(Rect r) {
4787 if (r != null) {
4788 mSourceBounds = new Rect(r);
4789 } else {
4790 r = null;
4791 }
4792 }
4793
4794 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004795 * Use with {@link #fillIn} to allow the current action value to be
4796 * overwritten, even if it is already set.
4797 */
4798 public static final int FILL_IN_ACTION = 1<<0;
4799
4800 /**
4801 * Use with {@link #fillIn} to allow the current data or type value
4802 * overwritten, even if it is already set.
4803 */
4804 public static final int FILL_IN_DATA = 1<<1;
4805
4806 /**
4807 * Use with {@link #fillIn} to allow the current categories to be
4808 * overwritten, even if they are already set.
4809 */
4810 public static final int FILL_IN_CATEGORIES = 1<<2;
4811
4812 /**
4813 * Use with {@link #fillIn} to allow the current component value to be
4814 * overwritten, even if it is already set.
4815 */
4816 public static final int FILL_IN_COMPONENT = 1<<3;
4817
4818 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004819 * Use with {@link #fillIn} to allow the current package value to be
4820 * overwritten, even if it is already set.
4821 */
4822 public static final int FILL_IN_PACKAGE = 1<<4;
4823
4824 /**
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08004825 * Use with {@link #fillIn} to allow the current package value to be
4826 * overwritten, even if it is already set.
4827 */
4828 public static final int FILL_IN_SOURCE_BOUNDS = 1<<5;
4829
4830 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004831 * Copy the contents of <var>other</var> in to this object, but only
4832 * where fields are not defined by this object. For purposes of a field
4833 * being defined, the following pieces of data in the Intent are
4834 * considered to be separate fields:
4835 *
4836 * <ul>
4837 * <li> action, as set by {@link #setAction}.
4838 * <li> data URI and MIME type, as set by {@link #setData(Uri)},
4839 * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}.
4840 * <li> categories, as set by {@link #addCategory}.
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004841 * <li> package, as set by {@link #setPackage}.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004842 * <li> component, as set by {@link #setComponent(ComponentName)} or
4843 * related methods.
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08004844 * <li> source bounds, as set by {@link #setSourceBounds}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004845 * <li> each top-level name in the associated extras.
4846 * </ul>
4847 *
4848 * <p>In addition, you can use the {@link #FILL_IN_ACTION},
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004849 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
4850 * and {@link #FILL_IN_COMPONENT} to override the restriction where the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004851 * corresponding field will not be replaced if it is already set.
4852 *
Brett Chabot3e391752009-07-21 16:07:23 -07004853 * <p>Note: The component field will only be copied if {@link #FILL_IN_COMPONENT} is explicitly
4854 * specified.
4855 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004856 * <p>For example, consider Intent A with {data="foo", categories="bar"}
4857 * and Intent B with {action="gotit", data-type="some/thing",
4858 * categories="one","two"}.
4859 *
4860 * <p>Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now
4861 * containing: {action="gotit", data-type="some/thing",
4862 * categories="bar"}.
4863 *
4864 * @param other Another Intent whose values are to be used to fill in
4865 * the current one.
4866 * @param flags Options to control which fields can be filled in.
4867 *
4868 * @return Returns a bit mask of {@link #FILL_IN_ACTION},
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004869 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
4870 * and {@link #FILL_IN_COMPONENT} indicating which fields were changed.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004871 */
4872 public int fillIn(Intent other, int flags) {
4873 int changes = 0;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004874 if (other.mAction != null
4875 && (mAction == null || (flags&FILL_IN_ACTION) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004876 mAction = other.mAction;
4877 changes |= FILL_IN_ACTION;
4878 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004879 if ((other.mData != null || other.mType != null)
4880 && ((mData == null && mType == null)
4881 || (flags&FILL_IN_DATA) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004882 mData = other.mData;
4883 mType = other.mType;
4884 changes |= FILL_IN_DATA;
4885 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004886 if (other.mCategories != null
4887 && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004888 if (other.mCategories != null) {
4889 mCategories = new HashSet<String>(other.mCategories);
4890 }
4891 changes |= FILL_IN_CATEGORIES;
4892 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004893 if (other.mPackage != null
4894 && (mPackage == null || (flags&FILL_IN_PACKAGE) != 0)) {
4895 mPackage = other.mPackage;
4896 changes |= FILL_IN_PACKAGE;
4897 }
4898 // Component is special: it can -only- be set if explicitly allowed,
4899 // since otherwise the sender could force the intent somewhere the
4900 // originator didn't intend.
4901 if (other.mComponent != null && (flags&FILL_IN_COMPONENT) != 0) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004902 mComponent = other.mComponent;
4903 changes |= FILL_IN_COMPONENT;
4904 }
4905 mFlags |= other.mFlags;
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08004906 if (other.mSourceBounds != null
4907 && (mSourceBounds == null || (flags&FILL_IN_SOURCE_BOUNDS) != 0)) {
4908 mSourceBounds = new Rect(other.mSourceBounds);
4909 changes |= FILL_IN_SOURCE_BOUNDS;
4910 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004911 if (mExtras == null) {
4912 if (other.mExtras != null) {
4913 mExtras = new Bundle(other.mExtras);
4914 }
4915 } else if (other.mExtras != null) {
4916 try {
4917 Bundle newb = new Bundle(other.mExtras);
4918 newb.putAll(mExtras);
4919 mExtras = newb;
4920 } catch (RuntimeException e) {
4921 // Modifying the extras can cause us to unparcel the contents
4922 // of the bundle, and if we do this in the system process that
4923 // may fail. We really should handle this (i.e., the Bundle
4924 // impl shouldn't be on top of a plain map), but for now just
4925 // ignore it and keep the original contents. :(
4926 Log.w("Intent", "Failure filling in extras", e);
4927 }
4928 }
4929 return changes;
4930 }
4931
4932 /**
4933 * Wrapper class holding an Intent and implementing comparisons on it for
4934 * the purpose of filtering. The class implements its
4935 * {@link #equals equals()} and {@link #hashCode hashCode()} methods as
4936 * simple calls to {@link Intent#filterEquals(Intent)} filterEquals()} and
4937 * {@link android.content.Intent#filterHashCode()} filterHashCode()}
4938 * on the wrapped Intent.
4939 */
4940 public static final class FilterComparison {
4941 private final Intent mIntent;
4942 private final int mHashCode;
4943
4944 public FilterComparison(Intent intent) {
4945 mIntent = intent;
4946 mHashCode = intent.filterHashCode();
4947 }
4948
4949 /**
4950 * Return the Intent that this FilterComparison represents.
4951 * @return Returns the Intent held by the FilterComparison. Do
4952 * not modify!
4953 */
4954 public Intent getIntent() {
4955 return mIntent;
4956 }
4957
4958 @Override
4959 public boolean equals(Object obj) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004960 if (obj instanceof FilterComparison) {
4961 Intent other = ((FilterComparison)obj).mIntent;
4962 return mIntent.filterEquals(other);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004963 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 return false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004965 }
4966
4967 @Override
4968 public int hashCode() {
4969 return mHashCode;
4970 }
4971 }
4972
4973 /**
4974 * Determine if two intents are the same for the purposes of intent
4975 * resolution (filtering). That is, if their action, data, type,
4976 * class, and categories are the same. This does <em>not</em> compare
4977 * any extra data included in the intents.
4978 *
4979 * @param other The other Intent to compare against.
4980 *
4981 * @return Returns true if action, data, type, class, and categories
4982 * are the same.
4983 */
4984 public boolean filterEquals(Intent other) {
4985 if (other == null) {
4986 return false;
4987 }
4988 if (mAction != other.mAction) {
4989 if (mAction != null) {
4990 if (!mAction.equals(other.mAction)) {
4991 return false;
4992 }
4993 } else {
4994 if (!other.mAction.equals(mAction)) {
4995 return false;
4996 }
4997 }
4998 }
4999 if (mData != other.mData) {
5000 if (mData != null) {
5001 if (!mData.equals(other.mData)) {
5002 return false;
5003 }
5004 } else {
5005 if (!other.mData.equals(mData)) {
5006 return false;
5007 }
5008 }
5009 }
5010 if (mType != other.mType) {
5011 if (mType != null) {
5012 if (!mType.equals(other.mType)) {
5013 return false;
5014 }
5015 } else {
5016 if (!other.mType.equals(mType)) {
5017 return false;
5018 }
5019 }
5020 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005021 if (mPackage != other.mPackage) {
5022 if (mPackage != null) {
5023 if (!mPackage.equals(other.mPackage)) {
5024 return false;
5025 }
5026 } else {
5027 if (!other.mPackage.equals(mPackage)) {
5028 return false;
5029 }
5030 }
5031 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005032 if (mComponent != other.mComponent) {
5033 if (mComponent != null) {
5034 if (!mComponent.equals(other.mComponent)) {
5035 return false;
5036 }
5037 } else {
5038 if (!other.mComponent.equals(mComponent)) {
5039 return false;
5040 }
5041 }
5042 }
5043 if (mCategories != other.mCategories) {
5044 if (mCategories != null) {
5045 if (!mCategories.equals(other.mCategories)) {
5046 return false;
5047 }
5048 } else {
5049 if (!other.mCategories.equals(mCategories)) {
5050 return false;
5051 }
5052 }
5053 }
5054
5055 return true;
5056 }
5057
5058 /**
5059 * Generate hash code that matches semantics of filterEquals().
5060 *
5061 * @return Returns the hash value of the action, data, type, class, and
5062 * categories.
5063 *
5064 * @see #filterEquals
5065 */
5066 public int filterHashCode() {
5067 int code = 0;
5068 if (mAction != null) {
5069 code += mAction.hashCode();
5070 }
5071 if (mData != null) {
5072 code += mData.hashCode();
5073 }
5074 if (mType != null) {
5075 code += mType.hashCode();
5076 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005077 if (mPackage != null) {
5078 code += mPackage.hashCode();
5079 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005080 if (mComponent != null) {
5081 code += mComponent.hashCode();
5082 }
5083 if (mCategories != null) {
5084 code += mCategories.hashCode();
5085 }
5086 return code;
5087 }
5088
5089 @Override
5090 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005091 StringBuilder b = new StringBuilder(128);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005092
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005093 b.append("Intent { ");
5094 toShortString(b, true, true);
5095 b.append(" }");
5096
5097 return b.toString();
5098 }
5099
5100 /** @hide */
5101 public String toShortString(boolean comp, boolean extras) {
5102 StringBuilder b = new StringBuilder(128);
5103 toShortString(b, comp, extras);
5104 return b.toString();
5105 }
Romain Guy4969af72009-06-17 10:53:19 -07005106
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005107 /** @hide */
5108 public void toShortString(StringBuilder b, boolean comp, boolean extras) {
5109 boolean first = true;
5110 if (mAction != null) {
5111 b.append("act=").append(mAction);
5112 first = false;
5113 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005114 if (mCategories != null) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005115 if (!first) {
5116 b.append(' ');
5117 }
5118 first = false;
5119 b.append("cat=[");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005120 Iterator<String> i = mCategories.iterator();
5121 boolean didone = false;
5122 while (i.hasNext()) {
5123 if (didone) b.append(",");
5124 didone = true;
5125 b.append(i.next());
5126 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005127 b.append("]");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005128 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005129 if (mData != null) {
5130 if (!first) {
5131 b.append(' ');
5132 }
5133 first = false;
5134 b.append("dat=").append(mData);
5135 }
5136 if (mType != null) {
5137 if (!first) {
5138 b.append(' ');
5139 }
5140 first = false;
5141 b.append("typ=").append(mType);
5142 }
5143 if (mFlags != 0) {
5144 if (!first) {
5145 b.append(' ');
5146 }
5147 first = false;
5148 b.append("flg=0x").append(Integer.toHexString(mFlags));
5149 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005150 if (mPackage != null) {
5151 if (!first) {
5152 b.append(' ');
5153 }
5154 first = false;
5155 b.append("pkg=").append(mPackage);
5156 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005157 if (comp && mComponent != null) {
5158 if (!first) {
5159 b.append(' ');
5160 }
5161 first = false;
5162 b.append("cmp=").append(mComponent.flattenToShortString());
5163 }
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08005164 if (mSourceBounds != null) {
5165 if (!first) {
5166 b.append(' ');
5167 }
5168 first = false;
5169 b.append("bnds=").append(mSourceBounds.toShortString());
5170 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005171 if (extras && mExtras != null) {
5172 if (!first) {
5173 b.append(' ');
5174 }
5175 first = false;
5176 b.append("(has extras)");
5177 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005178 }
5179
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005180 /**
5181 * Call {@link #toUri} with 0 flags.
5182 * @deprecated Use {@link #toUri} instead.
5183 */
5184 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005185 public String toURI() {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005186 return toUri(0);
5187 }
5188
5189 /**
5190 * Convert this Intent into a String holding a URI representation of it.
5191 * The returned URI string has been properly URI encoded, so it can be
5192 * used with {@link Uri#parse Uri.parse(String)}. The URI contains the
5193 * Intent's data as the base URI, with an additional fragment describing
5194 * the action, categories, type, flags, package, component, and extras.
Tom Taylord4a47292009-12-21 13:59:18 -08005195 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005196 * <p>You can convert the returned string back to an Intent with
5197 * {@link #getIntent}.
Tom Taylord4a47292009-12-21 13:59:18 -08005198 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005199 * @param flags Additional operating flags. Either 0 or
5200 * {@link #URI_INTENT_SCHEME}.
Tom Taylord4a47292009-12-21 13:59:18 -08005201 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005202 * @return Returns a URI encoding URI string describing the entire contents
5203 * of the Intent.
5204 */
5205 public String toUri(int flags) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005206 StringBuilder uri = new StringBuilder(128);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005207 String scheme = null;
5208 if (mData != null) {
5209 String data = mData.toString();
5210 if ((flags&URI_INTENT_SCHEME) != 0) {
5211 final int N = data.length();
5212 for (int i=0; i<N; i++) {
5213 char c = data.charAt(i);
5214 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
5215 || c == '.' || c == '-') {
5216 continue;
5217 }
5218 if (c == ':' && i > 0) {
5219 // Valid scheme.
5220 scheme = data.substring(0, i);
5221 uri.append("intent:");
5222 data = data.substring(i+1);
5223 break;
5224 }
Tom Taylord4a47292009-12-21 13:59:18 -08005225
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005226 // No scheme.
5227 break;
5228 }
5229 }
5230 uri.append(data);
Tom Taylord4a47292009-12-21 13:59:18 -08005231
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005232 } else if ((flags&URI_INTENT_SCHEME) != 0) {
5233 uri.append("intent:");
5234 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005235
5236 uri.append("#Intent;");
5237
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005238 if (scheme != null) {
5239 uri.append("scheme=").append(scheme).append(';');
5240 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005241 if (mAction != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005242 uri.append("action=").append(Uri.encode(mAction)).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005243 }
5244 if (mCategories != null) {
5245 for (String category : mCategories) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005246 uri.append("category=").append(Uri.encode(category)).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005247 }
5248 }
5249 if (mType != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005250 uri.append("type=").append(Uri.encode(mType, "/")).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005251 }
5252 if (mFlags != 0) {
5253 uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
5254 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005255 if (mPackage != null) {
5256 uri.append("package=").append(Uri.encode(mPackage)).append(';');
5257 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005258 if (mComponent != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005259 uri.append("component=").append(Uri.encode(
5260 mComponent.flattenToShortString(), "/")).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005261 }
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08005262 if (mSourceBounds != null) {
5263 uri.append("sourceBounds=")
5264 .append(Uri.encode(mSourceBounds.flattenToString()))
5265 .append(';');
5266 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005267 if (mExtras != null) {
5268 for (String key : mExtras.keySet()) {
5269 final Object value = mExtras.get(key);
5270 char entryType =
5271 value instanceof String ? 'S' :
5272 value instanceof Boolean ? 'B' :
5273 value instanceof Byte ? 'b' :
5274 value instanceof Character ? 'c' :
5275 value instanceof Double ? 'd' :
5276 value instanceof Float ? 'f' :
5277 value instanceof Integer ? 'i' :
5278 value instanceof Long ? 'l' :
5279 value instanceof Short ? 's' :
5280 '\0';
5281
5282 if (entryType != '\0') {
5283 uri.append(entryType);
5284 uri.append('.');
5285 uri.append(Uri.encode(key));
5286 uri.append('=');
5287 uri.append(Uri.encode(value.toString()));
5288 uri.append(';');
5289 }
5290 }
5291 }
The Android Open Source Project10592532009-03-18 17:39:46 -07005292
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005293 uri.append("end");
5294
5295 return uri.toString();
5296 }
The Android Open Source Project10592532009-03-18 17:39:46 -07005297
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005298 public int describeContents() {
5299 return (mExtras != null) ? mExtras.describeContents() : 0;
5300 }
5301
5302 public void writeToParcel(Parcel out, int flags) {
5303 out.writeString(mAction);
5304 Uri.writeToParcel(out, mData);
5305 out.writeString(mType);
5306 out.writeInt(mFlags);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005307 out.writeString(mPackage);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005308 ComponentName.writeToParcel(mComponent, out);
5309
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08005310 if (mSourceBounds != null) {
5311 out.writeInt(1);
5312 mSourceBounds.writeToParcel(out, flags);
5313 } else {
5314 out.writeInt(0);
5315 }
5316
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005317 if (mCategories != null) {
5318 out.writeInt(mCategories.size());
5319 for (String category : mCategories) {
5320 out.writeString(category);
5321 }
5322 } else {
5323 out.writeInt(0);
5324 }
5325
5326 out.writeBundle(mExtras);
5327 }
5328
5329 public static final Parcelable.Creator<Intent> CREATOR
5330 = new Parcelable.Creator<Intent>() {
5331 public Intent createFromParcel(Parcel in) {
5332 return new Intent(in);
5333 }
5334 public Intent[] newArray(int size) {
5335 return new Intent[size];
5336 }
5337 };
5338
Dianne Hackborneb034652009-09-07 00:49:58 -07005339 /** @hide */
5340 protected Intent(Parcel in) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005341 readFromParcel(in);
5342 }
5343
5344 public void readFromParcel(Parcel in) {
5345 mAction = in.readString();
5346 mData = Uri.CREATOR.createFromParcel(in);
5347 mType = in.readString();
5348 mFlags = in.readInt();
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005349 mPackage = in.readString();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005350 mComponent = ComponentName.readFromParcel(in);
5351
Joe Onoratoc7a63ee2009-12-02 21:13:17 -08005352 if (in.readInt() != 0) {
5353 mSourceBounds = Rect.CREATOR.createFromParcel(in);
5354 }
5355
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005356 int N = in.readInt();
5357 if (N > 0) {
5358 mCategories = new HashSet<String>();
5359 int i;
5360 for (i=0; i<N; i++) {
5361 mCategories.add(in.readString());
5362 }
5363 } else {
5364 mCategories = null;
5365 }
5366
5367 mExtras = in.readBundle();
5368 }
5369
5370 /**
5371 * Parses the "intent" element (and its children) from XML and instantiates
5372 * an Intent object. The given XML parser should be located at the tag
5373 * where parsing should start (often named "intent"), from which the
5374 * basic action, data, type, and package and class name will be
5375 * retrieved. The function will then parse in to any child elements,
5376 * looking for <category android:name="xxx"> tags to add categories and
5377 * <extra android:name="xxx" android:value="yyy"> to attach extra data
5378 * to the intent.
5379 *
5380 * @param resources The Resources to use when inflating resources.
5381 * @param parser The XML parser pointing at an "intent" tag.
5382 * @param attrs The AttributeSet interface for retrieving extended
5383 * attribute data at the current <var>parser</var> location.
5384 * @return An Intent object matching the XML data.
5385 * @throws XmlPullParserException If there was an XML parsing error.
5386 * @throws IOException If there was an I/O error.
5387 */
5388 public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
5389 throws XmlPullParserException, IOException {
5390 Intent intent = new Intent();
5391
5392 TypedArray sa = resources.obtainAttributes(attrs,
5393 com.android.internal.R.styleable.Intent);
5394
5395 intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action));
5396
5397 String data = sa.getString(com.android.internal.R.styleable.Intent_data);
5398 String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType);
5399 intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType);
5400
5401 String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage);
5402 String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass);
5403 if (packageName != null && className != null) {
5404 intent.setComponent(new ComponentName(packageName, className));
5405 }
5406
5407 sa.recycle();
5408
5409 int outerDepth = parser.getDepth();
5410 int type;
5411 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
5412 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
5413 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
5414 continue;
5415 }
5416
5417 String nodeName = parser.getName();
5418 if (nodeName.equals("category")) {
5419 sa = resources.obtainAttributes(attrs,
5420 com.android.internal.R.styleable.IntentCategory);
5421 String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name);
5422 sa.recycle();
5423
5424 if (cat != null) {
5425 intent.addCategory(cat);
5426 }
5427 XmlUtils.skipCurrentTag(parser);
5428
5429 } else if (nodeName.equals("extra")) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08005430 if (intent.mExtras == null) {
5431 intent.mExtras = new Bundle();
5432 }
5433 resources.parseBundleExtra("extra", attrs, intent.mExtras);
5434 XmlUtils.skipCurrentTag(parser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005435
5436 } else {
5437 XmlUtils.skipCurrentTag(parser);
5438 }
5439 }
5440
5441 return intent;
5442 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005443}