blob: 2a176727ce2bafc5747778a4d8a1a2f9066654df [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
19import org.xmlpull.v1.XmlPullParser;
20import org.xmlpull.v1.XmlPullParserException;
21
22import android.annotation.SdkConstant;
23import android.annotation.SdkConstant.SdkConstantType;
24import android.content.pm.ActivityInfo;
25import android.content.pm.PackageManager;
26import android.content.pm.ResolveInfo;
27import android.content.res.Resources;
28import android.content.res.TypedArray;
29import android.net.Uri;
30import android.os.Bundle;
31import android.os.IBinder;
32import android.os.Parcel;
33import android.os.Parcelable;
34import android.util.AttributeSet;
35import android.util.Log;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070036import com.android.internal.util.XmlUtils;
37
38import java.io.IOException;
39import java.io.Serializable;
40import java.net.URISyntaxException;
41import java.util.ArrayList;
42import java.util.HashSet;
43import java.util.Iterator;
44import java.util.Set;
45
46/**
47 * An intent is an abstract description of an operation to be performed. It
48 * can be used with {@link Context#startActivity(Intent) startActivity} to
49 * launch an {@link android.app.Activity},
50 * {@link android.content.Context#sendBroadcast(Intent) broadcastIntent} to
51 * send it to any interested {@link BroadcastReceiver BroadcastReceiver} components,
52 * and {@link android.content.Context#startService} or
53 * {@link android.content.Context#bindService} to communicate with a
54 * background {@link android.app.Service}.
55 *
56 * <p>An Intent provides a facility for performing late runtime binding between
57 * the code in different applications. Its most significant use is in the
58 * launching of activities, where it can be thought of as the glue between
59 * activities. It is
60 * basically a passive data structure holding an abstract description of an
61 * action to be performed. The primary pieces of information in an intent
62 * are:</p>
63 *
64 * <ul>
65 * <li> <p><b>action</b> -- The general action to be performed, such as
66 * {@link #ACTION_VIEW}, {@link #ACTION_EDIT}, {@link #ACTION_MAIN},
67 * etc.</p>
68 * </li>
69 * <li> <p><b>data</b> -- The data to operate on, such as a person record
70 * in the contacts database, expressed as a {@link android.net.Uri}.</p>
71 * </li>
72 * </ul>
73 *
74 *
75 * <p>Some examples of action/data pairs are:</p>
76 *
77 * <ul>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -070078 * <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/1</i></b> -- Display
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070079 * information about the person whose identifier is "1".</p>
80 * </li>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -070081 * <li> <p><b>{@link #ACTION_DIAL} <i>content://contacts/people/1</i></b> -- Display
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070082 * the phone dialer with the person filled in.</p>
83 * </li>
84 * <li> <p><b>{@link #ACTION_VIEW} <i>tel:123</i></b> -- Display
85 * the phone dialer with the given number filled in. Note how the
86 * VIEW action does what what is considered the most reasonable thing for
87 * a particular URI.</p>
88 * </li>
89 * <li> <p><b>{@link #ACTION_DIAL} <i>tel:123</i></b> -- Display
90 * the phone dialer with the given number filled in.</p>
91 * </li>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -070092 * <li> <p><b>{@link #ACTION_EDIT} <i>content://contacts/people/1</i></b> -- Edit
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070093 * information about the person whose identifier is "1".</p>
94 * </li>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -070095 * <li> <p><b>{@link #ACTION_VIEW} <i>content://contacts/people/</i></b> -- Display
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070096 * a list of people, which the user can browse through. This example is a
97 * typical top-level entry into the Contacts application, showing you the
98 * list of people. Selecting a particular person to view would result in a
99 * new intent { <b>{@link #ACTION_VIEW} <i>content://contacts/N</i></b> }
100 * being used to start an activity to display that person.</p>
101 * </li>
102 * </ul>
103 *
104 * <p>In addition to these primary attributes, there are a number of secondary
105 * attributes that you can also include with an intent:</p>
106 *
107 * <ul>
108 * <li> <p><b>category</b> -- Gives additional information about the action
109 * to execute. For example, {@link #CATEGORY_LAUNCHER} means it should
110 * appear in the Launcher as a top-level application, while
111 * {@link #CATEGORY_ALTERNATIVE} means it should be included in a list
112 * of alternative actions the user can perform on a piece of data.</p>
113 * <li> <p><b>type</b> -- Specifies an explicit type (a MIME type) of the
114 * intent data. Normally the type is inferred from the data itself.
115 * By setting this attribute, you disable that evaluation and force
116 * an explicit type.</p>
117 * <li> <p><b>component</b> -- Specifies an explicit name of a component
118 * class to use for the intent. Normally this is determined by looking
119 * at the other information in the intent (the action, data/type, and
120 * categories) and matching that with a component that can handle it.
121 * If this attribute is set then none of the evaluation is performed,
122 * and this component is used exactly as is. By specifying this attribute,
123 * all of the other Intent attributes become optional.</p>
124 * <li> <p><b>extras</b> -- This is a {@link Bundle} of any additional information.
125 * This can be used to provide extended information to the component.
126 * For example, if we have a action to send an e-mail message, we could
127 * also include extra pieces of data here to supply a subject, body,
128 * etc.</p>
129 * </ul>
130 *
131 * <p>Here are some examples of other operations you can specify as intents
132 * using these additional parameters:</p>
133 *
134 * <ul>
135 * <li> <p><b>{@link #ACTION_MAIN} with category {@link #CATEGORY_HOME}</b> --
136 * Launch the home screen.</p>
137 * </li>
138 * <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
139 * <i>{@link android.provider.Contacts.Phones#CONTENT_URI
140 * vnd.android.cursor.item/phone}</i></b>
141 * -- Display the list of people's phone numbers, allowing the user to
142 * browse through them and pick one and return it to the parent activity.</p>
143 * </li>
144 * <li> <p><b>{@link #ACTION_GET_CONTENT} with MIME type
145 * <i>*{@literal /}*</i> and category {@link #CATEGORY_OPENABLE}</b>
146 * -- Display all pickers for data that can be opened with
147 * {@link ContentResolver#openInputStream(Uri) ContentResolver.openInputStream()},
148 * allowing the user to pick one of them and then some data inside of it
149 * and returning the resulting URI to the caller. This can be used,
150 * for example, in an e-mail application to allow the user to pick some
151 * data to include as an attachment.</p>
152 * </li>
153 * </ul>
154 *
155 * <p>There are a variety of standard Intent action and category constants
156 * defined in the Intent class, but applications can also define their own.
157 * These strings use java style scoping, to ensure they are unique -- for
158 * example, the standard {@link #ACTION_VIEW} is called
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -0700159 * "android.intent.action.VIEW".</p>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700160 *
161 * <p>Put together, the set of actions, data types, categories, and extra data
162 * defines a language for the system allowing for the expression of phrases
163 * such as "call john smith's cell". As applications are added to the system,
164 * they can extend this language by adding new actions, types, and categories, or
165 * they can modify the behavior of existing phrases by supplying their own
166 * activities that handle them.</p>
167 *
168 * <a name="IntentResolution"></a>
169 * <h3>Intent Resolution</h3>
170 *
171 * <p>There are two primary forms of intents you will use.
172 *
173 * <ul>
174 * <li> <p><b>Explicit Intents</b> have specified a component (via
175 * {@link #setComponent} or {@link #setClass}), which provides the exact
176 * class to be run. Often these will not include any other information,
177 * simply being a way for an application to launch various internal
178 * activities it has as the user interacts with the application.
179 *
180 * <li> <p><b>Implicit Intents</b> have not specified a component;
181 * instead, they must include enough information for the system to
182 * determine which of the available components is best to run for that
183 * intent.
184 * </ul>
185 *
186 * <p>When using implicit intents, given such an arbitrary intent we need to
187 * know what to do with it. This is handled by the process of <em>Intent
188 * resolution</em>, which maps an Intent to an {@link android.app.Activity},
189 * {@link BroadcastReceiver}, or {@link android.app.Service} (or sometimes two or
190 * more activities/receivers) that can handle it.</p>
191 *
192 * <p>The intent resolution mechanism basically revolves around matching an
193 * Intent against all of the &lt;intent-filter&gt; descriptions in the
194 * installed application packages. (Plus, in the case of broadcasts, any {@link BroadcastReceiver}
195 * objects explicitly registered with {@link Context#registerReceiver}.) More
196 * details on this can be found in the documentation on the {@link
197 * IntentFilter} class.</p>
198 *
199 * <p>There are three pieces of information in the Intent that are used for
200 * resolution: the action, type, and category. Using this information, a query
201 * is done on the {@link PackageManager} for a component that can handle the
202 * intent. The appropriate component is determined based on the intent
203 * information supplied in the <code>AndroidManifest.xml</code> file as
204 * follows:</p>
205 *
206 * <ul>
207 * <li> <p>The <b>action</b>, if given, must be listed by the component as
208 * one it handles.</p>
209 * <li> <p>The <b>type</b> is retrieved from the Intent's data, if not
210 * already supplied in the Intent. Like the action, if a type is
211 * included in the intent (either explicitly or implicitly in its
212 * data), then this must be listed by the component as one it handles.</p>
213 * <li> For data that is not a <code>content:</code> URI and where no explicit
214 * type is included in the Intent, instead the <b>scheme</b> of the
215 * intent data (such as <code>http:</code> or <code>mailto:</code>) is
216 * considered. Again like the action, if we are matching a scheme it
217 * must be listed by the component as one it can handle.
218 * <li> <p>The <b>categories</b>, if supplied, must <em>all</em> be listed
219 * by the activity as categories it handles. That is, if you include
220 * the categories {@link #CATEGORY_LAUNCHER} and
221 * {@link #CATEGORY_ALTERNATIVE}, then you will only resolve to components
222 * with an intent that lists <em>both</em> of those categories.
223 * Activities will very often need to support the
224 * {@link #CATEGORY_DEFAULT} so that they can be found by
225 * {@link Context#startActivity Context.startActivity()}.</p>
226 * </ul>
227 *
228 * <p>For example, consider the Note Pad sample application that
229 * allows user to browse through a list of notes data and view details about
230 * individual items. Text in italics indicate places were you would replace a
231 * name with one specific to your own package.</p>
232 *
233 * <pre> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
234 * package="<i>com.android.notepad</i>"&gt;
235 * &lt;application android:icon="@drawable/app_notes"
236 * android:label="@string/app_name"&gt;
237 *
238 * &lt;provider class=".NotePadProvider"
239 * android:authorities="<i>com.google.provider.NotePad</i>" /&gt;
240 *
241 * &lt;activity class=".NotesList" android:label="@string/title_notes_list"&gt;
242 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700243 * &lt;action android:name="android.intent.action.MAIN" /&gt;
244 * &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700245 * &lt;/intent-filter&gt;
246 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700247 * &lt;action android:name="android.intent.action.VIEW" /&gt;
248 * &lt;action android:name="android.intent.action.EDIT" /&gt;
249 * &lt;action android:name="android.intent.action.PICK" /&gt;
250 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
251 * &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700252 * &lt;/intent-filter&gt;
253 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700254 * &lt;action android:name="android.intent.action.GET_CONTENT" /&gt;
255 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
256 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700257 * &lt;/intent-filter&gt;
258 * &lt;/activity&gt;
259 *
260 * &lt;activity class=".NoteEditor" android:label="@string/title_note"&gt;
261 * &lt;intent-filter android:label="@string/resolve_edit"&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700262 * &lt;action android:name="android.intent.action.VIEW" /&gt;
263 * &lt;action android:name="android.intent.action.EDIT" /&gt;
264 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
265 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700266 * &lt;/intent-filter&gt;
267 *
268 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700269 * &lt;action android:name="android.intent.action.INSERT" /&gt;
270 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
271 * &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700272 * &lt;/intent-filter&gt;
273 *
274 * &lt;/activity&gt;
275 *
276 * &lt;activity class=".TitleEditor" android:label="@string/title_edit_title"
277 * android:theme="@android:style/Theme.Dialog"&gt;
278 * &lt;intent-filter android:label="@string/resolve_title"&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700279 * &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
280 * &lt;category android:name="android.intent.category.DEFAULT" /&gt;
281 * &lt;category android:name="android.intent.category.ALTERNATIVE" /&gt;
282 * &lt;category android:name="android.intent.category.SELECTED_ALTERNATIVE" /&gt;
283 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700284 * &lt;/intent-filter&gt;
285 * &lt;/activity&gt;
286 *
287 * &lt;/application&gt;
288 * &lt;/manifest&gt;</pre>
289 *
290 * <p>The first activity,
291 * <code>com.android.notepad.NotesList</code>, serves as our main
292 * entry into the app. It can do three things as described by its three intent
293 * templates:
294 * <ol>
295 * <li><pre>
296 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700297 * &lt;action android:name="{@link #ACTION_MAIN android.intent.action.MAIN}" /&gt;
298 * &lt;category android:name="{@link #CATEGORY_LAUNCHER android.intent.category.LAUNCHER}" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700299 * &lt;/intent-filter&gt;</pre>
300 * <p>This provides a top-level entry into the NotePad application: the standard
301 * MAIN action is a main entry point (not requiring any other information in
302 * the Intent), and the LAUNCHER category says that this entry point should be
303 * listed in the application launcher.</p>
304 * <li><pre>
305 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700306 * &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
307 * &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
308 * &lt;action android:name="{@link #ACTION_PICK android.intent.action.PICK}" /&gt;
309 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
310 * &lt;data mimeType:name="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700311 * &lt;/intent-filter&gt;</pre>
312 * <p>This declares the things that the activity can do on a directory of
313 * notes. The type being supported is given with the &lt;type&gt; tag, where
314 * <code>vnd.android.cursor.dir/vnd.google.note</code> is a URI from which
315 * a Cursor of zero or more items (<code>vnd.android.cursor.dir</code>) can
316 * be retrieved which holds our note pad data (<code>vnd.google.note</code>).
317 * The activity allows the user to view or edit the directory of data (via
318 * the VIEW and EDIT actions), or to pick a particular note and return it
319 * to the caller (via the PICK action). Note also the DEFAULT category
320 * supplied here: this is <em>required</em> for the
321 * {@link Context#startActivity Context.startActivity} method to resolve your
322 * activity when its component name is not explicitly specified.</p>
323 * <li><pre>
324 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700325 * &lt;action android:name="{@link #ACTION_GET_CONTENT android.intent.action.GET_CONTENT}" /&gt;
326 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
327 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700328 * &lt;/intent-filter&gt;</pre>
329 * <p>This filter describes the ability return to the caller a note selected by
330 * the user without needing to know where it came from. The data type
331 * <code>vnd.android.cursor.item/vnd.google.note</code> is a URI from which
332 * a Cursor of exactly one (<code>vnd.android.cursor.item</code>) item can
333 * be retrieved which contains our note pad data (<code>vnd.google.note</code>).
334 * The GET_CONTENT action is similar to the PICK action, where the activity
335 * will return to its caller a piece of data selected by the user. Here,
336 * however, the caller specifies the type of data they desire instead of
337 * the type of data the user will be picking from.</p>
338 * </ol>
339 *
340 * <p>Given these capabilities, the following intents will resolve to the
341 * NotesList activity:</p>
342 *
343 * <ul>
344 * <li> <p><b>{ action=android.app.action.MAIN }</b> matches all of the
345 * activities that can be used as top-level entry points into an
346 * application.</p>
347 * <li> <p><b>{ action=android.app.action.MAIN,
348 * category=android.app.category.LAUNCHER }</b> is the actual intent
349 * used by the Launcher to populate its top-level list.</p>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -0700350 * <li> <p><b>{ action=android.intent.action.VIEW
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700351 * data=content://com.google.provider.NotePad/notes }</b>
352 * displays a list of all the notes under
353 * "content://com.google.provider.NotePad/notes", which
354 * the user can browse through and see the details on.</p>
355 * <li> <p><b>{ action=android.app.action.PICK
356 * data=content://com.google.provider.NotePad/notes }</b>
357 * provides a list of the notes under
358 * "content://com.google.provider.NotePad/notes", from which
359 * the user can pick a note whose data URL is returned back to the caller.</p>
360 * <li> <p><b>{ action=android.app.action.GET_CONTENT
361 * type=vnd.android.cursor.item/vnd.google.note }</b>
362 * is similar to the pick action, but allows the caller to specify the
363 * kind of data they want back so that the system can find the appropriate
364 * activity to pick something of that data type.</p>
365 * </ul>
366 *
367 * <p>The second activity,
368 * <code>com.android.notepad.NoteEditor</code>, shows the user a single
369 * note entry and allows them to edit it. It can do two things as described
370 * by its two intent templates:
371 * <ol>
372 * <li><pre>
373 * &lt;intent-filter android:label="@string/resolve_edit"&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700374 * &lt;action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" /&gt;
375 * &lt;action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" /&gt;
376 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
377 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700378 * &lt;/intent-filter&gt;</pre>
379 * <p>The first, primary, purpose of this activity is to let the user interact
380 * with a single note, as decribed by the MIME type
381 * <code>vnd.android.cursor.item/vnd.google.note</code>. The activity can
382 * either VIEW a note or allow the user to EDIT it. Again we support the
383 * DEFAULT category to allow the activity to be launched without explicitly
384 * specifying its component.</p>
385 * <li><pre>
386 * &lt;intent-filter&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700387 * &lt;action android:name="{@link #ACTION_INSERT android.intent.action.INSERT}" /&gt;
388 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
389 * &lt;data android:mimeType="vnd.android.cursor.dir/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700390 * &lt;/intent-filter&gt;</pre>
391 * <p>The secondary use of this activity is to insert a new note entry into
392 * an existing directory of notes. This is used when the user creates a new
393 * note: the INSERT action is executed on the directory of notes, causing
394 * this activity to run and have the user create the new note data which
395 * it then adds to the content provider.</p>
396 * </ol>
397 *
398 * <p>Given these capabilities, the following intents will resolve to the
399 * NoteEditor activity:</p>
400 *
401 * <ul>
Yusuf T. Mobile8ecb36e2009-07-10 14:13:29 -0700402 * <li> <p><b>{ action=android.intent.action.VIEW
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700403 * data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
404 * shows the user the content of note <var>{ID}</var>.</p>
405 * <li> <p><b>{ action=android.app.action.EDIT
406 * data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
407 * allows the user to edit the content of note <var>{ID}</var>.</p>
408 * <li> <p><b>{ action=android.app.action.INSERT
409 * data=content://com.google.provider.NotePad/notes }</b>
410 * creates a new, empty note in the notes list at
411 * "content://com.google.provider.NotePad/notes"
412 * and allows the user to edit it. If they keep their changes, the URI
413 * of the newly created note is returned to the caller.</p>
414 * </ul>
415 *
416 * <p>The last activity,
417 * <code>com.android.notepad.TitleEditor</code>, allows the user to
418 * edit the title of a note. This could be implemented as a class that the
419 * application directly invokes (by explicitly setting its component in
420 * the Intent), but here we show a way you can publish alternative
421 * operations on existing data:</p>
422 *
423 * <pre>
424 * &lt;intent-filter android:label="@string/resolve_title"&gt;
Romain Guy4969af72009-06-17 10:53:19 -0700425 * &lt;action android:name="<i>com.android.notepad.action.EDIT_TITLE</i>" /&gt;
426 * &lt;category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" /&gt;
427 * &lt;category android:name="{@link #CATEGORY_ALTERNATIVE android.intent.category.ALTERNATIVE}" /&gt;
428 * &lt;category android:name="{@link #CATEGORY_SELECTED_ALTERNATIVE android.intent.category.SELECTED_ALTERNATIVE}" /&gt;
429 * &lt;data android:mimeType="vnd.android.cursor.item/<i>vnd.google.note</i>" /&gt;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700430 * &lt;/intent-filter&gt;</pre>
431 *
432 * <p>In the single intent template here, we
433 * have created our own private action called
434 * <code>com.android.notepad.action.EDIT_TITLE</code> which means to
435 * edit the title of a note. It must be invoked on a specific note
436 * (data type <code>vnd.android.cursor.item/vnd.google.note</code>) like the previous
437 * view and edit actions, but here displays and edits the title contained
438 * in the note data.
439 *
440 * <p>In addition to supporting the default category as usual, our title editor
441 * also supports two other standard categories: ALTERNATIVE and
442 * SELECTED_ALTERNATIVE. Implementing
443 * these categories allows others to find the special action it provides
444 * without directly knowing about it, through the
445 * {@link android.content.pm.PackageManager#queryIntentActivityOptions} method, or
446 * more often to build dynamic menu items with
447 * {@link android.view.Menu#addIntentOptions}. Note that in the intent
448 * template here was also supply an explicit name for the template
449 * (via <code>android:label="@string/resolve_title"</code>) to better control
450 * what the user sees when presented with this activity as an alternative
451 * action to the data they are viewing.
452 *
453 * <p>Given these capabilities, the following intent will resolve to the
454 * TitleEditor activity:</p>
455 *
456 * <ul>
457 * <li> <p><b>{ action=com.android.notepad.action.EDIT_TITLE
458 * data=content://com.google.provider.NotePad/notes/<var>{ID}</var> }</b>
459 * displays and allows the user to edit the title associated
460 * with note <var>{ID}</var>.</p>
461 * </ul>
462 *
463 * <h3>Standard Activity Actions</h3>
464 *
465 * <p>These are the current standard actions that Intent defines for launching
466 * activities (usually through {@link Context#startActivity}. The most
467 * important, and by far most frequently used, are {@link #ACTION_MAIN} and
468 * {@link #ACTION_EDIT}.
469 *
470 * <ul>
471 * <li> {@link #ACTION_MAIN}
472 * <li> {@link #ACTION_VIEW}
473 * <li> {@link #ACTION_ATTACH_DATA}
474 * <li> {@link #ACTION_EDIT}
475 * <li> {@link #ACTION_PICK}
476 * <li> {@link #ACTION_CHOOSER}
477 * <li> {@link #ACTION_GET_CONTENT}
478 * <li> {@link #ACTION_DIAL}
479 * <li> {@link #ACTION_CALL}
480 * <li> {@link #ACTION_SEND}
481 * <li> {@link #ACTION_SENDTO}
482 * <li> {@link #ACTION_ANSWER}
483 * <li> {@link #ACTION_INSERT}
484 * <li> {@link #ACTION_DELETE}
485 * <li> {@link #ACTION_RUN}
486 * <li> {@link #ACTION_SYNC}
487 * <li> {@link #ACTION_PICK_ACTIVITY}
488 * <li> {@link #ACTION_SEARCH}
489 * <li> {@link #ACTION_WEB_SEARCH}
490 * <li> {@link #ACTION_FACTORY_TEST}
491 * </ul>
492 *
493 * <h3>Standard Broadcast Actions</h3>
494 *
495 * <p>These are the current standard actions that Intent defines for receiving
496 * broadcasts (usually through {@link Context#registerReceiver} or a
497 * &lt;receiver&gt; tag in a manifest).
498 *
499 * <ul>
500 * <li> {@link #ACTION_TIME_TICK}
501 * <li> {@link #ACTION_TIME_CHANGED}
502 * <li> {@link #ACTION_TIMEZONE_CHANGED}
503 * <li> {@link #ACTION_BOOT_COMPLETED}
504 * <li> {@link #ACTION_PACKAGE_ADDED}
505 * <li> {@link #ACTION_PACKAGE_CHANGED}
506 * <li> {@link #ACTION_PACKAGE_REMOVED}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 * <li> {@link #ACTION_PACKAGE_RESTARTED}
508 * <li> {@link #ACTION_PACKAGE_DATA_CLEARED}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700509 * <li> {@link #ACTION_UID_REMOVED}
510 * <li> {@link #ACTION_BATTERY_CHANGED}
Cliff Spradlinfda6fae2008-10-22 20:29:16 -0700511 * <li> {@link #ACTION_POWER_CONNECTED}
Romain Guy4969af72009-06-17 10:53:19 -0700512 * <li> {@link #ACTION_POWER_DISCONNECTED}
513 * <li> {@link #ACTION_SHUTDOWN}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700514 * </ul>
515 *
516 * <h3>Standard Categories</h3>
517 *
518 * <p>These are the current standard categories that can be used to further
519 * clarify an Intent via {@link #addCategory}.
520 *
521 * <ul>
522 * <li> {@link #CATEGORY_DEFAULT}
523 * <li> {@link #CATEGORY_BROWSABLE}
524 * <li> {@link #CATEGORY_TAB}
525 * <li> {@link #CATEGORY_ALTERNATIVE}
526 * <li> {@link #CATEGORY_SELECTED_ALTERNATIVE}
527 * <li> {@link #CATEGORY_LAUNCHER}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 * <li> {@link #CATEGORY_INFO}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700529 * <li> {@link #CATEGORY_HOME}
530 * <li> {@link #CATEGORY_PREFERENCE}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700531 * <li> {@link #CATEGORY_TEST}
532 * </ul>
533 *
534 * <h3>Standard Extra Data</h3>
535 *
536 * <p>These are the current standard fields that can be used as extra data via
537 * {@link #putExtra}.
538 *
539 * <ul>
540 * <li> {@link #EXTRA_TEMPLATE}
541 * <li> {@link #EXTRA_INTENT}
542 * <li> {@link #EXTRA_STREAM}
543 * <li> {@link #EXTRA_TEXT}
544 * </ul>
545 *
546 * <h3>Flags</h3>
547 *
548 * <p>These are the possible flags that can be used in the Intent via
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800549 * {@link #setFlags} and {@link #addFlags}. See {@link #setFlags} for a list
550 * of all possible flags.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700551 */
552public class Intent implements Parcelable {
553 // ---------------------------------------------------------------------
554 // ---------------------------------------------------------------------
555 // Standard intent activity actions (see action variable).
556
557 /**
558 * Activity Action: Start as a main entry point, does not expect to
559 * receive data.
560 * <p>Input: nothing
561 * <p>Output: nothing
562 */
563 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
564 public static final String ACTION_MAIN = "android.intent.action.MAIN";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800565
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700566 /**
567 * Activity Action: Display the data to the user. This is the most common
568 * action performed on data -- it is the generic action you can use on
569 * a piece of data to get the most reasonable thing to occur. For example,
570 * when used on a contacts entry it will view the entry; when used on a
571 * mailto: URI it will bring up a compose window filled with the information
572 * supplied by the URI; when used with a tel: URI it will invoke the
573 * dialer.
574 * <p>Input: {@link #getData} is URI from which to retrieve data.
575 * <p>Output: nothing.
576 */
577 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
578 public static final String ACTION_VIEW = "android.intent.action.VIEW";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800579
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700580 /**
581 * A synonym for {@link #ACTION_VIEW}, the "standard" action that is
582 * performed on a piece of data.
583 */
584 public static final String ACTION_DEFAULT = ACTION_VIEW;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800585
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700586 /**
587 * Used to indicate that some piece of data should be attached to some other
588 * place. For example, image data could be attached to a contact. It is up
589 * to the recipient to decide where the data should be attached; the intent
590 * does not specify the ultimate destination.
591 * <p>Input: {@link #getData} is URI of data to be attached.
592 * <p>Output: nothing.
593 */
594 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
595 public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800596
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700597 /**
598 * Activity Action: Provide explicit editable access to the given data.
599 * <p>Input: {@link #getData} is URI of data to be edited.
600 * <p>Output: nothing.
601 */
602 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
603 public static final String ACTION_EDIT = "android.intent.action.EDIT";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800604
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700605 /**
606 * Activity Action: Pick an existing item, or insert a new item, and then edit it.
607 * <p>Input: {@link #getType} is the desired MIME type of the item to create or edit.
608 * The extras can contain type specific data to pass through to the editing/creating
609 * activity.
610 * <p>Output: The URI of the item that was picked. This must be a content:
611 * URI so that any receiver can access it.
612 */
613 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
614 public static final String ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800615
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700616 /**
617 * Activity Action: Pick an item from the data, returning what was selected.
618 * <p>Input: {@link #getData} is URI containing a directory of data
619 * (vnd.android.cursor.dir/*) from which to pick an item.
620 * <p>Output: The URI of the item that was picked.
621 */
622 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
623 public static final String ACTION_PICK = "android.intent.action.PICK";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800624
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700625 /**
626 * Activity Action: Creates a shortcut.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800627 * <p>Input: Nothing.</p>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700628 * <p>Output: An Intent representing the shortcut. The intent must contain three
629 * extras: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String),
630 * and SHORTCUT_ICON (value: Bitmap) or SHORTCUT_ICON_RESOURCE
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800631 * (value: ShortcutIconResource).</p>
632 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700633 * @see #EXTRA_SHORTCUT_INTENT
634 * @see #EXTRA_SHORTCUT_NAME
635 * @see #EXTRA_SHORTCUT_ICON
636 * @see #EXTRA_SHORTCUT_ICON_RESOURCE
637 * @see android.content.Intent.ShortcutIconResource
638 */
639 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
640 public static final String ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
641
642 /**
643 * The name of the extra used to define the Intent of a shortcut.
644 *
645 * @see #ACTION_CREATE_SHORTCUT
646 */
647 public static final String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
648 /**
649 * The name of the extra used to define the name of a shortcut.
650 *
651 * @see #ACTION_CREATE_SHORTCUT
652 */
653 public static final String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
654 /**
655 * The name of the extra used to define the icon, as a Bitmap, of a shortcut.
656 *
657 * @see #ACTION_CREATE_SHORTCUT
658 */
659 public static final String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
660 /**
661 * The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.
662 *
663 * @see #ACTION_CREATE_SHORTCUT
664 * @see android.content.Intent.ShortcutIconResource
665 */
666 public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
667 "android.intent.extra.shortcut.ICON_RESOURCE";
668
669 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800670 * Represents a shortcut/live folder icon resource.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700671 *
672 * @see Intent#ACTION_CREATE_SHORTCUT
673 * @see Intent#EXTRA_SHORTCUT_ICON_RESOURCE
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800674 * @see android.provider.LiveFolders#ACTION_CREATE_LIVE_FOLDER
675 * @see android.provider.LiveFolders#EXTRA_LIVE_FOLDER_ICON
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700676 */
677 public static class ShortcutIconResource implements Parcelable {
678 /**
679 * The package name of the application containing the icon.
680 */
681 public String packageName;
682
683 /**
684 * The resource name of the icon, including package, name and type.
685 */
686 public String resourceName;
687
688 /**
689 * Creates a new ShortcutIconResource for the specified context and resource
690 * identifier.
691 *
692 * @param context The context of the application.
693 * @param resourceId The resource idenfitier for the icon.
694 * @return A new ShortcutIconResource with the specified's context package name
695 * and icon resource idenfitier.
696 */
697 public static ShortcutIconResource fromContext(Context context, int resourceId) {
698 ShortcutIconResource icon = new ShortcutIconResource();
699 icon.packageName = context.getPackageName();
700 icon.resourceName = context.getResources().getResourceName(resourceId);
701 return icon;
702 }
703
704 /**
705 * Used to read a ShortcutIconResource from a Parcel.
706 */
707 public static final Parcelable.Creator<ShortcutIconResource> CREATOR =
708 new Parcelable.Creator<ShortcutIconResource>() {
709
710 public ShortcutIconResource createFromParcel(Parcel source) {
711 ShortcutIconResource icon = new ShortcutIconResource();
712 icon.packageName = source.readString();
713 icon.resourceName = source.readString();
714 return icon;
715 }
716
717 public ShortcutIconResource[] newArray(int size) {
718 return new ShortcutIconResource[size];
719 }
720 };
721
722 /**
723 * No special parcel contents.
724 */
725 public int describeContents() {
726 return 0;
727 }
728
729 public void writeToParcel(Parcel dest, int flags) {
730 dest.writeString(packageName);
731 dest.writeString(resourceName);
732 }
733
734 @Override
735 public String toString() {
736 return resourceName;
737 }
738 }
739
740 /**
741 * Activity Action: Display an activity chooser, allowing the user to pick
742 * what they want to before proceeding. This can be used as an alternative
743 * to the standard activity picker that is displayed by the system when
744 * you try to start an activity with multiple possible matches, with these
745 * differences in behavior:
746 * <ul>
747 * <li>You can specify the title that will appear in the activity chooser.
748 * <li>The user does not have the option to make one of the matching
749 * activities a preferred activity, and all possible activities will
750 * always be shown even if one of them is currently marked as the
751 * preferred activity.
752 * </ul>
753 * <p>
754 * This action should be used when the user will naturally expect to
755 * select an activity in order to proceed. An example if when not to use
756 * it is when the user clicks on a "mailto:" link. They would naturally
757 * expect to go directly to their mail app, so startActivity() should be
758 * called directly: it will
759 * either launch the current preferred app, or put up a dialog allowing the
760 * user to pick an app to use and optionally marking that as preferred.
761 * <p>
762 * In contrast, if the user is selecting a menu item to send a picture
763 * they are viewing to someone else, there are many different things they
764 * may want to do at this point: send it through e-mail, upload it to a
765 * web service, etc. In this case the CHOOSER action should be used, to
766 * always present to the user a list of the things they can do, with a
767 * nice title given by the caller such as "Send this photo with:".
768 * <p>
769 * As a convenience, an Intent of this form can be created with the
770 * {@link #createChooser} function.
771 * <p>Input: No data should be specified. get*Extra must have
772 * a {@link #EXTRA_INTENT} field containing the Intent being executed,
773 * and can optionally have a {@link #EXTRA_TITLE} field containing the
774 * title text to display in the chooser.
775 * <p>Output: Depends on the protocol of {@link #EXTRA_INTENT}.
776 */
777 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
778 public static final String ACTION_CHOOSER = "android.intent.action.CHOOSER";
779
780 /**
781 * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
782 *
783 * @param target The Intent that the user will be selecting an activity
784 * to perform.
785 * @param title Optional title that will be displayed in the chooser.
786 * @return Return a new Intent object that you can hand to
787 * {@link Context#startActivity(Intent) Context.startActivity()} and
788 * related methods.
789 */
790 public static Intent createChooser(Intent target, CharSequence title) {
791 Intent intent = new Intent(ACTION_CHOOSER);
792 intent.putExtra(EXTRA_INTENT, target);
793 if (title != null) {
794 intent.putExtra(EXTRA_TITLE, title);
795 }
796 return intent;
797 }
798 /**
799 * Activity Action: Allow the user to select a particular kind of data and
800 * return it. This is different than {@link #ACTION_PICK} in that here we
801 * just say what kind of data is desired, not a URI of existing data from
802 * which the user can pick. A ACTION_GET_CONTENT could allow the user to
803 * create the data as it runs (for example taking a picture or recording a
804 * sound), let them browser over the web and download the desired data,
805 * etc.
806 * <p>
807 * There are two main ways to use this action: if you want an specific kind
808 * of data, such as a person contact, you set the MIME type to the kind of
809 * data you want and launch it with {@link Context#startActivity(Intent)}.
810 * The system will then launch the best application to select that kind
811 * of data for you.
812 * <p>
813 * You may also be interested in any of a set of types of content the user
814 * can pick. For example, an e-mail application that wants to allow the
815 * user to add an attachment to an e-mail message can use this action to
816 * bring up a list of all of the types of content the user can attach.
817 * <p>
818 * In this case, you should wrap the GET_CONTENT intent with a chooser
819 * (through {@link #createChooser}), which will give the proper interface
820 * for the user to pick how to send your data and allow you to specify
821 * a prompt indicating what they are doing. You will usually specify a
822 * broad MIME type (such as image/* or {@literal *}/*), resulting in a
823 * broad range of content types the user can select from.
824 * <p>
825 * When using such a broad GET_CONTENT action, it is often desireable to
826 * only pick from data that can be represented as a stream. This is
827 * accomplished by requiring the {@link #CATEGORY_OPENABLE} in the Intent.
828 * <p>
829 * Input: {@link #getType} is the desired MIME type to retrieve. Note
830 * that no URI is supplied in the intent, as there are no constraints on
831 * where the returned data originally comes from. You may also include the
832 * {@link #CATEGORY_OPENABLE} if you can only accept data that can be
833 * opened as a stream.
834 * <p>
835 * Output: The URI of the item that was picked. This must be a content:
836 * URI so that any receiver can access it.
837 */
838 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
839 public static final String ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
840 /**
841 * Activity Action: Dial a number as specified by the data. This shows a
842 * UI with the number being dialed, allowing the user to explicitly
843 * initiate the call.
844 * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
845 * is URI of a phone number to be dialed or a tel: URI of an explicit phone
846 * number.
847 * <p>Output: nothing.
848 */
849 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
850 public static final String ACTION_DIAL = "android.intent.action.DIAL";
851 /**
852 * Activity Action: Perform a call to someone specified by the data.
853 * <p>Input: If nothing, an empty dialer is started; else {@link #getData}
854 * is URI of a phone number to be dialed or a tel: URI of an explicit phone
855 * number.
856 * <p>Output: nothing.
857 *
858 * <p>Note: there will be restrictions on which applications can initiate a
859 * call; most applications should use the {@link #ACTION_DIAL}.
860 * <p>Note: this Intent <strong>cannot</strong> be used to call emergency
861 * numbers. Applications can <strong>dial</strong> emergency numbers using
862 * {@link #ACTION_DIAL}, however.
863 */
864 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
865 public static final String ACTION_CALL = "android.intent.action.CALL";
866 /**
867 * Activity Action: Perform a call to an emergency number specified by the
868 * data.
869 * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
870 * tel: URI of an explicit phone number.
871 * <p>Output: nothing.
872 * @hide
873 */
874 public static final String ACTION_CALL_EMERGENCY = "android.intent.action.CALL_EMERGENCY";
875 /**
876 * Activity action: Perform a call to any number (emergency or not)
877 * specified by the data.
878 * <p>Input: {@link #getData} is URI of a phone number to be dialed or a
879 * tel: URI of an explicit phone number.
880 * <p>Output: nothing.
881 * @hide
882 */
883 public static final String ACTION_CALL_PRIVILEGED = "android.intent.action.CALL_PRIVILEGED";
884 /**
885 * Activity Action: Send a message to someone specified by the data.
886 * <p>Input: {@link #getData} is URI describing the target.
887 * <p>Output: nothing.
888 */
889 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
890 public static final String ACTION_SENDTO = "android.intent.action.SENDTO";
891 /**
892 * Activity Action: Deliver some data to someone else. Who the data is
893 * being delivered to is not specified; it is up to the receiver of this
894 * action to ask the user where the data should be sent.
895 * <p>
896 * When launching a SEND intent, you should usually wrap it in a chooser
897 * (through {@link #createChooser}), which will give the proper interface
898 * for the user to pick how to send your data and allow you to specify
899 * a prompt indicating what they are doing.
900 * <p>
901 * Input: {@link #getType} is the MIME type of the data being sent.
902 * get*Extra can have either a {@link #EXTRA_TEXT}
903 * or {@link #EXTRA_STREAM} field, containing the data to be sent. If
904 * using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it
905 * should be the MIME type of the data in EXTRA_STREAM. Use {@literal *}/*
906 * if the MIME type is unknown (this will only allow senders that can
907 * handle generic data streams).
908 * <p>
909 * Optional standard extras, which may be interpreted by some recipients as
910 * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
911 * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
912 * <p>
913 * Output: nothing.
914 */
915 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
916 public static final String ACTION_SEND = "android.intent.action.SEND";
917 /**
Wu-cheng Li649f99e2009-06-17 14:29:57 +0800918 * Activity Action: Deliver multiple data to someone else.
919 * <p>
920 * Like ACTION_SEND, except the data is multiple.
921 * <p>
922 * Input: {@link #getType} is the MIME type of the data being sent.
923 * get*ArrayListExtra can have either a {@link #EXTRA_TEXT} or {@link
924 * #EXTRA_STREAM} field, containing the data to be sent.
925 * <p>
926 * Optional standard extras, which may be interpreted by some recipients as
927 * appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
928 * {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.
929 * <p>
930 * Output: nothing.
931 */
932 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
933 public static final String ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE";
934 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700935 * Activity Action: Handle an incoming phone call.
936 * <p>Input: nothing.
937 * <p>Output: nothing.
938 */
939 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
940 public static final String ACTION_ANSWER = "android.intent.action.ANSWER";
941 /**
942 * Activity Action: Insert an empty item into the given container.
943 * <p>Input: {@link #getData} is URI of the directory (vnd.android.cursor.dir/*)
944 * in which to place the data.
945 * <p>Output: URI of the new data that was created.
946 */
947 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
948 public static final String ACTION_INSERT = "android.intent.action.INSERT";
949 /**
950 * Activity Action: Delete the given data from its container.
951 * <p>Input: {@link #getData} is URI of data to be deleted.
952 * <p>Output: nothing.
953 */
954 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
955 public static final String ACTION_DELETE = "android.intent.action.DELETE";
956 /**
957 * Activity Action: Run the data, whatever that means.
958 * <p>Input: ? (Note: this is currently specific to the test harness.)
959 * <p>Output: nothing.
960 */
961 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
962 public static final String ACTION_RUN = "android.intent.action.RUN";
963 /**
964 * Activity Action: Perform a data synchronization.
965 * <p>Input: ?
966 * <p>Output: ?
967 */
968 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
969 public static final String ACTION_SYNC = "android.intent.action.SYNC";
970 /**
971 * Activity Action: Pick an activity given an intent, returning the class
972 * selected.
973 * <p>Input: get*Extra field {@link #EXTRA_INTENT} is an Intent
974 * used with {@link PackageManager#queryIntentActivities} to determine the
975 * set of activities from which to pick.
976 * <p>Output: Class name of the activity that was selected.
977 */
978 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
979 public static final String ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
980 /**
981 * Activity Action: Perform a search.
982 * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
983 * is the text to search for. If empty, simply
984 * enter your search results Activity with the search UI activated.
985 * <p>Output: nothing.
986 */
987 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
988 public static final String ACTION_SEARCH = "android.intent.action.SEARCH";
989 /**
Jim Miller7e4ad352009-03-25 18:16:41 -0700990 * Activity Action: Start the platform-defined tutorial
991 * <p>Input: {@link android.app.SearchManager#QUERY getStringExtra(SearchManager.QUERY)}
992 * is the text to search for. If empty, simply
993 * enter your search results Activity with the search UI activated.
994 * <p>Output: nothing.
995 */
996 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
997 public static final String ACTION_SYSTEM_TUTORIAL = "android.intent.action.SYSTEM_TUTORIAL";
998 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700999 * Activity Action: Perform a web search.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001000 * <p>
1001 * Input: {@link android.app.SearchManager#QUERY
1002 * getStringExtra(SearchManager.QUERY)} is the text to search for. If it is
1003 * a url starts with http or https, the site will be opened. If it is plain
1004 * text, Google search will be applied.
1005 * <p>
1006 * Output: nothing.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001007 */
1008 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1009 public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
1010 /**
1011 * Activity Action: List all available applications
1012 * <p>Input: Nothing.
1013 * <p>Output: nothing.
1014 */
1015 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1016 public static final String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
1017 /**
1018 * Activity Action: Show settings for choosing wallpaper
1019 * <p>Input: Nothing.
1020 * <p>Output: Nothing.
1021 */
1022 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1023 public static final String ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
1024
1025 /**
1026 * Activity Action: Show activity for reporting a bug.
1027 * <p>Input: Nothing.
1028 * <p>Output: Nothing.
1029 */
1030 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1031 public static final String ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
1032
1033 /**
1034 * Activity Action: Main entry point for factory tests. Only used when
1035 * the device is booting in factory test node. The implementing package
1036 * must be installed in the system image.
1037 * <p>Input: nothing
1038 * <p>Output: nothing
1039 */
1040 public static final String ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
1041
1042 /**
1043 * Activity Action: The user pressed the "call" button to go to the dialer
1044 * or other appropriate UI for placing a call.
1045 * <p>Input: Nothing.
1046 * <p>Output: Nothing.
1047 */
1048 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1049 public static final String ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
1050
1051 /**
1052 * Activity Action: Start Voice Command.
1053 * <p>Input: Nothing.
1054 * <p>Output: Nothing.
1055 */
1056 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1057 public static final String ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001058
1059 /**
1060 * Activity Action: Start action associated with long pressing on the
1061 * search key.
1062 * <p>Input: Nothing.
1063 * <p>Output: Nothing.
1064 */
1065 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1066 public static final String ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";
The Android Open Source Project10592532009-03-18 17:39:46 -07001067
Jacek Surazski86b6c532009-05-13 14:38:28 +02001068 /**
1069 * Activity Action: The user pressed the "Report" button in the crash/ANR dialog.
1070 * This intent is delivered to the package which installed the application, usually
1071 * the Market.
1072 * <p>Input: No data is specified. The bug report is passed in using
1073 * an {@link #EXTRA_BUG_REPORT} field.
1074 * <p>Output: Nothing.
1075 * @hide
1076 */
1077 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1078 public static final String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
Dianne Hackborn3d74bb42009-06-19 10:35:21 -07001079
1080 /**
1081 * Activity Action: Show power usage information to the user.
1082 * <p>Input: Nothing.
1083 * <p>Output: Nothing.
1084 */
1085 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1086 public static final String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
1087
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07001088 /**
1089 * Activity Action: Setup wizard to launch after a platform update. This
1090 * activity should have a string meta-data field associated with it,
1091 * {@link #METADATA_SETUP_VERSION}, which defines the current version of
1092 * the platform for setup. The activity will be launched only if
1093 * {@link android.provider.Settings.Secure#LAST_SETUP_SHOWN} is not the
1094 * same value.
1095 * <p>Input: Nothing.
1096 * <p>Output: Nothing.
1097 * @hide
1098 */
1099 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1100 public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
1101
1102 /**
1103 * A string associated with a {@link #ACTION_UPGRADE_SETUP} activity
1104 * describing the last run version of the platform that was setup.
1105 * @hide
1106 */
1107 public static final String METADATA_SETUP_VERSION = "android.SETUP_VERSION";
1108
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001109 // ---------------------------------------------------------------------
1110 // ---------------------------------------------------------------------
1111 // Standard intent broadcast actions (see action variable).
1112
1113 /**
1114 * Broadcast Action: Sent after the screen turns off.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001115 *
1116 * <p class="note">This is a protected intent that can only be sent
1117 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001118 */
1119 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1120 public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
1121 /**
1122 * Broadcast Action: Sent after the screen turns on.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001123 *
1124 * <p class="note">This is a protected intent that can only be sent
1125 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001126 */
1127 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1128 public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001129
1130 /**
The Android Open Source Project10592532009-03-18 17:39:46 -07001131 * 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 -07001132 * keyguard is gone).
Dianne Hackborn854060af2009-07-09 18:14:31 -07001133 *
1134 * <p class="note">This is a protected intent that can only be sent
1135 * by the system.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001136 */
1137 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1138 public static final String ACTION_USER_PRESENT= "android.intent.action.USER_PRESENT";
1139
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001140 /**
1141 * Broadcast Action: The current time has changed. Sent every
1142 * minute. You can <em>not</em> receive this through components declared
1143 * in manifests, only by exlicitly registering for it with
1144 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1145 * Context.registerReceiver()}.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001146 *
1147 * <p class="note">This is a protected intent that can only be sent
1148 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001149 */
1150 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1151 public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
1152 /**
1153 * Broadcast Action: The time was set.
1154 */
1155 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1156 public static final String ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
1157 /**
1158 * Broadcast Action: The date has changed.
1159 */
1160 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1161 public static final String ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
1162 /**
1163 * Broadcast Action: The timezone has changed. The intent will have the following extra values:</p>
1164 * <ul>
1165 * <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time zone.</li>
1166 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001167 *
1168 * <p class="note">This is a protected intent that can only be sent
1169 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001170 */
1171 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1172 public static final String ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
1173 /**
1174 * Alarm Changed Action: This is broadcast when the AlarmClock
1175 * application's alarm is set or unset. It is used by the
1176 * AlarmClock application and the StatusBar service.
1177 * @hide
1178 */
1179 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1180 public static final String ACTION_ALARM_CHANGED = "android.intent.action.ALARM_CHANGED";
1181 /**
1182 * Sync State Changed Action: This is broadcast when the sync starts or stops or when one has
1183 * been failing for a long time. It is used by the SyncManager and the StatusBar service.
1184 * @hide
1185 */
1186 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1187 public static final String ACTION_SYNC_STATE_CHANGED
1188 = "android.intent.action.SYNC_STATE_CHANGED";
1189 /**
1190 * Broadcast Action: This is broadcast once, after the system has finished
1191 * booting. It can be used to perform application-specific initialization,
1192 * such as installing alarms. You must hold the
1193 * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
1194 * in order to receive this broadcast.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001195 *
1196 * <p class="note">This is a protected intent that can only be sent
1197 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001198 */
1199 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1200 public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
1201 /**
1202 * Broadcast Action: This is broadcast when a user action should request a
1203 * temporary system dialog to dismiss. Some examples of temporary system
1204 * dialogs are the notification window-shade and the recent tasks dialog.
1205 */
1206 public static final String ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
1207 /**
1208 * Broadcast Action: Trigger the download and eventual installation
1209 * of a package.
1210 * <p>Input: {@link #getData} is the URI of the package file to download.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001211 *
1212 * <p class="note">This is a protected intent that can only be sent
1213 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001214 */
1215 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1216 public static final String ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
1217 /**
1218 * Broadcast Action: A new application package has been installed on the
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001219 * device. The data contains the name of the package. Note that the
1220 * newly installed package does <em>not</em> receive this broadcast.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 * <p>My include the following extras:
1222 * <ul>
1223 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1224 * <li> {@link #EXTRA_REPLACING} is set to true if this is following
1225 * an {@link #ACTION_PACKAGE_REMOVED} broadcast for the same package.
1226 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001227 *
1228 * <p class="note">This is a protected intent that can only be sent
1229 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001230 */
1231 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1232 public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
1233 /**
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001234 * Broadcast Action: A new version of an application package has been
1235 * installed, replacing an existing version that was previously installed.
1236 * The data contains the name of the package.
1237 * <p>My include the following extras:
1238 * <ul>
1239 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
1240 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001241 *
1242 * <p class="note">This is a protected intent that can only be sent
1243 * by the system.
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001244 */
1245 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1246 public static final String ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
1247 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001248 * Broadcast Action: An existing application package has been removed from
1249 * the device. The data contains the name of the package. The package
1250 * that is being installed does <em>not</em> receive this Intent.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 * <ul>
1252 * <li> {@link #EXTRA_UID} containing the integer uid previously assigned
1253 * to the package.
1254 * <li> {@link #EXTRA_DATA_REMOVED} is set to true if the entire
1255 * application -- data and code -- is being removed.
1256 * <li> {@link #EXTRA_REPLACING} is set to true if this will be followed
1257 * by an {@link #ACTION_PACKAGE_ADDED} broadcast for the same package.
1258 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001259 *
1260 * <p class="note">This is a protected intent that can only be sent
1261 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001262 */
1263 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1264 public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
1265 /**
1266 * Broadcast Action: An existing application package has been changed (e.g. a component has been
1267 * enabled or disabled. The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 * <ul>
1269 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
Suchi Amalapurapu0214e942009-09-02 11:03:18 -07001270 * <li> {@link #EXTRA_CHANGED_COMPONENT_NAME} containing the class name of the changed component.
1271 * <li> {@link #EXTRA_DONT_KILL_APP} containing boolean field to override the default action of restarting the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001273 *
1274 * <p class="note">This is a protected intent that can only be sent
1275 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001276 */
1277 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1278 public static final String ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
1279 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 * Broadcast Action: The user has restarted a package, and all of its
1281 * processes have been killed. All runtime state
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001282 * associated with it (processes, alarms, notifications, etc) should
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001283 * be removed. Note that the restarted package does <em>not</em>
1284 * receive this broadcast.
1285 * The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 * <ul>
1287 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1288 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001289 *
1290 * <p class="note">This is a protected intent that can only be sent
1291 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001292 */
1293 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1294 public static final String ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
1295 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 * Broadcast Action: The user has cleared the data of a package. This should
1297 * be preceded by {@link #ACTION_PACKAGE_RESTARTED}, after which all of
The Android Open Source Projectc2ad2412009-03-19 23:08:54 -07001298 * its persistent data is erased and this broadcast sent.
1299 * Note that the cleared package does <em>not</em>
1300 * receive this broadcast. The data contains the name of the package.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 * <ul>
1302 * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package.
1303 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001304 *
1305 * <p class="note">This is a protected intent that can only be sent
1306 * by the system.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 */
1308 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1309 public static final String ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
1310 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001311 * Broadcast Action: A user ID has been removed from the system. The user
1312 * ID number is stored in the extra data under {@link #EXTRA_UID}.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001313 *
1314 * <p class="note">This is a protected intent that can only be sent
1315 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001316 */
1317 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1318 public static final String ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
1319 /**
1320 * Broadcast Action: The current system wallpaper has changed. See
1321 * {@link Context#getWallpaper} for retrieving the new wallpaper.
1322 */
1323 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1324 public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
1325 /**
1326 * Broadcast Action: The current device {@link android.content.res.Configuration}
1327 * (orientation, locale, etc) has changed. When such a change happens, the
1328 * UIs (view hierarchy) will need to be rebuilt based on this new
1329 * information; for the most part, applications don't need to worry about
1330 * this, because the system will take care of stopping and restarting the
1331 * application to make sure it sees the new changes. Some system code that
1332 * can not be restarted will need to watch for this action and handle it
1333 * appropriately.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001334 *
1335 * <p class="note">This is a protected intent that can only be sent
1336 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001337 *
1338 * @see android.content.res.Configuration
1339 */
1340 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1341 public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
1342 /**
1343 * Broadcast Action: The charging state, or charge level of the battery has
1344 * changed.
The Android Open Source Project10592532009-03-18 17:39:46 -07001345 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001346 * <p class="note">
1347 * You can <em>not</em> receive this through components declared
Dianne Hackborn854060af2009-07-09 18:14:31 -07001348 * in manifests, only by explicitly registering for it with
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001349 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
1350 * Context.registerReceiver()}.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001351 *
1352 * <p class="note">This is a protected intent that can only be sent
1353 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001354 */
1355 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1356 public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
1357 /**
1358 * Broadcast Action: Indicates low battery condition on the device.
1359 * This broadcast corresponds to the "Low battery warning" system dialog.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001360 *
1361 * <p class="note">This is a protected intent that can only be sent
1362 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001363 */
1364 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1365 public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
1366 /**
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001367 * Broadcast Action: Indicates the battery is now okay after being low.
1368 * This will be sent after {@link #ACTION_BATTERY_LOW} once the battery has
1369 * gone back up to an okay state.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001370 *
1371 * <p class="note">This is a protected intent that can only be sent
1372 * by the system.
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001373 */
1374 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1375 public static final String ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";
1376 /**
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001377 * Broadcast Action: External power has been connected to the device.
1378 * This is intended for applications that wish to register specifically to this notification.
1379 * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1380 * stay active to receive this notification. This action can be used to implement actions
1381 * that wait until power is available to trigger.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001382 *
1383 * <p class="note">This is a protected intent that can only be sent
1384 * by the system.
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001385 */
1386 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001387 public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001388 /**
1389 * Broadcast Action: External power has been removed from the device.
1390 * This is intended for applications that wish to register specifically to this notification.
1391 * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to
1392 * stay active to receive this notification. This action can be used to implement actions
Romain Guy4969af72009-06-17 10:53:19 -07001393 * that wait until power is available to trigger.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001394 *
1395 * <p class="note">This is a protected intent that can only be sent
1396 * by the system.
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001397 */
1398 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jean-Baptiste Queru1ef45642008-10-24 11:49:25 -07001399 public static final String ACTION_POWER_DISCONNECTED =
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001400 "android.intent.action.ACTION_POWER_DISCONNECTED";
Cliff Spradlinfda6fae2008-10-22 20:29:16 -07001401 /**
Dianne Hackborn55280a92009-05-07 15:53:46 -07001402 * Broadcast Action: Device is shutting down.
1403 * This is broadcast when the device is being shut down (completely turned
1404 * off, not sleeping). Once the broadcast is complete, the final shutdown
1405 * will proceed and all unsaved data lost. Apps will not normally need
Dianne Hackbornfe240ec2009-08-27 12:51:11 -07001406 * to handle this, since the foreground activity will be paused as well.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001407 *
1408 * <p class="note">This is a protected intent that can only be sent
1409 * by the system.
Dianne Hackborn55280a92009-05-07 15:53:46 -07001410 */
1411 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Romain Guy4969af72009-06-17 10:53:19 -07001412 public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
Dianne Hackborn55280a92009-05-07 15:53:46 -07001413 /**
Mike Lockwoodbad80e02009-07-30 01:21:08 -07001414 * Activity Action: Start this activity to request system shutdown.
1415 * The optional boolean extra field {@link #EXTRA_KEY_CONFIRM} can be set to true
1416 * to request confirmation from the user before shutting down.
1417 *
1418 * <p class="note">This is a protected intent that can only be sent
1419 * by the system.
1420 *
1421 * {@hide}
1422 */
1423 public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
1424 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001425 * Broadcast Action: Indicates low memory condition on the device
Dianne Hackborn854060af2009-07-09 18:14:31 -07001426 *
1427 * <p class="note">This is a protected intent that can only be sent
1428 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001429 */
1430 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1431 public static final String ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
1432 /**
1433 * Broadcast Action: Indicates low memory condition on the device no longer exists
Dianne Hackborn854060af2009-07-09 18:14:31 -07001434 *
1435 * <p class="note">This is a protected intent that can only be sent
1436 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001437 */
1438 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1439 public static final String ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
1440 /**
1441 * Broadcast Action: Indicates low memory condition notification acknowledged by user
1442 * and package management should be started.
1443 * This is triggered by the user from the ACTION_DEVICE_STORAGE_LOW
1444 * notification.
1445 */
1446 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1447 public static final String ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
1448 /**
1449 * Broadcast Action: The device has entered USB Mass Storage mode.
1450 * This is used mainly for the USB Settings panel.
1451 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1452 * when the SD card file system is mounted or unmounted
1453 */
1454 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1455 public static final String ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
1456
1457 /**
1458 * Broadcast Action: The device has exited USB Mass Storage mode.
1459 * This is used mainly for the USB Settings panel.
1460 * Apps should listen for ACTION_MEDIA_MOUNTED and ACTION_MEDIA_UNMOUNTED broadcasts to be notified
1461 * when the SD card file system is mounted or unmounted
1462 */
1463 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1464 public static final String ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
1465
1466 /**
1467 * Broadcast Action: External media has been removed.
1468 * The path to the mount point for the removed media is contained in the Intent.mData field.
1469 */
1470 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1471 public static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
1472
1473 /**
1474 * Broadcast Action: External media is present, but not mounted at its mount point.
1475 * The path to the mount point for the removed media is contained in the Intent.mData field.
1476 */
1477 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1478 public static final String ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
1479
1480 /**
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08001481 * Broadcast Action: External media is present, and being disk-checked
1482 * 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 -08001483 */
1484 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1485 public static final String ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
1486
1487 /**
1488 * Broadcast Action: External media is present, but is using an incompatible fs (or is blank)
1489 * 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 -08001490 */
1491 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1492 public static final String ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
1493
1494 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001495 * Broadcast Action: External media is present and mounted at its mount point.
1496 * The path to the mount point for the removed media is contained in the Intent.mData field.
1497 * The Intent contains an extra with name "read-only" and Boolean value to indicate if the
1498 * media was mounted read only.
1499 */
1500 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1501 public static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
1502
1503 /**
1504 * Broadcast Action: External media is unmounted because it is being shared via USB mass storage.
1505 * The path to the mount point for the removed media is contained in the Intent.mData field.
1506 */
1507 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1508 public static final String ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
1509
1510 /**
1511 * Broadcast Action: External media was removed from SD card slot, but mount point was not unmounted.
1512 * The path to the mount point for the removed media is contained in the Intent.mData field.
1513 */
1514 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1515 public static final String ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
1516
1517 /**
1518 * Broadcast Action: External media is present but cannot be mounted.
1519 * The path to the mount point for the removed media is contained in the Intent.mData field.
1520 */
1521 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1522 public static final String ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
1523
1524 /**
1525 * Broadcast Action: User has expressed the desire to remove the external storage media.
1526 * Applications should close all files they have open within the mount point when they receive this intent.
1527 * The path to the mount point for the media to be ejected is contained in the Intent.mData field.
1528 */
1529 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1530 public static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
1531
1532 /**
1533 * Broadcast Action: The media scanner has started scanning a directory.
1534 * The path to the directory being scanned is contained in the Intent.mData field.
1535 */
1536 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1537 public static final String ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
1538
1539 /**
1540 * Broadcast Action: The media scanner has finished scanning a directory.
1541 * The path to the scanned directory is contained in the Intent.mData field.
1542 */
1543 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1544 public static final String ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
1545
1546 /**
1547 * Broadcast Action: Request the media scanner to scan a file and add it to the media database.
1548 * The path to the file is contained in the Intent.mData field.
1549 */
1550 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1551 public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
1552
1553 /**
1554 * Broadcast Action: The "Media Button" was pressed. Includes a single
1555 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1556 * caused the broadcast.
1557 */
1558 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1559 public static final String ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
1560
1561 /**
1562 * Broadcast Action: The "Camera Button" was pressed. Includes a single
1563 * extra field, {@link #EXTRA_KEY_EVENT}, containing the key event that
1564 * caused the broadcast.
1565 */
1566 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1567 public static final String ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
1568
1569 // *** NOTE: @todo(*) The following really should go into a more domain-specific
1570 // location; they are not general-purpose actions.
1571
1572 /**
1573 * Broadcast Action: An GTalk connection has been established.
1574 */
1575 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1576 public static final String ACTION_GTALK_SERVICE_CONNECTED =
1577 "android.intent.action.GTALK_CONNECTED";
1578
1579 /**
1580 * Broadcast Action: An GTalk connection has been disconnected.
1581 */
1582 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1583 public static final String ACTION_GTALK_SERVICE_DISCONNECTED =
1584 "android.intent.action.GTALK_DISCONNECTED";
The Android Open Source Project10592532009-03-18 17:39:46 -07001585
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001586 /**
1587 * Broadcast Action: An input method has been changed.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001588 */
1589 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1590 public static final String ACTION_INPUT_METHOD_CHANGED =
1591 "android.intent.action.INPUT_METHOD_CHANGED";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001592
1593 /**
1594 * <p>Broadcast Action: The user has switched the phone into or out of Airplane Mode. One or
1595 * more radios have been turned off or on. The intent will have the following extra value:</p>
1596 * <ul>
1597 * <li><em>state</em> - A boolean value indicating whether Airplane Mode is on. If true,
1598 * then cell radio and possibly other radios such as bluetooth or WiFi may have also been
1599 * turned off</li>
1600 * </ul>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001601 *
1602 * <p class="note">This is a protected intent that can only be sent
1603 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001604 */
1605 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1606 public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
1607
1608 /**
1609 * Broadcast Action: Some content providers have parts of their namespace
1610 * where they publish new events or items that the user may be especially
1611 * interested in. For these things, they may broadcast this action when the
1612 * set of interesting items change.
1613 *
1614 * For example, GmailProvider sends this notification when the set of unread
1615 * mail in the inbox changes.
1616 *
1617 * <p>The data of the intent identifies which part of which provider
1618 * changed. When queried through the content resolver, the data URI will
1619 * return the data set in question.
1620 *
1621 * <p>The intent will have the following extra values:
1622 * <ul>
1623 * <li><em>count</em> - The number of items in the data set. This is the
1624 * same as the number of items in the cursor returned by querying the
1625 * data URI. </li>
1626 * </ul>
1627 *
1628 * This intent will be sent at boot (if the count is non-zero) and when the
1629 * data set changes. It is possible for the data set to change without the
1630 * count changing (for example, if a new unread message arrives in the same
1631 * sync operation in which a message is archived). The phone should still
1632 * ring/vibrate/etc as normal in this case.
1633 */
1634 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1635 public static final String ACTION_PROVIDER_CHANGED =
1636 "android.intent.action.PROVIDER_CHANGED";
1637
1638 /**
1639 * Broadcast Action: Wired Headset plugged in or unplugged.
1640 *
1641 * <p>The intent will have the following extra values:
1642 * <ul>
1643 * <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
1644 * <li><em>name</em> - Headset type, human readable string </li>
1645 * </ul>
1646 * </ul>
1647 */
1648 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1649 public static final String ACTION_HEADSET_PLUG =
1650 "android.intent.action.HEADSET_PLUG";
1651
1652 /**
1653 * Broadcast Action: An outgoing call is about to be placed.
1654 *
1655 * <p>The Intent will have the following extra value:
1656 * <ul>
The Android Open Source Project10592532009-03-18 17:39:46 -07001657 * <li><em>{@link android.content.Intent#EXTRA_PHONE_NUMBER}</em> -
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001658 * the phone number originally intended to be dialed.</li>
1659 * </ul>
1660 * <p>Once the broadcast is finished, the resultData is used as the actual
1661 * number to call. If <code>null</code>, no call will be placed.</p>
The Android Open Source Project10592532009-03-18 17:39:46 -07001662 * <p>It is perfectly acceptable for multiple receivers to process the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001663 * outgoing call in turn: for example, a parental control application
1664 * might verify that the user is authorized to place the call at that
1665 * time, then a number-rewriting application might add an area code if
1666 * one was not specified.</p>
1667 * <p>For consistency, any receiver whose purpose is to prohibit phone
1668 * calls should have a priority of 0, to ensure it will see the final
1669 * phone number to be dialed.
The Android Open Source Project10592532009-03-18 17:39:46 -07001670 * Any receiver whose purpose is to rewrite phone numbers to be called
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001671 * should have a positive priority.
1672 * Negative priorities are reserved for the system for this broadcast;
1673 * using them may cause problems.</p>
1674 * <p>Any BroadcastReceiver receiving this Intent <em>must not</em>
1675 * abort the broadcast.</p>
1676 * <p>Emergency calls cannot be intercepted using this mechanism, and
1677 * other calls cannot be modified to call emergency numbers using this
1678 * mechanism.
The Android Open Source Project10592532009-03-18 17:39:46 -07001679 * <p>You must hold the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001680 * {@link android.Manifest.permission#PROCESS_OUTGOING_CALLS}
1681 * permission to receive this Intent.</p>
Dianne Hackborn854060af2009-07-09 18:14:31 -07001682 *
1683 * <p class="note">This is a protected intent that can only be sent
1684 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001685 */
1686 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1687 public static final String ACTION_NEW_OUTGOING_CALL =
1688 "android.intent.action.NEW_OUTGOING_CALL";
1689
1690 /**
1691 * Broadcast Action: Have the device reboot. This is only for use by
1692 * system code.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001693 *
1694 * <p class="note">This is a protected intent that can only be sent
1695 * by the system.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001696 */
1697 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1698 public static final String ACTION_REBOOT =
1699 "android.intent.action.REBOOT";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700
Wei Huang97ecc9c2009-05-11 17:44:20 -07001701 /**
1702 * Broadcast Action: a remote intent is to be broadcasted.
1703 *
1704 * A remote intent is used for remote RPC between devices. The remote intent
1705 * is serialized and sent from one device to another device. The receiving
1706 * device parses the remote intent and broadcasts it. Note that anyone can
1707 * broadcast a remote intent. However, if the intent receiver of the remote intent
1708 * does not trust intent broadcasts from arbitrary intent senders, it should require
1709 * the sender to hold certain permissions so only trusted sender's broadcast will be
1710 * let through.
1711 */
1712 public static final String ACTION_REMOTE_INTENT =
1713 "android.intent.action.REMOTE_INTENT";
1714
Dianne Hackborn9acc0302009-08-25 00:27:12 -07001715 /**
1716 * Broadcast Action: hook for permforming cleanup after a system update.
1717 *
1718 * The broadcast is sent when the system is booting, before the
1719 * BOOT_COMPLETED broadcast. It is only sent to receivers in the system
1720 * image. A receiver for this should do its work and then disable itself
1721 * so that it does not get run again at the next boot.
1722 * @hide
1723 */
1724 public static final String ACTION_PRE_BOOT_COMPLETED =
1725 "android.intent.action.PRE_BOOT_COMPLETED";
1726
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001727 // ---------------------------------------------------------------------
1728 // ---------------------------------------------------------------------
1729 // Standard intent categories (see addCategory()).
1730
1731 /**
1732 * Set if the activity should be an option for the default action
1733 * (center press) to perform on a piece of data. Setting this will
1734 * hide from the user any activities without it set when performing an
1735 * action on some data. Note that this is normal -not- set in the
1736 * Intent when initiating an action -- it is for use in intent filters
1737 * specified in packages.
1738 */
1739 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1740 public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
1741 /**
1742 * Activities that can be safely invoked from a browser must support this
1743 * category. For example, if the user is viewing a web page or an e-mail
1744 * and clicks on a link in the text, the Intent generated execute that
1745 * link will require the BROWSABLE category, so that only activities
1746 * supporting this category will be considered as possible actions. By
1747 * supporting this category, you are promising that there is nothing
1748 * damaging (without user intervention) that can happen by invoking any
1749 * matching Intent.
1750 */
1751 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1752 public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
1753 /**
1754 * Set if the activity should be considered as an alternative action to
1755 * the data the user is currently viewing. See also
1756 * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
1757 * applies to the selection in a list of items.
1758 *
1759 * <p>Supporting this category means that you would like your activity to be
1760 * displayed in the set of alternative things the user can do, usually as
1761 * part of the current activity's options menu. You will usually want to
1762 * include a specific label in the &lt;intent-filter&gt; of this action
1763 * describing to the user what it does.
1764 *
1765 * <p>The action of IntentFilter with this category is important in that it
1766 * describes the specific action the target will perform. This generally
1767 * should not be a generic action (such as {@link #ACTION_VIEW}, but rather
1768 * a specific name such as "com.android.camera.action.CROP. Only one
1769 * alternative of any particular action will be shown to the user, so using
1770 * a specific action like this makes sure that your alternative will be
1771 * displayed while also allowing other applications to provide their own
1772 * overrides of that particular action.
1773 */
1774 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1775 public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
1776 /**
1777 * Set if the activity should be considered as an alternative selection
1778 * action to the data the user has currently selected. This is like
1779 * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list
1780 * of items from which the user can select, giving them alternatives to the
1781 * default action that will be performed on it.
1782 */
1783 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1784 public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
1785 /**
1786 * Intended to be used as a tab inside of an containing TabActivity.
1787 */
1788 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1789 public static final String CATEGORY_TAB = "android.intent.category.TAB";
1790 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001791 * Should be displayed in the top-level launcher.
1792 */
1793 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1794 public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
1795 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 * Provides information about the package it is in; typically used if
1797 * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
1798 * a front-door to the user without having to be shown in the all apps list.
1799 */
1800 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1801 public static final String CATEGORY_INFO = "android.intent.category.INFO";
1802 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001803 * This is the home activity, that is the first activity that is displayed
1804 * when the device boots.
1805 */
1806 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1807 public static final String CATEGORY_HOME = "android.intent.category.HOME";
1808 /**
1809 * This activity is a preference panel.
1810 */
1811 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1812 public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
1813 /**
1814 * This activity is a development preference panel.
1815 */
1816 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1817 public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
1818 /**
1819 * Capable of running inside a parent activity container.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001820 */
1821 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1822 public static final String CATEGORY_EMBED = "android.intent.category.EMBED";
1823 /**
1824 * This activity may be exercised by the monkey or other automated test tools.
1825 */
1826 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1827 public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY";
1828 /**
1829 * To be used as a test (not part of the normal user experience).
1830 */
1831 public static final String CATEGORY_TEST = "android.intent.category.TEST";
1832 /**
1833 * To be used as a unit test (run through the Test Harness).
1834 */
1835 public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
1836 /**
1837 * To be used as an sample code example (not part of the normal user
1838 * experience).
1839 */
1840 public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
1841 /**
1842 * Used to indicate that a GET_CONTENT intent only wants URIs that can be opened with
1843 * ContentResolver.openInputStream. Openable URIs must support the columns in OpenableColumns
1844 * when queried, though it is allowable for those columns to be blank.
1845 */
1846 @SdkConstant(SdkConstantType.INTENT_CATEGORY)
1847 public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
1848
1849 /**
1850 * To be used as code under test for framework instrumentation tests.
1851 */
1852 public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
1853 "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05001854
1855 /**
1856 * Broadcast Action: The phone was docked or undocked. Includes the extra
1857 * field {@link #EXTRA_DOCK_STATE}, containing the current dock state.
1858 * @hide
1859 */
1860 public static final String ACTION_DOCK_EVENT = "android.intent.action.DOCK_EVENT";
1861
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001862 // ---------------------------------------------------------------------
1863 // ---------------------------------------------------------------------
1864 // Standard extra data keys.
1865
1866 /**
1867 * The initial data to place in a newly created record. Use with
1868 * {@link #ACTION_INSERT}. The data here is a Map containing the same
1869 * fields as would be given to the underlying ContentProvider.insert()
1870 * call.
1871 */
1872 public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
1873
1874 /**
1875 * A constant CharSequence that is associated with the Intent, used with
1876 * {@link #ACTION_SEND} to supply the literal data to be sent. Note that
1877 * this may be a styled CharSequence, so you must use
1878 * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to
1879 * retrieve it.
1880 */
1881 public static final String EXTRA_TEXT = "android.intent.extra.TEXT";
1882
1883 /**
1884 * A content: URI holding a stream of data associated with the Intent,
1885 * used with {@link #ACTION_SEND} to supply the data being sent.
1886 */
1887 public static final String EXTRA_STREAM = "android.intent.extra.STREAM";
1888
1889 /**
1890 * A String[] holding e-mail addresses that should be delivered to.
1891 */
1892 public static final String EXTRA_EMAIL = "android.intent.extra.EMAIL";
1893
1894 /**
1895 * A String[] holding e-mail addresses that should be carbon copied.
1896 */
1897 public static final String EXTRA_CC = "android.intent.extra.CC";
1898
1899 /**
1900 * A String[] holding e-mail addresses that should be blind carbon copied.
1901 */
1902 public static final String EXTRA_BCC = "android.intent.extra.BCC";
1903
1904 /**
1905 * A constant string holding the desired subject line of a message.
1906 */
1907 public static final String EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
1908
1909 /**
1910 * An Intent describing the choices you would like shown with
1911 * {@link #ACTION_PICK_ACTIVITY}.
1912 */
1913 public static final String EXTRA_INTENT = "android.intent.extra.INTENT";
1914
1915 /**
1916 * A CharSequence dialog title to provide to the user when used with a
1917 * {@link #ACTION_CHOOSER}.
1918 */
1919 public static final String EXTRA_TITLE = "android.intent.extra.TITLE";
1920
1921 /**
1922 * A {@link android.view.KeyEvent} object containing the event that
1923 * triggered the creation of the Intent it is in.
1924 */
1925 public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
1926
1927 /**
Mike Lockwoodbad80e02009-07-30 01:21:08 -07001928 * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to request confirmation from the user
1929 * before shutting down.
1930 *
1931 * {@hide}
1932 */
1933 public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";
1934
1935 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001936 * Used as an boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
1937 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
1938 * of restarting the application.
1939 */
1940 public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP";
1941
1942 /**
1943 * A String holding the phone number originally entered in
1944 * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual
1945 * number to call in a {@link android.content.Intent#ACTION_CALL}.
1946 */
1947 public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
1948 /**
1949 * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED}
1950 * intents to supply the uid the package had been assigned. Also an optional
1951 * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
1952 * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same
1953 * purpose.
1954 */
1955 public static final String EXTRA_UID = "android.intent.extra.UID";
1956
1957 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
1959 * intents to indicate whether this represents a full uninstall (removing
1960 * both the code and its data) or a partial uninstall (leaving its data,
1961 * implying that this is an update).
1962 */
1963 public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
The Android Open Source Project10592532009-03-18 17:39:46 -07001964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 /**
1966 * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED}
1967 * intents to indicate that this is a replacement of the package, so this
1968 * broadcast will immediately be followed by an add broadcast for a
1969 * different version of the same package.
1970 */
1971 public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING";
The Android Open Source Project10592532009-03-18 17:39:46 -07001972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001974 * Used as an int extra field in {@link android.app.AlarmManager} intents
1975 * to tell the application being invoked how many pending alarms are being
1976 * delievered with the intent. For one-shot alarms this will always be 1.
1977 * For recurring alarms, this might be greater than 1 if the device was
1978 * asleep or powered off at the time an earlier alarm would have been
1979 * delivered.
1980 */
1981 public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT";
Romain Guy4969af72009-06-17 10:53:19 -07001982
Jacek Surazski86b6c532009-05-13 14:38:28 +02001983 /**
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05001984 * Used as an int extra field in {@link android.content.Intent#ACTION_DOCK_EVENT}
1985 * intents to request the dock state. Possible values are
Mike Lockwood725fcbf2009-08-24 13:09:20 -07001986 * {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
1987 * {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
1988 * {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}.
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05001989 * @hide
1990 */
1991 public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
1992
1993 /**
1994 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
1995 * to represent that the phone is not in any dock.
1996 * @hide
1997 */
1998 public static final int EXTRA_DOCK_STATE_UNDOCKED = 0;
1999
2000 /**
2001 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2002 * to represent that the phone is in a desk dock.
2003 * @hide
2004 */
2005 public static final int EXTRA_DOCK_STATE_DESK = 1;
2006
2007 /**
2008 * Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
2009 * to represent that the phone is in a car dock.
2010 * @hide
2011 */
2012 public static final int EXTRA_DOCK_STATE_CAR = 2;
2013
2014 /**
Jacek Surazski86b6c532009-05-13 14:38:28 +02002015 * Used as a parcelable extra field in {@link #ACTION_APP_ERROR}, containing
2016 * the bug report.
Romain Guy4969af72009-06-17 10:53:19 -07002017 *
Jacek Surazski86b6c532009-05-13 14:38:28 +02002018 * @hide
2019 */
2020 public static final String EXTRA_BUG_REPORT = "android.intent.extra.BUG_REPORT";
2021
2022 /**
Romain Guy4969af72009-06-17 10:53:19 -07002023 * Used as a string extra field when sending an intent to PackageInstaller to install a
Jacek Surazski86b6c532009-05-13 14:38:28 +02002024 * package. Specifies the installer package name; this package will receive the
2025 * {@link #ACTION_APP_ERROR} intent.
Romain Guy4969af72009-06-17 10:53:19 -07002026 *
Jacek Surazski86b6c532009-05-13 14:38:28 +02002027 * @hide
2028 */
Romain Guy4969af72009-06-17 10:53:19 -07002029 public static final String EXTRA_INSTALLER_PACKAGE_NAME
Jacek Surazski86b6c532009-05-13 14:38:28 +02002030 = "android.intent.extra.INSTALLER_PACKAGE_NAME";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002031
Wei Huang97ecc9c2009-05-11 17:44:20 -07002032 /**
2033 * Used in the extra field in the remote intent. It's astring token passed with the
2034 * remote intent.
2035 */
2036 public static final String EXTRA_REMOTE_INTENT_TOKEN =
2037 "android.intent.extra.remote_intent_token";
2038
Suchi Amalapurapu0214e942009-09-02 11:03:18 -07002039 /**
2040 * Used as an int extra field in {@link android.content.Intent#ACTION_PACKAGE_CHANGED}
2041 * intent to supply the name of the component that changed.
2042 * @hide
2043 */
2044 public static final String EXTRA_CHANGED_COMPONENT_NAME =
2045 "android.intent.extra.changed_component_name";
2046
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002047 // ---------------------------------------------------------------------
2048 // ---------------------------------------------------------------------
2049 // Intent flags (see mFlags variable).
2050
2051 /**
2052 * If set, the recipient of this Intent will be granted permission to
2053 * perform read operations on the Uri in the Intent's data.
2054 */
2055 public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
2056 /**
2057 * If set, the recipient of this Intent will be granted permission to
2058 * perform write operations on the Uri in the Intent's data.
2059 */
2060 public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
2061 /**
2062 * Can be set by the caller to indicate that this Intent is coming from
2063 * a background operation, not from direct user interaction.
2064 */
2065 public static final int FLAG_FROM_BACKGROUND = 0x00000004;
2066 /**
2067 * A flag you can enable for debugging: when set, log messages will be
2068 * printed during the resolution of this intent to show you what has
2069 * been found to create the final resolved list.
2070 */
2071 public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
2072
2073 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002074 * If set, the new activity is not kept in the history stack. As soon as
2075 * the user navigates away from it, the activity is finished. This may also
2076 * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
2077 * noHistory} attribute.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002078 */
2079 public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
2080 /**
2081 * If set, the activity will not be launched if it is already running
2082 * at the top of the history stack.
2083 */
2084 public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
2085 /**
2086 * If set, this activity will become the start of a new task on this
2087 * history stack. A task (from the activity that started it to the
2088 * next task activity) defines an atomic group of activities that the
2089 * user can move to. Tasks can be moved to the foreground and background;
2090 * all of the activities inside of a particular task always remain in
The Android Open Source Project10592532009-03-18 17:39:46 -07002091 * the same order. See
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 * <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2093 * Activities and Tasks</a> for more details on tasks.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002094 *
2095 * <p>This flag is generally used by activities that want
2096 * to present a "launcher" style behavior: they give the user a list of
2097 * separate things that can be done, which otherwise run completely
2098 * independently of the activity launching them.
2099 *
2100 * <p>When using this flag, if a task is already running for the activity
2101 * you are now starting, then a new activity will not be started; instead,
2102 * the current task will simply be brought to the front of the screen with
2103 * the state it was last in. See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag
2104 * to disable this behavior.
2105 *
2106 * <p>This flag can not be used when the caller is requesting a result from
2107 * the activity being launched.
2108 */
2109 public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
2110 /**
2111 * <strong>Do not use this flag unless you are implementing your own
2112 * top-level application launcher.</strong> Used in conjunction with
2113 * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the
2114 * behavior of bringing an existing task to the foreground. When set,
2115 * a new task is <em>always</em> started to host the Activity for the
2116 * Intent, regardless of whether there is already an existing task running
2117 * the same thing.
2118 *
2119 * <p><strong>Because the default system does not include graphical task management,
2120 * you should not use this flag unless you provide some way for a user to
2121 * return back to the tasks you have launched.</strong>
The Android Open Source Project10592532009-03-18 17:39:46 -07002122 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002123 * <p>This flag is ignored if
2124 * {@link #FLAG_ACTIVITY_NEW_TASK} is not set.
2125 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2127 * Activities and Tasks</a> for more details on tasks.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002128 */
2129 public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
2130 /**
2131 * If set, and the activity being launched is already running in the
2132 * current task, then instead of launching a new instance of that activity,
2133 * all of the other activities on top of it will be closed and this Intent
2134 * will be delivered to the (now on top) old activity as a new Intent.
2135 *
2136 * <p>For example, consider a task consisting of the activities: A, B, C, D.
2137 * If D calls startActivity() with an Intent that resolves to the component
2138 * of activity B, then C and D will be finished and B receive the given
2139 * Intent, resulting in the stack now being: A, B.
2140 *
Dianne Hackbornaa52f9a2009-08-25 16:01:15 -07002141 * <p>The currently running instance of activity B in the above example will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 * either receive the new intent you are starting here in its
2143 * onNewIntent() method, or be itself finished and restarted with the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002144 * new intent. If it has declared its launch mode to be "multiple" (the
Dianne Hackbornaa52f9a2009-08-25 16:01:15 -07002145 * default) and you have not set {@link #FLAG_ACTIVITY_SINGLE_TOP} in
2146 * the same intent, then it will be finished and re-created; for all other
2147 * launch modes or if {@link #FLAG_ACTIVITY_SINGLE_TOP} is set then this
2148 * Intent will be delivered to the current instance's onNewIntent().
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002149 *
2150 * <p>This launch mode can also be used to good effect in conjunction with
2151 * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity
2152 * of a task, it will bring any currently running instance of that task
2153 * to the foreground, and then clear it to its root state. This is
2154 * especially useful, for example, when launching an activity from the
2155 * notification manager.
2156 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 * <p>See <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
2158 * Activities and Tasks</a> for more details on tasks.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002159 */
2160 public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
2161 /**
2162 * If set and this intent is being used to launch a new activity from an
2163 * existing one, then the reply target of the existing activity will be
2164 * transfered to the new activity. This way the new activity can call
2165 * {@link android.app.Activity#setResult} and have that result sent back to
2166 * the reply target of the original activity.
2167 */
2168 public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
2169 /**
2170 * If set and this intent is being used to launch a new activity from an
2171 * existing one, the current activity will not be counted as the top
2172 * activity for deciding whether the new intent should be delivered to
2173 * the top instead of starting a new one. The previous activity will
2174 * be used as the top, with the assumption being that the current activity
2175 * will finish itself immediately.
2176 */
2177 public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
2178 /**
2179 * If set, the new activity is not kept in the list of recently launched
2180 * activities.
2181 */
2182 public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
2183 /**
2184 * This flag is not normally set by application code, but set for you by
2185 * the system as described in the
2186 * {@link android.R.styleable#AndroidManifestActivity_launchMode
2187 * launchMode} documentation for the singleTask mode.
2188 */
2189 public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
2190 /**
2191 * If set, and this activity is either being started in a new task or
2192 * bringing to the top an existing task, then it will be launched as
2193 * the front door of the task. This will result in the application of
2194 * any affinities needed to have that task in the proper state (either
2195 * moving activities to or from it), or simply resetting that task to
2196 * its initial state if needed.
2197 */
2198 public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
2199 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002200 * This flag is not normally set by application code, but set for you by
2201 * the system if this activity is being launched from history
2202 * (longpress home key).
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002203 */
2204 public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002205 /**
2206 * If set, this marks a point in the task's activity stack that should
2207 * be cleared when the task is reset. That is, the next time the task
Marco Nelissenc53fc4e2009-05-11 12:15:31 -07002208 * is brought to the foreground with
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002209 * {@link #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED} (typically as a result of
2210 * the user re-launching it from home), this activity and all on top of
2211 * it will be finished so that the user does not return to them, but
2212 * instead returns to whatever activity preceeded it.
The Android Open Source Project10592532009-03-18 17:39:46 -07002213 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002214 * <p>This is useful for cases where you have a logical break in your
2215 * application. For example, an e-mail application may have a command
2216 * to view an attachment, which launches an image view activity to
2217 * display it. This activity should be part of the e-mail application's
2218 * task, since it is a part of the task the user is involved in. However,
2219 * if the user leaves that task, and later selects the e-mail app from
2220 * home, we may like them to return to the conversation they were
2221 * viewing, not the picture attachment, since that is confusing. By
2222 * setting this flag when launching the image viewer, that viewer and
2223 * any activities it starts will be removed the next time the user returns
2224 * to mail.
2225 */
2226 public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002227 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint}
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002229 * callback from occurring on the current frontmost activity before it is
2230 * paused as the newly-started activity is brought to the front.
The Android Open Source Project10592532009-03-18 17:39:46 -07002231 *
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002232 * <p>Typically, an activity can rely on that callback to indicate that an
2233 * explicit user action has caused their activity to be moved out of the
2234 * foreground. The callback marks an appropriate point in the activity's
2235 * lifecycle for it to dismiss any notifications that it intends to display
2236 * "until the user has seen them," such as a blinking LED.
The Android Open Source Project10592532009-03-18 17:39:46 -07002237 *
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002238 * <p>If an activity is ever started via any non-user-driven events such as
2239 * phone-call receipt or an alarm handler, this flag should be passed to {@link
2240 * Context#startActivity Context.startActivity}, ensuring that the pausing
The Android Open Source Project10592532009-03-18 17:39:46 -07002241 * activity does not think the user has acknowledged its notification.
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08002242 */
2243 public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 /**
2245 * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
2246 * this flag will cause the launched activity to be brought to the front of its
2247 * task's history stack if it is already running.
The Android Open Source Project10592532009-03-18 17:39:46 -07002248 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 * <p>For example, consider a task consisting of four activities: A, B, C, D.
2250 * If D calls startActivity() with an Intent that resolves to the component
2251 * of activity B, then B will be brought to the front of the history stack,
2252 * with this resulting order: A, C, D, B.
The Android Open Source Project10592532009-03-18 17:39:46 -07002253 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also
The Android Open Source Project10592532009-03-18 17:39:46 -07002255 * specified.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 */
2257 public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002258 /**
2259 * If set, when sending a broadcast only registered receivers will be
2260 * called -- no BroadcastReceiver components will be launched.
2261 */
2262 public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 /**
2264 * If set, when sending a broadcast <i>before boot has completed</i> only
2265 * registered receivers will be called -- no BroadcastReceiver components
2266 * will be launched. Sticky intent state will be recorded properly even
2267 * if no receivers wind up being called. If {@link #FLAG_RECEIVER_REGISTERED_ONLY}
2268 * is specified in the broadcast intent, this flag is unnecessary.
The Android Open Source Project10592532009-03-18 17:39:46 -07002269 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 * <p>This flag is only for use by system sevices as a convenience to
2271 * avoid having to implement a more complex mechanism around detection
2272 * of boot completion.
The Android Open Source Project10592532009-03-18 17:39:46 -07002273 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002274 * @hide
2275 */
2276 public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x20000000;
Dianne Hackborn9acc0302009-08-25 00:27:12 -07002277 /**
2278 * Set when this broadcast is for a boot upgrade, a special mode that
2279 * allows the broadcast to be sent before the system is ready and launches
2280 * the app process with no providers running in it.
2281 * @hide
2282 */
2283 public static final int FLAG_RECEIVER_BOOT_UPGRADE = 0x10000000;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002284
2285 // ---------------------------------------------------------------------
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002286 // ---------------------------------------------------------------------
2287 // toUri() and parseUri() options.
2288
2289 /**
2290 * Flag for use with {@link #toUri} and {@link #parseUri}: the URI string
2291 * always has the "intent:" scheme. This syntax can be used when you want
2292 * to later disambiguate between URIs that are intended to describe an
2293 * Intent vs. all others that should be treated as raw URIs. When used
2294 * with {@link #parseUri}, any other scheme will result in a generic
2295 * VIEW action for that raw URI.
2296 */
2297 public static final int URI_INTENT_SCHEME = 1<<0;
2298
2299 // ---------------------------------------------------------------------
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002300
2301 private String mAction;
2302 private Uri mData;
2303 private String mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002304 private String mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002305 private ComponentName mComponent;
2306 private int mFlags;
2307 private HashSet<String> mCategories;
2308 private Bundle mExtras;
2309
2310 // ---------------------------------------------------------------------
2311
2312 /**
2313 * Create an empty intent.
2314 */
2315 public Intent() {
2316 }
2317
2318 /**
2319 * Copy constructor.
2320 */
2321 public Intent(Intent o) {
2322 this.mAction = o.mAction;
2323 this.mData = o.mData;
2324 this.mType = o.mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002325 this.mPackage = o.mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002326 this.mComponent = o.mComponent;
2327 this.mFlags = o.mFlags;
2328 if (o.mCategories != null) {
2329 this.mCategories = new HashSet<String>(o.mCategories);
2330 }
2331 if (o.mExtras != null) {
2332 this.mExtras = new Bundle(o.mExtras);
2333 }
2334 }
2335
2336 @Override
2337 public Object clone() {
2338 return new Intent(this);
2339 }
2340
2341 private Intent(Intent o, boolean all) {
2342 this.mAction = o.mAction;
2343 this.mData = o.mData;
2344 this.mType = o.mType;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002345 this.mPackage = o.mPackage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002346 this.mComponent = o.mComponent;
2347 if (o.mCategories != null) {
2348 this.mCategories = new HashSet<String>(o.mCategories);
2349 }
2350 }
2351
2352 /**
2353 * Make a clone of only the parts of the Intent that are relevant for
2354 * filter matching: the action, data, type, component, and categories.
2355 */
2356 public Intent cloneFilter() {
2357 return new Intent(this, false);
2358 }
2359
2360 /**
2361 * Create an intent with a given action. All other fields (data, type,
2362 * class) are null. Note that the action <em>must</em> be in a
2363 * namespace because Intents are used globally in the system -- for
2364 * example the system VIEW action is android.intent.action.VIEW; an
2365 * application's custom action would be something like
2366 * com.google.app.myapp.CUSTOM_ACTION.
2367 *
2368 * @param action The Intent action, such as ACTION_VIEW.
2369 */
2370 public Intent(String action) {
2371 mAction = action;
2372 }
2373
2374 /**
2375 * Create an intent with a given action and for a given data url. Note
2376 * that the action <em>must</em> be in a namespace because Intents are
2377 * used globally in the system -- for example the system VIEW action is
2378 * android.intent.action.VIEW; an application's custom action would be
2379 * something like com.google.app.myapp.CUSTOM_ACTION.
2380 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07002381 * <p><em>Note: scheme and host name matching in the Android framework is
2382 * case-sensitive, unlike the formal RFC. As a result,
2383 * you should always ensure that you write your Uri with these elements
2384 * using lower case letters, and normalize any Uris you receive from
2385 * outside of Android to ensure the scheme and host is lower case.</em></p>
2386 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002387 * @param action The Intent action, such as ACTION_VIEW.
2388 * @param uri The Intent data URI.
2389 */
2390 public Intent(String action, Uri uri) {
2391 mAction = action;
2392 mData = uri;
2393 }
2394
2395 /**
2396 * Create an intent for a specific component. All other fields (action, data,
2397 * type, class) are null, though they can be modified later with explicit
2398 * calls. This provides a convenient way to create an intent that is
2399 * intended to execute a hard-coded class name, rather than relying on the
2400 * system to find an appropriate class for you; see {@link #setComponent}
2401 * for more information on the repercussions of this.
2402 *
2403 * @param packageContext A Context of the application package implementing
2404 * this class.
2405 * @param cls The component class that is to be used for the intent.
2406 *
2407 * @see #setClass
2408 * @see #setComponent
2409 * @see #Intent(String, android.net.Uri , Context, Class)
2410 */
2411 public Intent(Context packageContext, Class<?> cls) {
2412 mComponent = new ComponentName(packageContext, cls);
2413 }
2414
2415 /**
2416 * Create an intent for a specific component with a specified action and data.
2417 * This is equivalent using {@link #Intent(String, android.net.Uri)} to
2418 * construct the Intent and then calling {@link #setClass} to set its
2419 * class.
2420 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07002421 * <p><em>Note: scheme and host name matching in the Android framework is
2422 * case-sensitive, unlike the formal RFC. As a result,
2423 * you should always ensure that you write your Uri with these elements
2424 * using lower case letters, and normalize any Uris you receive from
2425 * outside of Android to ensure the scheme and host is lower case.</em></p>
2426 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002427 * @param action The Intent action, such as ACTION_VIEW.
2428 * @param uri The Intent data URI.
2429 * @param packageContext A Context of the application package implementing
2430 * this class.
2431 * @param cls The component class that is to be used for the intent.
2432 *
2433 * @see #Intent(String, android.net.Uri)
2434 * @see #Intent(Context, Class)
2435 * @see #setClass
2436 * @see #setComponent
2437 */
2438 public Intent(String action, Uri uri,
2439 Context packageContext, Class<?> cls) {
2440 mAction = action;
2441 mData = uri;
2442 mComponent = new ComponentName(packageContext, cls);
2443 }
2444
2445 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002446 * Call {@link #parseUri} with 0 flags.
2447 * @deprecated Use {@link #parseUri} instead.
2448 */
2449 @Deprecated
2450 public static Intent getIntent(String uri) throws URISyntaxException {
2451 return parseUri(uri, 0);
2452 }
2453
2454 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002455 * Create an intent from a URI. This URI may encode the action,
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002456 * category, and other intent fields, if it was returned by
Dianne Hackborn7f205432009-07-28 00:13:47 -07002457 * {@link #toUri}. If the Intent was not generate by toUri(), its data
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002458 * will be the entire URI and its action will be ACTION_VIEW.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002459 *
2460 * <p>The URI given here must not be relative -- that is, it must include
2461 * the scheme and full path.
2462 *
2463 * @param uri The URI to turn into an Intent.
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002464 * @param flags Additional processing flags. Either 0 or
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002465 *
2466 * @return Intent The newly created Intent object.
2467 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002468 * @throws URISyntaxException Throws URISyntaxError if the basic URI syntax
2469 * it bad (as parsed by the Uri class) or the Intent data within the
2470 * URI is invalid.
2471 *
2472 * @see #toUri
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002473 */
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002474 public static Intent parseUri(String uri, int flags) throws URISyntaxException {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002475 int i = 0;
2476 try {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002477 // Validate intent scheme for if requested.
2478 if ((flags&URI_INTENT_SCHEME) != 0) {
2479 if (!uri.startsWith("intent:")) {
2480 Intent intent = new Intent(ACTION_VIEW);
2481 try {
2482 intent.setData(Uri.parse(uri));
2483 } catch (IllegalArgumentException e) {
2484 throw new URISyntaxException(uri, e.getMessage());
2485 }
2486 return intent;
2487 }
2488 }
2489
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002490 // simple case
2491 i = uri.lastIndexOf("#");
2492 if (i == -1) return new Intent(ACTION_VIEW, Uri.parse(uri));
2493
2494 // old format Intent URI
2495 if (!uri.startsWith("#Intent;", i)) return getIntentOld(uri);
The Android Open Source Project10592532009-03-18 17:39:46 -07002496
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002497 // new format
2498 Intent intent = new Intent(ACTION_VIEW);
2499
2500 // fetch data part, if present
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002501 String data = i >= 0 ? uri.substring(0, i) : null;
2502 String scheme = null;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002503 i += "#Intent;".length();
The Android Open Source Project10592532009-03-18 17:39:46 -07002504
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002505 // loop over contents of Intent, all name=value;
2506 while (!uri.startsWith("end", i)) {
2507 int eq = uri.indexOf('=', i);
2508 int semi = uri.indexOf(';', eq);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002509 String value = Uri.decode(uri.substring(eq + 1, semi));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002510
2511 // action
2512 if (uri.startsWith("action=", i)) {
2513 intent.mAction = value;
2514 }
2515
2516 // categories
2517 else if (uri.startsWith("category=", i)) {
2518 intent.addCategory(value);
2519 }
2520
2521 // type
2522 else if (uri.startsWith("type=", i)) {
2523 intent.mType = value;
2524 }
2525
2526 // launch flags
2527 else if (uri.startsWith("launchFlags=", i)) {
2528 intent.mFlags = Integer.decode(value).intValue();
2529 }
2530
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002531 // package
2532 else if (uri.startsWith("package=", i)) {
2533 intent.mPackage = value;
2534 }
2535
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002536 // component
2537 else if (uri.startsWith("component=", i)) {
2538 intent.mComponent = ComponentName.unflattenFromString(value);
2539 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002540
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002541 // scheme
2542 else if (uri.startsWith("scheme=", i)) {
2543 scheme = value;
2544 }
2545
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002546 // extra
2547 else {
2548 String key = Uri.decode(uri.substring(i + 2, eq));
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002549 // create Bundle if it doesn't already exist
2550 if (intent.mExtras == null) intent.mExtras = new Bundle();
2551 Bundle b = intent.mExtras;
2552 // add EXTRA
2553 if (uri.startsWith("S.", i)) b.putString(key, value);
2554 else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value));
2555 else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value));
2556 else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0));
2557 else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value));
2558 else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value));
2559 else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value));
2560 else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value));
2561 else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value));
2562 else throw new URISyntaxException(uri, "unknown EXTRA type", i);
2563 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002564
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002565 // move to the next item
2566 i = semi + 1;
2567 }
2568
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07002569 if (data != null) {
2570 if (data.startsWith("intent:")) {
2571 data = data.substring(7);
2572 if (scheme != null) {
2573 data = scheme + ':' + data;
2574 }
2575 }
2576
2577 if (data.length() > 0) {
2578 try {
2579 intent.mData = Uri.parse(data);
2580 } catch (IllegalArgumentException e) {
2581 throw new URISyntaxException(uri, e.getMessage());
2582 }
2583 }
2584 }
2585
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002586 return intent;
The Android Open Source Project10592532009-03-18 17:39:46 -07002587
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002588 } catch (IndexOutOfBoundsException e) {
2589 throw new URISyntaxException(uri, "illegal Intent URI format", i);
2590 }
2591 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002592
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002593 public static Intent getIntentOld(String uri) throws URISyntaxException {
2594 Intent intent;
2595
2596 int i = uri.lastIndexOf('#');
2597 if (i >= 0) {
2598 Uri data = null;
2599 String action = null;
2600 if (i > 0) {
2601 data = Uri.parse(uri.substring(0, i));
2602 }
2603
2604 i++;
2605
2606 if (uri.regionMatches(i, "action(", 0, 7)) {
2607 i += 7;
2608 int j = uri.indexOf(')', i);
2609 action = uri.substring(i, j);
2610 i = j + 1;
2611 }
2612
2613 intent = new Intent(action, data);
2614
2615 if (uri.regionMatches(i, "categories(", 0, 11)) {
2616 i += 11;
2617 int j = uri.indexOf(')', i);
2618 while (i < j) {
2619 int sep = uri.indexOf('!', i);
2620 if (sep < 0) sep = j;
2621 if (i < sep) {
2622 intent.addCategory(uri.substring(i, sep));
2623 }
2624 i = sep + 1;
2625 }
2626 i = j + 1;
2627 }
2628
2629 if (uri.regionMatches(i, "type(", 0, 5)) {
2630 i += 5;
2631 int j = uri.indexOf(')', i);
2632 intent.mType = uri.substring(i, j);
2633 i = j + 1;
2634 }
2635
2636 if (uri.regionMatches(i, "launchFlags(", 0, 12)) {
2637 i += 12;
2638 int j = uri.indexOf(')', i);
2639 intent.mFlags = Integer.decode(uri.substring(i, j)).intValue();
2640 i = j + 1;
2641 }
2642
2643 if (uri.regionMatches(i, "component(", 0, 10)) {
2644 i += 10;
2645 int j = uri.indexOf(')', i);
2646 int sep = uri.indexOf('!', i);
2647 if (sep >= 0 && sep < j) {
2648 String pkg = uri.substring(i, sep);
2649 String cls = uri.substring(sep + 1, j);
2650 intent.mComponent = new ComponentName(pkg, cls);
2651 }
2652 i = j + 1;
2653 }
2654
2655 if (uri.regionMatches(i, "extras(", 0, 7)) {
2656 i += 7;
The Android Open Source Project10592532009-03-18 17:39:46 -07002657
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002658 final int closeParen = uri.indexOf(')', i);
2659 if (closeParen == -1) throw new URISyntaxException(uri,
2660 "EXTRA missing trailing ')'", i);
2661
2662 while (i < closeParen) {
2663 // fetch the key value
2664 int j = uri.indexOf('=', i);
2665 if (j <= i + 1 || i >= closeParen) {
2666 throw new URISyntaxException(uri, "EXTRA missing '='", i);
2667 }
2668 char type = uri.charAt(i);
2669 i++;
2670 String key = uri.substring(i, j);
2671 i = j + 1;
The Android Open Source Project10592532009-03-18 17:39:46 -07002672
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002673 // get type-value
2674 j = uri.indexOf('!', i);
2675 if (j == -1 || j >= closeParen) j = closeParen;
2676 if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2677 String value = uri.substring(i, j);
2678 i = j;
2679
2680 // create Bundle if it doesn't already exist
2681 if (intent.mExtras == null) intent.mExtras = new Bundle();
The Android Open Source Project10592532009-03-18 17:39:46 -07002682
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002683 // add item to bundle
2684 try {
2685 switch (type) {
2686 case 'S':
2687 intent.mExtras.putString(key, Uri.decode(value));
2688 break;
2689 case 'B':
2690 intent.mExtras.putBoolean(key, Boolean.parseBoolean(value));
2691 break;
2692 case 'b':
2693 intent.mExtras.putByte(key, Byte.parseByte(value));
2694 break;
2695 case 'c':
2696 intent.mExtras.putChar(key, Uri.decode(value).charAt(0));
2697 break;
2698 case 'd':
2699 intent.mExtras.putDouble(key, Double.parseDouble(value));
2700 break;
2701 case 'f':
2702 intent.mExtras.putFloat(key, Float.parseFloat(value));
2703 break;
2704 case 'i':
2705 intent.mExtras.putInt(key, Integer.parseInt(value));
2706 break;
2707 case 'l':
2708 intent.mExtras.putLong(key, Long.parseLong(value));
2709 break;
2710 case 's':
2711 intent.mExtras.putShort(key, Short.parseShort(value));
2712 break;
2713 default:
2714 throw new URISyntaxException(uri, "EXTRA has unknown type", i);
2715 }
2716 } catch (NumberFormatException e) {
2717 throw new URISyntaxException(uri, "EXTRA value can't be parsed", i);
2718 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002719
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002720 char ch = uri.charAt(i);
2721 if (ch == ')') break;
2722 if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i);
2723 i++;
2724 }
2725 }
2726
2727 if (intent.mAction == null) {
2728 // By default, if no action is specified, then use VIEW.
2729 intent.mAction = ACTION_VIEW;
2730 }
2731
2732 } else {
2733 intent = new Intent(ACTION_VIEW, Uri.parse(uri));
2734 }
2735
2736 return intent;
2737 }
2738
2739 /**
2740 * Retrieve the general action to be performed, such as
2741 * {@link #ACTION_VIEW}. The action describes the general way the rest of
2742 * the information in the intent should be interpreted -- most importantly,
2743 * what to do with the data returned by {@link #getData}.
2744 *
2745 * @return The action of this intent or null if none is specified.
2746 *
2747 * @see #setAction
2748 */
2749 public String getAction() {
2750 return mAction;
2751 }
2752
2753 /**
2754 * Retrieve data this intent is operating on. This URI specifies the name
2755 * of the data; often it uses the content: scheme, specifying data in a
2756 * content provider. Other schemes may be handled by specific activities,
2757 * such as http: by the web browser.
2758 *
2759 * @return The URI of the data this intent is targeting or null.
2760 *
2761 * @see #getScheme
2762 * @see #setData
2763 */
2764 public Uri getData() {
2765 return mData;
2766 }
2767
2768 /**
2769 * The same as {@link #getData()}, but returns the URI as an encoded
2770 * String.
2771 */
2772 public String getDataString() {
2773 return mData != null ? mData.toString() : null;
2774 }
2775
2776 /**
2777 * Return the scheme portion of the intent's data. If the data is null or
2778 * does not include a scheme, null is returned. Otherwise, the scheme
2779 * prefix without the final ':' is returned, i.e. "http".
2780 *
2781 * <p>This is the same as calling getData().getScheme() (and checking for
2782 * null data).
2783 *
2784 * @return The scheme of this intent.
2785 *
2786 * @see #getData
2787 */
2788 public String getScheme() {
2789 return mData != null ? mData.getScheme() : null;
2790 }
2791
2792 /**
2793 * Retrieve any explicit MIME type included in the intent. This is usually
2794 * null, as the type is determined by the intent data.
2795 *
2796 * @return If a type was manually set, it is returned; else null is
2797 * returned.
2798 *
2799 * @see #resolveType(ContentResolver)
2800 * @see #setType
2801 */
2802 public String getType() {
2803 return mType;
2804 }
2805
2806 /**
2807 * Return the MIME data type of this intent. If the type field is
2808 * explicitly set, that is simply returned. Otherwise, if the data is set,
2809 * the type of that data is returned. If neither fields are set, a null is
2810 * returned.
2811 *
2812 * @return The MIME type of this intent.
2813 *
2814 * @see #getType
2815 * @see #resolveType(ContentResolver)
2816 */
2817 public String resolveType(Context context) {
2818 return resolveType(context.getContentResolver());
2819 }
2820
2821 /**
2822 * Return the MIME data type of this intent. If the type field is
2823 * explicitly set, that is simply returned. Otherwise, if the data is set,
2824 * the type of that data is returned. If neither fields are set, a null is
2825 * returned.
2826 *
2827 * @param resolver A ContentResolver that can be used to determine the MIME
2828 * type of the intent's data.
2829 *
2830 * @return The MIME type of this intent.
2831 *
2832 * @see #getType
2833 * @see #resolveType(Context)
2834 */
2835 public String resolveType(ContentResolver resolver) {
2836 if (mType != null) {
2837 return mType;
2838 }
2839 if (mData != null) {
2840 if ("content".equals(mData.getScheme())) {
2841 return resolver.getType(mData);
2842 }
2843 }
2844 return null;
2845 }
2846
2847 /**
2848 * Return the MIME data type of this intent, only if it will be needed for
2849 * intent resolution. This is not generally useful for application code;
2850 * it is used by the frameworks for communicating with back-end system
2851 * services.
2852 *
2853 * @param resolver A ContentResolver that can be used to determine the MIME
2854 * type of the intent's data.
2855 *
2856 * @return The MIME type of this intent, or null if it is unknown or not
2857 * needed.
2858 */
2859 public String resolveTypeIfNeeded(ContentResolver resolver) {
2860 if (mComponent != null) {
2861 return mType;
2862 }
2863 return resolveType(resolver);
2864 }
2865
2866 /**
2867 * Check if an category exists in the intent.
2868 *
2869 * @param category The category to check.
2870 *
2871 * @return boolean True if the intent contains the category, else false.
2872 *
2873 * @see #getCategories
2874 * @see #addCategory
2875 */
2876 public boolean hasCategory(String category) {
2877 return mCategories != null && mCategories.contains(category);
2878 }
2879
2880 /**
2881 * Return the set of all categories in the intent. If there are no categories,
2882 * returns NULL.
2883 *
2884 * @return Set The set of categories you can examine. Do not modify!
2885 *
2886 * @see #hasCategory
2887 * @see #addCategory
2888 */
2889 public Set<String> getCategories() {
2890 return mCategories;
2891 }
2892
2893 /**
2894 * Sets the ClassLoader that will be used when unmarshalling
2895 * any Parcelable values from the extras of this Intent.
2896 *
2897 * @param loader a ClassLoader, or null to use the default loader
2898 * at the time of unmarshalling.
2899 */
2900 public void setExtrasClassLoader(ClassLoader loader) {
2901 if (mExtras != null) {
2902 mExtras.setClassLoader(loader);
2903 }
2904 }
2905
2906 /**
2907 * Returns true if an extra value is associated with the given name.
2908 * @param name the extra's name
2909 * @return true if the given extra is present.
2910 */
2911 public boolean hasExtra(String name) {
2912 return mExtras != null && mExtras.containsKey(name);
2913 }
2914
2915 /**
2916 * Returns true if the Intent's extras contain a parcelled file descriptor.
2917 * @return true if the Intent contains a parcelled file descriptor.
2918 */
2919 public boolean hasFileDescriptors() {
2920 return mExtras != null && mExtras.hasFileDescriptors();
2921 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002922
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002923 /**
2924 * Retrieve extended data from the intent.
2925 *
2926 * @param name The name of the desired item.
2927 *
2928 * @return the value of an item that previously added with putExtra()
2929 * or null if none was found.
2930 *
2931 * @deprecated
2932 * @hide
2933 */
2934 @Deprecated
2935 public Object getExtra(String name) {
2936 return getExtra(name, null);
2937 }
2938
2939 /**
2940 * Retrieve extended data from the intent.
2941 *
2942 * @param name The name of the desired item.
2943 * @param defaultValue the value to be returned if no value of the desired
2944 * type is stored with the given name.
2945 *
2946 * @return the value of an item that previously added with putExtra()
2947 * or the default value if none was found.
2948 *
2949 * @see #putExtra(String, boolean)
2950 */
2951 public boolean getBooleanExtra(String name, boolean defaultValue) {
2952 return mExtras == null ? defaultValue :
2953 mExtras.getBoolean(name, defaultValue);
2954 }
2955
2956 /**
2957 * Retrieve extended data from the intent.
2958 *
2959 * @param name The name of the desired item.
2960 * @param defaultValue the value to be returned if no value of the desired
2961 * type is stored with the given name.
2962 *
2963 * @return the value of an item that previously added with putExtra()
2964 * or the default value if none was found.
2965 *
2966 * @see #putExtra(String, byte)
2967 */
2968 public byte getByteExtra(String name, byte defaultValue) {
2969 return mExtras == null ? defaultValue :
2970 mExtras.getByte(name, defaultValue);
2971 }
2972
2973 /**
2974 * Retrieve extended data from the intent.
2975 *
2976 * @param name The name of the desired item.
2977 * @param defaultValue the value to be returned if no value of the desired
2978 * type is stored with the given name.
2979 *
2980 * @return the value of an item that previously added with putExtra()
2981 * or the default value if none was found.
2982 *
2983 * @see #putExtra(String, short)
2984 */
2985 public short getShortExtra(String name, short defaultValue) {
2986 return mExtras == null ? defaultValue :
2987 mExtras.getShort(name, defaultValue);
2988 }
2989
2990 /**
2991 * Retrieve extended data from the intent.
2992 *
2993 * @param name The name of the desired item.
2994 * @param defaultValue the value to be returned if no value of the desired
2995 * type is stored with the given name.
2996 *
2997 * @return the value of an item that previously added with putExtra()
2998 * or the default value if none was found.
2999 *
3000 * @see #putExtra(String, char)
3001 */
3002 public char getCharExtra(String name, char defaultValue) {
3003 return mExtras == null ? defaultValue :
3004 mExtras.getChar(name, defaultValue);
3005 }
3006
3007 /**
3008 * Retrieve extended data from the intent.
3009 *
3010 * @param name The name of the desired item.
3011 * @param defaultValue the value to be returned if no value of the desired
3012 * type is stored with the given name.
3013 *
3014 * @return the value of an item that previously added with putExtra()
3015 * or the default value if none was found.
3016 *
3017 * @see #putExtra(String, int)
3018 */
3019 public int getIntExtra(String name, int defaultValue) {
3020 return mExtras == null ? defaultValue :
3021 mExtras.getInt(name, defaultValue);
3022 }
3023
3024 /**
3025 * Retrieve extended data from the intent.
3026 *
3027 * @param name The name of the desired item.
3028 * @param defaultValue the value to be returned if no value of the desired
3029 * type is stored with the given name.
3030 *
3031 * @return the value of an item that previously added with putExtra()
3032 * or the default value if none was found.
3033 *
3034 * @see #putExtra(String, long)
3035 */
3036 public long getLongExtra(String name, long defaultValue) {
3037 return mExtras == null ? defaultValue :
3038 mExtras.getLong(name, defaultValue);
3039 }
3040
3041 /**
3042 * Retrieve extended data from the intent.
3043 *
3044 * @param name The name of the desired item.
3045 * @param defaultValue the value to be returned if no value of the desired
3046 * type is stored with the given name.
3047 *
3048 * @return the value of an item that previously added with putExtra(),
3049 * or the default value if no such item is present
3050 *
3051 * @see #putExtra(String, float)
3052 */
3053 public float getFloatExtra(String name, float defaultValue) {
3054 return mExtras == null ? defaultValue :
3055 mExtras.getFloat(name, defaultValue);
3056 }
3057
3058 /**
3059 * Retrieve extended data from the intent.
3060 *
3061 * @param name The name of the desired item.
3062 * @param defaultValue the value to be returned if no value of the desired
3063 * type is stored with the given name.
3064 *
3065 * @return the value of an item that previously added with putExtra()
3066 * or the default value if none was found.
3067 *
3068 * @see #putExtra(String, double)
3069 */
3070 public double getDoubleExtra(String name, double defaultValue) {
3071 return mExtras == null ? defaultValue :
3072 mExtras.getDouble(name, defaultValue);
3073 }
3074
3075 /**
3076 * Retrieve extended data from the intent.
3077 *
3078 * @param name The name of the desired item.
3079 *
3080 * @return the value of an item that previously added with putExtra()
3081 * or null if no String value was found.
3082 *
3083 * @see #putExtra(String, String)
3084 */
3085 public String getStringExtra(String name) {
3086 return mExtras == null ? null : mExtras.getString(name);
3087 }
3088
3089 /**
3090 * Retrieve extended data from the intent.
3091 *
3092 * @param name The name of the desired item.
3093 *
3094 * @return the value of an item that previously added with putExtra()
3095 * or null if no CharSequence value was found.
3096 *
3097 * @see #putExtra(String, CharSequence)
3098 */
3099 public CharSequence getCharSequenceExtra(String name) {
3100 return mExtras == null ? null : mExtras.getCharSequence(name);
3101 }
3102
3103 /**
3104 * Retrieve extended data from the intent.
3105 *
3106 * @param name The name of the desired item.
3107 *
3108 * @return the value of an item that previously added with putExtra()
3109 * or null if no Parcelable value was found.
3110 *
3111 * @see #putExtra(String, Parcelable)
3112 */
3113 public <T extends Parcelable> T getParcelableExtra(String name) {
3114 return mExtras == null ? null : mExtras.<T>getParcelable(name);
3115 }
3116
3117 /**
3118 * Retrieve extended data from the intent.
3119 *
3120 * @param name The name of the desired item.
3121 *
3122 * @return the value of an item that previously added with putExtra()
3123 * or null if no Parcelable[] value was found.
3124 *
3125 * @see #putExtra(String, Parcelable[])
3126 */
3127 public Parcelable[] getParcelableArrayExtra(String name) {
3128 return mExtras == null ? null : mExtras.getParcelableArray(name);
3129 }
3130
3131 /**
3132 * Retrieve extended data from the intent.
3133 *
3134 * @param name The name of the desired item.
3135 *
3136 * @return the value of an item that previously added with putExtra()
3137 * or null if no ArrayList<Parcelable> value was found.
3138 *
3139 * @see #putParcelableArrayListExtra(String, ArrayList)
3140 */
3141 public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name) {
3142 return mExtras == null ? null : mExtras.<T>getParcelableArrayList(name);
3143 }
3144
3145 /**
3146 * Retrieve extended data from the intent.
3147 *
3148 * @param name The name of the desired item.
3149 *
3150 * @return the value of an item that previously added with putExtra()
3151 * or null if no Serializable value was found.
3152 *
3153 * @see #putExtra(String, Serializable)
3154 */
3155 public Serializable getSerializableExtra(String name) {
3156 return mExtras == null ? null : mExtras.getSerializable(name);
3157 }
3158
3159 /**
3160 * Retrieve extended data from the intent.
3161 *
3162 * @param name The name of the desired item.
3163 *
3164 * @return the value of an item that previously added with putExtra()
3165 * or null if no ArrayList<Integer> value was found.
3166 *
3167 * @see #putIntegerArrayListExtra(String, ArrayList)
3168 */
3169 public ArrayList<Integer> getIntegerArrayListExtra(String name) {
3170 return mExtras == null ? null : mExtras.getIntegerArrayList(name);
3171 }
3172
3173 /**
3174 * Retrieve extended data from the intent.
3175 *
3176 * @param name The name of the desired item.
3177 *
3178 * @return the value of an item that previously added with putExtra()
3179 * or null if no ArrayList<String> value was found.
3180 *
3181 * @see #putStringArrayListExtra(String, ArrayList)
3182 */
3183 public ArrayList<String> getStringArrayListExtra(String name) {
3184 return mExtras == null ? null : mExtras.getStringArrayList(name);
3185 }
3186
3187 /**
3188 * Retrieve extended data from the intent.
3189 *
3190 * @param name The name of the desired item.
3191 *
3192 * @return the value of an item that previously added with putExtra()
3193 * or null if no boolean array value was found.
3194 *
3195 * @see #putExtra(String, boolean[])
3196 */
3197 public boolean[] getBooleanArrayExtra(String name) {
3198 return mExtras == null ? null : mExtras.getBooleanArray(name);
3199 }
3200
3201 /**
3202 * Retrieve extended data from the intent.
3203 *
3204 * @param name The name of the desired item.
3205 *
3206 * @return the value of an item that previously added with putExtra()
3207 * or null if no byte array value was found.
3208 *
3209 * @see #putExtra(String, byte[])
3210 */
3211 public byte[] getByteArrayExtra(String name) {
3212 return mExtras == null ? null : mExtras.getByteArray(name);
3213 }
3214
3215 /**
3216 * Retrieve extended data from the intent.
3217 *
3218 * @param name The name of the desired item.
3219 *
3220 * @return the value of an item that previously added with putExtra()
3221 * or null if no short array value was found.
3222 *
3223 * @see #putExtra(String, short[])
3224 */
3225 public short[] getShortArrayExtra(String name) {
3226 return mExtras == null ? null : mExtras.getShortArray(name);
3227 }
3228
3229 /**
3230 * Retrieve extended data from the intent.
3231 *
3232 * @param name The name of the desired item.
3233 *
3234 * @return the value of an item that previously added with putExtra()
3235 * or null if no char array value was found.
3236 *
3237 * @see #putExtra(String, char[])
3238 */
3239 public char[] getCharArrayExtra(String name) {
3240 return mExtras == null ? null : mExtras.getCharArray(name);
3241 }
3242
3243 /**
3244 * Retrieve extended data from the intent.
3245 *
3246 * @param name The name of the desired item.
3247 *
3248 * @return the value of an item that previously added with putExtra()
3249 * or null if no int array value was found.
3250 *
3251 * @see #putExtra(String, int[])
3252 */
3253 public int[] getIntArrayExtra(String name) {
3254 return mExtras == null ? null : mExtras.getIntArray(name);
3255 }
3256
3257 /**
3258 * Retrieve extended data from the intent.
3259 *
3260 * @param name The name of the desired item.
3261 *
3262 * @return the value of an item that previously added with putExtra()
3263 * or null if no long array value was found.
3264 *
3265 * @see #putExtra(String, long[])
3266 */
3267 public long[] getLongArrayExtra(String name) {
3268 return mExtras == null ? null : mExtras.getLongArray(name);
3269 }
3270
3271 /**
3272 * Retrieve extended data from the intent.
3273 *
3274 * @param name The name of the desired item.
3275 *
3276 * @return the value of an item that previously added with putExtra()
3277 * or null if no float array value was found.
3278 *
3279 * @see #putExtra(String, float[])
3280 */
3281 public float[] getFloatArrayExtra(String name) {
3282 return mExtras == null ? null : mExtras.getFloatArray(name);
3283 }
3284
3285 /**
3286 * Retrieve extended data from the intent.
3287 *
3288 * @param name The name of the desired item.
3289 *
3290 * @return the value of an item that previously added with putExtra()
3291 * or null if no double array value was found.
3292 *
3293 * @see #putExtra(String, double[])
3294 */
3295 public double[] getDoubleArrayExtra(String name) {
3296 return mExtras == null ? null : mExtras.getDoubleArray(name);
3297 }
3298
3299 /**
3300 * Retrieve extended data from the intent.
3301 *
3302 * @param name The name of the desired item.
3303 *
3304 * @return the value of an item that previously added with putExtra()
3305 * or null if no String array value was found.
3306 *
3307 * @see #putExtra(String, String[])
3308 */
3309 public String[] getStringArrayExtra(String name) {
3310 return mExtras == null ? null : mExtras.getStringArray(name);
3311 }
3312
3313 /**
3314 * Retrieve extended data from the intent.
3315 *
3316 * @param name The name of the desired item.
3317 *
3318 * @return the value of an item that previously added with putExtra()
3319 * or null if no Bundle value was found.
3320 *
3321 * @see #putExtra(String, Bundle)
3322 */
3323 public Bundle getBundleExtra(String name) {
3324 return mExtras == null ? null : mExtras.getBundle(name);
3325 }
3326
3327 /**
3328 * Retrieve extended data from the intent.
3329 *
3330 * @param name The name of the desired item.
3331 *
3332 * @return the value of an item that previously added with putExtra()
3333 * or null if no IBinder value was found.
3334 *
3335 * @see #putExtra(String, IBinder)
3336 *
3337 * @deprecated
3338 * @hide
3339 */
3340 @Deprecated
3341 public IBinder getIBinderExtra(String name) {
3342 return mExtras == null ? null : mExtras.getIBinder(name);
3343 }
3344
3345 /**
3346 * Retrieve extended data from the intent.
3347 *
3348 * @param name The name of the desired item.
3349 * @param defaultValue The default value to return in case no item is
3350 * associated with the key 'name'
3351 *
3352 * @return the value of an item that previously added with putExtra()
3353 * or defaultValue if none was found.
3354 *
3355 * @see #putExtra
3356 *
3357 * @deprecated
3358 * @hide
3359 */
3360 @Deprecated
3361 public Object getExtra(String name, Object defaultValue) {
3362 Object result = defaultValue;
3363 if (mExtras != null) {
3364 Object result2 = mExtras.get(name);
3365 if (result2 != null) {
3366 result = result2;
3367 }
3368 }
3369
3370 return result;
3371 }
3372
3373 /**
3374 * Retrieves a map of extended data from the intent.
3375 *
3376 * @return the map of all extras previously added with putExtra(),
3377 * or null if none have been added.
3378 */
3379 public Bundle getExtras() {
3380 return (mExtras != null)
3381 ? new Bundle(mExtras)
3382 : null;
3383 }
3384
3385 /**
3386 * Retrieve any special flags associated with this intent. You will
3387 * normally just set them with {@link #setFlags} and let the system
3388 * take the appropriate action with them.
3389 *
3390 * @return int The currently set flags.
3391 *
3392 * @see #setFlags
3393 */
3394 public int getFlags() {
3395 return mFlags;
3396 }
3397
3398 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07003399 * Retrieve the application package name this Intent is limited to. When
3400 * resolving an Intent, if non-null this limits the resolution to only
3401 * components in the given application package.
3402 *
3403 * @return The name of the application package for the Intent.
3404 *
3405 * @see #resolveActivity
3406 * @see #setPackage
3407 */
3408 public String getPackage() {
3409 return mPackage;
3410 }
3411
3412 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003413 * Retrieve the concrete component associated with the intent. When receiving
3414 * an intent, this is the component that was found to best handle it (that is,
3415 * yourself) and will always be non-null; in all other cases it will be
3416 * null unless explicitly set.
3417 *
3418 * @return The name of the application component to handle the intent.
3419 *
3420 * @see #resolveActivity
3421 * @see #setComponent
3422 */
3423 public ComponentName getComponent() {
3424 return mComponent;
3425 }
3426
3427 /**
3428 * Return the Activity component that should be used to handle this intent.
3429 * The appropriate component is determined based on the information in the
3430 * intent, evaluated as follows:
3431 *
3432 * <p>If {@link #getComponent} returns an explicit class, that is returned
3433 * without any further consideration.
3434 *
3435 * <p>The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent
3436 * category to be considered.
3437 *
3438 * <p>If {@link #getAction} is non-NULL, the activity must handle this
3439 * action.
3440 *
3441 * <p>If {@link #resolveType} returns non-NULL, the activity must handle
3442 * this type.
3443 *
3444 * <p>If {@link #addCategory} has added any categories, the activity must
3445 * handle ALL of the categories specified.
3446 *
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07003447 * <p>If {@link #getPackage} is non-NULL, only activity components in
3448 * that application package will be considered.
3449 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003450 * <p>If there are no activities that satisfy all of these conditions, a
3451 * null string is returned.
3452 *
3453 * <p>If multiple activities are found to satisfy the intent, the one with
3454 * the highest priority will be used. If there are multiple activities
3455 * with the same priority, the system will either pick the best activity
3456 * based on user preference, or resolve to a system class that will allow
3457 * the user to pick an activity and forward from there.
3458 *
3459 * <p>This method is implemented simply by calling
3460 * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter
3461 * true.</p>
3462 * <p> This API is called for you as part of starting an activity from an
3463 * intent. You do not normally need to call it yourself.</p>
3464 *
3465 * @param pm The package manager with which to resolve the Intent.
3466 *
3467 * @return Name of the component implementing an activity that can
3468 * display the intent.
3469 *
3470 * @see #setComponent
3471 * @see #getComponent
3472 * @see #resolveActivityInfo
3473 */
3474 public ComponentName resolveActivity(PackageManager pm) {
3475 if (mComponent != null) {
3476 return mComponent;
3477 }
3478
3479 ResolveInfo info = pm.resolveActivity(
3480 this, PackageManager.MATCH_DEFAULT_ONLY);
3481 if (info != null) {
3482 return new ComponentName(
3483 info.activityInfo.applicationInfo.packageName,
3484 info.activityInfo.name);
3485 }
3486
3487 return null;
3488 }
3489
3490 /**
3491 * Resolve the Intent into an {@link ActivityInfo}
3492 * describing the activity that should execute the intent. Resolution
3493 * follows the same rules as described for {@link #resolveActivity}, but
3494 * you get back the completely information about the resolved activity
3495 * instead of just its class name.
3496 *
3497 * @param pm The package manager with which to resolve the Intent.
3498 * @param flags Addition information to retrieve as per
3499 * {@link PackageManager#getActivityInfo(ComponentName, int)
3500 * PackageManager.getActivityInfo()}.
3501 *
3502 * @return PackageManager.ActivityInfo
3503 *
3504 * @see #resolveActivity
3505 */
3506 public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) {
3507 ActivityInfo ai = null;
3508 if (mComponent != null) {
3509 try {
3510 ai = pm.getActivityInfo(mComponent, flags);
3511 } catch (PackageManager.NameNotFoundException e) {
3512 // ignore
3513 }
3514 } else {
3515 ResolveInfo info = pm.resolveActivity(
3516 this, PackageManager.MATCH_DEFAULT_ONLY);
3517 if (info != null) {
3518 ai = info.activityInfo;
3519 }
3520 }
3521
3522 return ai;
3523 }
3524
3525 /**
3526 * Set the general action to be performed.
3527 *
3528 * @param action An action name, such as ACTION_VIEW. Application-specific
3529 * actions should be prefixed with the vendor's package name.
3530 *
3531 * @return Returns the same Intent object, for chaining multiple calls
3532 * into a single statement.
3533 *
3534 * @see #getAction
3535 */
3536 public Intent setAction(String action) {
3537 mAction = action;
3538 return this;
3539 }
3540
3541 /**
3542 * Set the data this intent is operating on. This method automatically
3543 * clears any type that was previously set by {@link #setType}.
3544 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003545 * <p><em>Note: scheme and host name matching in the Android framework is
3546 * case-sensitive, unlike the formal RFC. As a result,
3547 * you should always ensure that you write your Uri with these elements
3548 * using lower case letters, and normalize any Uris you receive from
3549 * outside of Android to ensure the scheme and host is lower case.</em></p>
3550 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003551 * @param data The URI of the data this intent is now targeting.
3552 *
3553 * @return Returns the same Intent object, for chaining multiple calls
3554 * into a single statement.
3555 *
3556 * @see #getData
3557 * @see #setType
3558 * @see #setDataAndType
3559 */
3560 public Intent setData(Uri data) {
3561 mData = data;
3562 mType = null;
3563 return this;
3564 }
3565
3566 /**
3567 * Set an explicit MIME data type. This is used to create intents that
3568 * only specify a type and not data, for example to indicate the type of
3569 * data to return. This method automatically clears any data that was
3570 * previously set by {@link #setData}.
Romain Guy4969af72009-06-17 10:53:19 -07003571 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003572 * <p><em>Note: MIME type matching in the Android framework is
3573 * case-sensitive, unlike formal RFC MIME types. As a result,
3574 * you should always write your MIME types with lower case letters,
3575 * and any MIME types you receive from outside of Android should be
3576 * converted to lower case before supplying them here.</em></p>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003577 *
3578 * @param type The MIME type of the data being handled by this intent.
3579 *
3580 * @return Returns the same Intent object, for chaining multiple calls
3581 * into a single statement.
3582 *
3583 * @see #getType
3584 * @see #setData
3585 * @see #setDataAndType
3586 */
3587 public Intent setType(String type) {
3588 mData = null;
3589 mType = type;
3590 return this;
3591 }
3592
3593 /**
3594 * (Usually optional) Set the data for the intent along with an explicit
3595 * MIME data type. This method should very rarely be used -- it allows you
3596 * to override the MIME type that would ordinarily be inferred from the
3597 * data with your own type given here.
3598 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07003599 * <p><em>Note: MIME type, Uri scheme, and host name matching in the
3600 * Android framework is case-sensitive, unlike the formal RFC definitions.
3601 * As a result, you should always write these elements with lower case letters,
3602 * and normalize any MIME types or Uris you receive from
3603 * outside of Android to ensure these elements are lower case before
3604 * supplying them here.</em></p>
3605 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07003606 * @param data The URI of the data this intent is now targeting.
3607 * @param type The MIME type of the data being handled by this intent.
3608 *
3609 * @return Returns the same Intent object, for chaining multiple calls
3610 * into a single statement.
3611 *
3612 * @see #setData
3613 * @see #setType
3614 */
3615 public Intent setDataAndType(Uri data, String type) {
3616 mData = data;
3617 mType = type;
3618 return this;
3619 }
3620
3621 /**
3622 * Add a new category to the intent. Categories provide additional detail
3623 * about the action the intent is perform. When resolving an intent, only
3624 * activities that provide <em>all</em> of the requested categories will be
3625 * used.
3626 *
3627 * @param category The desired category. This can be either one of the
3628 * predefined Intent categories, or a custom category in your own
3629 * namespace.
3630 *
3631 * @return Returns the same Intent object, for chaining multiple calls
3632 * into a single statement.
3633 *
3634 * @see #hasCategory
3635 * @see #removeCategory
3636 */
3637 public Intent addCategory(String category) {
3638 if (mCategories == null) {
3639 mCategories = new HashSet<String>();
3640 }
3641 mCategories.add(category);
3642 return this;
3643 }
3644
3645 /**
3646 * Remove an category from an intent.
3647 *
3648 * @param category The category to remove.
3649 *
3650 * @see #addCategory
3651 */
3652 public void removeCategory(String category) {
3653 if (mCategories != null) {
3654 mCategories.remove(category);
3655 if (mCategories.size() == 0) {
3656 mCategories = null;
3657 }
3658 }
3659 }
3660
3661 /**
3662 * Add extended data to the intent. The name must include a package
3663 * prefix, for example the app com.android.contacts would use names
3664 * like "com.android.contacts.ShowAll".
3665 *
3666 * @param name The name of the extra data, with package prefix.
3667 * @param value The boolean data value.
3668 *
3669 * @return Returns the same Intent object, for chaining multiple calls
3670 * into a single statement.
3671 *
3672 * @see #putExtras
3673 * @see #removeExtra
3674 * @see #getBooleanExtra(String, boolean)
3675 */
3676 public Intent putExtra(String name, boolean value) {
3677 if (mExtras == null) {
3678 mExtras = new Bundle();
3679 }
3680 mExtras.putBoolean(name, value);
3681 return this;
3682 }
3683
3684 /**
3685 * Add extended data to the intent. The name must include a package
3686 * prefix, for example the app com.android.contacts would use names
3687 * like "com.android.contacts.ShowAll".
3688 *
3689 * @param name The name of the extra data, with package prefix.
3690 * @param value The byte data value.
3691 *
3692 * @return Returns the same Intent object, for chaining multiple calls
3693 * into a single statement.
3694 *
3695 * @see #putExtras
3696 * @see #removeExtra
3697 * @see #getByteExtra(String, byte)
3698 */
3699 public Intent putExtra(String name, byte value) {
3700 if (mExtras == null) {
3701 mExtras = new Bundle();
3702 }
3703 mExtras.putByte(name, value);
3704 return this;
3705 }
3706
3707 /**
3708 * Add extended data to the intent. The name must include a package
3709 * prefix, for example the app com.android.contacts would use names
3710 * like "com.android.contacts.ShowAll".
3711 *
3712 * @param name The name of the extra data, with package prefix.
3713 * @param value The char data value.
3714 *
3715 * @return Returns the same Intent object, for chaining multiple calls
3716 * into a single statement.
3717 *
3718 * @see #putExtras
3719 * @see #removeExtra
3720 * @see #getCharExtra(String, char)
3721 */
3722 public Intent putExtra(String name, char value) {
3723 if (mExtras == null) {
3724 mExtras = new Bundle();
3725 }
3726 mExtras.putChar(name, value);
3727 return this;
3728 }
3729
3730 /**
3731 * Add extended data to the intent. The name must include a package
3732 * prefix, for example the app com.android.contacts would use names
3733 * like "com.android.contacts.ShowAll".
3734 *
3735 * @param name The name of the extra data, with package prefix.
3736 * @param value The short data value.
3737 *
3738 * @return Returns the same Intent object, for chaining multiple calls
3739 * into a single statement.
3740 *
3741 * @see #putExtras
3742 * @see #removeExtra
3743 * @see #getShortExtra(String, short)
3744 */
3745 public Intent putExtra(String name, short value) {
3746 if (mExtras == null) {
3747 mExtras = new Bundle();
3748 }
3749 mExtras.putShort(name, value);
3750 return this;
3751 }
3752
3753 /**
3754 * Add extended data to the intent. The name must include a package
3755 * prefix, for example the app com.android.contacts would use names
3756 * like "com.android.contacts.ShowAll".
3757 *
3758 * @param name The name of the extra data, with package prefix.
3759 * @param value The integer data value.
3760 *
3761 * @return Returns the same Intent object, for chaining multiple calls
3762 * into a single statement.
3763 *
3764 * @see #putExtras
3765 * @see #removeExtra
3766 * @see #getIntExtra(String, int)
3767 */
3768 public Intent putExtra(String name, int value) {
3769 if (mExtras == null) {
3770 mExtras = new Bundle();
3771 }
3772 mExtras.putInt(name, value);
3773 return this;
3774 }
3775
3776 /**
3777 * Add extended data to the intent. The name must include a package
3778 * prefix, for example the app com.android.contacts would use names
3779 * like "com.android.contacts.ShowAll".
3780 *
3781 * @param name The name of the extra data, with package prefix.
3782 * @param value The long data value.
3783 *
3784 * @return Returns the same Intent object, for chaining multiple calls
3785 * into a single statement.
3786 *
3787 * @see #putExtras
3788 * @see #removeExtra
3789 * @see #getLongExtra(String, long)
3790 */
3791 public Intent putExtra(String name, long value) {
3792 if (mExtras == null) {
3793 mExtras = new Bundle();
3794 }
3795 mExtras.putLong(name, value);
3796 return this;
3797 }
3798
3799 /**
3800 * Add extended data to the intent. The name must include a package
3801 * prefix, for example the app com.android.contacts would use names
3802 * like "com.android.contacts.ShowAll".
3803 *
3804 * @param name The name of the extra data, with package prefix.
3805 * @param value The float data value.
3806 *
3807 * @return Returns the same Intent object, for chaining multiple calls
3808 * into a single statement.
3809 *
3810 * @see #putExtras
3811 * @see #removeExtra
3812 * @see #getFloatExtra(String, float)
3813 */
3814 public Intent putExtra(String name, float value) {
3815 if (mExtras == null) {
3816 mExtras = new Bundle();
3817 }
3818 mExtras.putFloat(name, value);
3819 return this;
3820 }
3821
3822 /**
3823 * Add extended data to the intent. The name must include a package
3824 * prefix, for example the app com.android.contacts would use names
3825 * like "com.android.contacts.ShowAll".
3826 *
3827 * @param name The name of the extra data, with package prefix.
3828 * @param value The double data value.
3829 *
3830 * @return Returns the same Intent object, for chaining multiple calls
3831 * into a single statement.
3832 *
3833 * @see #putExtras
3834 * @see #removeExtra
3835 * @see #getDoubleExtra(String, double)
3836 */
3837 public Intent putExtra(String name, double value) {
3838 if (mExtras == null) {
3839 mExtras = new Bundle();
3840 }
3841 mExtras.putDouble(name, value);
3842 return this;
3843 }
3844
3845 /**
3846 * Add extended data to the intent. The name must include a package
3847 * prefix, for example the app com.android.contacts would use names
3848 * like "com.android.contacts.ShowAll".
3849 *
3850 * @param name The name of the extra data, with package prefix.
3851 * @param value The String data value.
3852 *
3853 * @return Returns the same Intent object, for chaining multiple calls
3854 * into a single statement.
3855 *
3856 * @see #putExtras
3857 * @see #removeExtra
3858 * @see #getStringExtra(String)
3859 */
3860 public Intent putExtra(String name, String value) {
3861 if (mExtras == null) {
3862 mExtras = new Bundle();
3863 }
3864 mExtras.putString(name, value);
3865 return this;
3866 }
3867
3868 /**
3869 * Add extended data to the intent. The name must include a package
3870 * prefix, for example the app com.android.contacts would use names
3871 * like "com.android.contacts.ShowAll".
3872 *
3873 * @param name The name of the extra data, with package prefix.
3874 * @param value The CharSequence data value.
3875 *
3876 * @return Returns the same Intent object, for chaining multiple calls
3877 * into a single statement.
3878 *
3879 * @see #putExtras
3880 * @see #removeExtra
3881 * @see #getCharSequenceExtra(String)
3882 */
3883 public Intent putExtra(String name, CharSequence value) {
3884 if (mExtras == null) {
3885 mExtras = new Bundle();
3886 }
3887 mExtras.putCharSequence(name, value);
3888 return this;
3889 }
3890
3891 /**
3892 * Add extended data to the intent. The name must include a package
3893 * prefix, for example the app com.android.contacts would use names
3894 * like "com.android.contacts.ShowAll".
3895 *
3896 * @param name The name of the extra data, with package prefix.
3897 * @param value The Parcelable data value.
3898 *
3899 * @return Returns the same Intent object, for chaining multiple calls
3900 * into a single statement.
3901 *
3902 * @see #putExtras
3903 * @see #removeExtra
3904 * @see #getParcelableExtra(String)
3905 */
3906 public Intent putExtra(String name, Parcelable value) {
3907 if (mExtras == null) {
3908 mExtras = new Bundle();
3909 }
3910 mExtras.putParcelable(name, value);
3911 return this;
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 Parcelable[] 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 #getParcelableArrayExtra(String)
3928 */
3929 public Intent putExtra(String name, Parcelable[] value) {
3930 if (mExtras == null) {
3931 mExtras = new Bundle();
3932 }
3933 mExtras.putParcelableArray(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 ArrayList<Parcelable> 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 #getParcelableArrayListExtra(String)
3951 */
3952 public Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) {
3953 if (mExtras == null) {
3954 mExtras = new Bundle();
3955 }
3956 mExtras.putParcelableArrayList(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 ArrayList<Integer> 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 #getIntegerArrayListExtra(String)
3974 */
3975 public Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) {
3976 if (mExtras == null) {
3977 mExtras = new Bundle();
3978 }
3979 mExtras.putIntegerArrayList(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 ArrayList<String> 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 #getStringArrayListExtra(String)
3997 */
3998 public Intent putStringArrayListExtra(String name, ArrayList<String> value) {
3999 if (mExtras == null) {
4000 mExtras = new Bundle();
4001 }
4002 mExtras.putStringArrayList(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 Serializable 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 #getSerializableExtra(String)
4020 */
4021 public Intent putExtra(String name, Serializable value) {
4022 if (mExtras == null) {
4023 mExtras = new Bundle();
4024 }
4025 mExtras.putSerializable(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 boolean array 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 #getBooleanArrayExtra(String)
4043 */
4044 public Intent putExtra(String name, boolean[] value) {
4045 if (mExtras == null) {
4046 mExtras = new Bundle();
4047 }
4048 mExtras.putBooleanArray(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 byte array 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 #getByteArrayExtra(String)
4066 */
4067 public Intent putExtra(String name, byte[] value) {
4068 if (mExtras == null) {
4069 mExtras = new Bundle();
4070 }
4071 mExtras.putByteArray(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 short array 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 #getShortArrayExtra(String)
4089 */
4090 public Intent putExtra(String name, short[] value) {
4091 if (mExtras == null) {
4092 mExtras = new Bundle();
4093 }
4094 mExtras.putShortArray(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 char array 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 #getCharArrayExtra(String)
4112 */
4113 public Intent putExtra(String name, char[] value) {
4114 if (mExtras == null) {
4115 mExtras = new Bundle();
4116 }
4117 mExtras.putCharArray(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 int array 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 #getIntArrayExtra(String)
4135 */
4136 public Intent putExtra(String name, int[] value) {
4137 if (mExtras == null) {
4138 mExtras = new Bundle();
4139 }
4140 mExtras.putIntArray(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 byte array 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 #getLongArrayExtra(String)
4158 */
4159 public Intent putExtra(String name, long[] value) {
4160 if (mExtras == null) {
4161 mExtras = new Bundle();
4162 }
4163 mExtras.putLongArray(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 float array 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 #getFloatArrayExtra(String)
4181 */
4182 public Intent putExtra(String name, float[] value) {
4183 if (mExtras == null) {
4184 mExtras = new Bundle();
4185 }
4186 mExtras.putFloatArray(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 double array 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 #getDoubleArrayExtra(String)
4204 */
4205 public Intent putExtra(String name, double[] value) {
4206 if (mExtras == null) {
4207 mExtras = new Bundle();
4208 }
4209 mExtras.putDoubleArray(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 String array 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 #getStringArrayExtra(String)
4227 */
4228 public Intent putExtra(String name, String[] value) {
4229 if (mExtras == null) {
4230 mExtras = new Bundle();
4231 }
4232 mExtras.putStringArray(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 Bundle 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 #getBundleExtra(String)
4250 */
4251 public Intent putExtra(String name, Bundle value) {
4252 if (mExtras == null) {
4253 mExtras = new Bundle();
4254 }
4255 mExtras.putBundle(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 IBinder 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 #getIBinderExtra(String)
4273 *
4274 * @deprecated
4275 * @hide
4276 */
4277 @Deprecated
4278 public Intent putExtra(String name, IBinder value) {
4279 if (mExtras == null) {
4280 mExtras = new Bundle();
4281 }
4282 mExtras.putIBinder(name, value);
4283 return this;
4284 }
4285
4286 /**
4287 * Copy all extras in 'src' in to this intent.
4288 *
4289 * @param src Contains the extras to copy.
4290 *
4291 * @see #putExtra
4292 */
4293 public Intent putExtras(Intent src) {
4294 if (src.mExtras != null) {
4295 if (mExtras == null) {
4296 mExtras = new Bundle(src.mExtras);
4297 } else {
4298 mExtras.putAll(src.mExtras);
4299 }
4300 }
4301 return this;
4302 }
4303
4304 /**
4305 * Add a set of extended data to the intent. The keys must include a package
4306 * prefix, for example the app com.android.contacts would use names
4307 * like "com.android.contacts.ShowAll".
4308 *
4309 * @param extras The Bundle of extras to add to this intent.
4310 *
4311 * @see #putExtra
4312 * @see #removeExtra
4313 */
4314 public Intent putExtras(Bundle extras) {
4315 if (mExtras == null) {
4316 mExtras = new Bundle();
4317 }
4318 mExtras.putAll(extras);
4319 return this;
4320 }
4321
4322 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004323 * Completely replace the extras in the Intent with the extras in the
4324 * given Intent.
The Android Open Source Project10592532009-03-18 17:39:46 -07004325 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004326 * @param src The exact extras contained in this Intent are copied
4327 * into the target intent, replacing any that were previously there.
4328 */
4329 public Intent replaceExtras(Intent src) {
4330 mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null;
4331 return this;
4332 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004333
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004334 /**
4335 * Completely replace the extras in the Intent with the given Bundle of
4336 * extras.
The Android Open Source Project10592532009-03-18 17:39:46 -07004337 *
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004338 * @param extras The new set of extras in the Intent, or null to erase
4339 * all extras.
4340 */
4341 public Intent replaceExtras(Bundle extras) {
4342 mExtras = extras != null ? new Bundle(extras) : null;
4343 return this;
4344 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004345
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004346 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004347 * Remove extended data from the intent.
4348 *
4349 * @see #putExtra
4350 */
4351 public void removeExtra(String name) {
4352 if (mExtras != null) {
4353 mExtras.remove(name);
4354 if (mExtras.size() == 0) {
4355 mExtras = null;
4356 }
4357 }
4358 }
4359
4360 /**
4361 * Set special flags controlling how this intent is handled. Most values
4362 * here depend on the type of component being executed by the Intent,
4363 * specifically the FLAG_ACTIVITY_* flags are all for use with
4364 * {@link Context#startActivity Context.startActivity()} and the
4365 * FLAG_RECEIVER_* flags are all for use with
4366 * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.
4367 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 * <p>See the <a href="{@docRoot}guide/topics/fundamentals.html#acttask">Application Fundamentals:
4369 * 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 -07004370 * the behavior of your application.
4371 *
4372 * @param flags The desired flags.
4373 *
4374 * @return Returns the same Intent object, for chaining multiple calls
4375 * into a single statement.
4376 *
4377 * @see #getFlags
4378 * @see #addFlags
4379 *
4380 * @see #FLAG_GRANT_READ_URI_PERMISSION
4381 * @see #FLAG_GRANT_WRITE_URI_PERMISSION
4382 * @see #FLAG_DEBUG_LOG_RESOLUTION
4383 * @see #FLAG_FROM_BACKGROUND
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004384 * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004385 * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004386 * @see #FLAG_ACTIVITY_CLEAR_TOP
4387 * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
4388 * @see #FLAG_ACTIVITY_FORWARD_RESULT
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004389 * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004390 * @see #FLAG_ACTIVITY_MULTIPLE_TASK
4391 * @see #FLAG_ACTIVITY_NEW_TASK
4392 * @see #FLAG_ACTIVITY_NO_HISTORY
The Android Open Source Projectf1e484a2009-01-22 00:13:42 -08004393 * @see #FLAG_ACTIVITY_NO_USER_ACTION
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08004394 * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP
4395 * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004396 * @see #FLAG_ACTIVITY_SINGLE_TOP
4397 * @see #FLAG_RECEIVER_REGISTERED_ONLY
4398 */
4399 public Intent setFlags(int flags) {
4400 mFlags = flags;
4401 return this;
4402 }
4403
4404 /**
4405 * Add additional flags to the intent (or with existing flags
4406 * value).
4407 *
4408 * @param flags The new flags to set.
4409 *
4410 * @return Returns the same Intent object, for chaining multiple calls
4411 * into a single statement.
4412 *
4413 * @see #setFlags
4414 */
4415 public Intent addFlags(int flags) {
4416 mFlags |= flags;
4417 return this;
4418 }
4419
4420 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004421 * (Usually optional) Set an explicit application package name that limits
4422 * the components this Intent will resolve to. If left to the default
4423 * value of null, all components in all applications will considered.
4424 * If non-null, the Intent can only match the components in the given
4425 * application package.
4426 *
4427 * @param packageName The name of the application package to handle the
4428 * intent, or null to allow any application package.
4429 *
4430 * @return Returns the same Intent object, for chaining multiple calls
4431 * into a single statement.
4432 *
4433 * @see #getPackage
4434 * @see #resolveActivity
4435 */
4436 public Intent setPackage(String packageName) {
4437 mPackage = packageName;
4438 return this;
4439 }
4440
4441 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004442 * (Usually optional) Explicitly set the component to handle the intent.
4443 * If left with the default value of null, the system will determine the
4444 * appropriate class to use based on the other fields (action, data,
4445 * type, categories) in the Intent. If this class is defined, the
4446 * specified class will always be used regardless of the other fields. You
4447 * should only set this value when you know you absolutely want a specific
4448 * class to be used; otherwise it is better to let the system find the
4449 * appropriate class so that you will respect the installed applications
4450 * and user preferences.
4451 *
4452 * @param component The name of the application component to handle the
4453 * intent, or null to let the system find one for you.
4454 *
4455 * @return Returns the same Intent object, for chaining multiple calls
4456 * into a single statement.
4457 *
4458 * @see #setClass
4459 * @see #setClassName(Context, String)
4460 * @see #setClassName(String, String)
4461 * @see #getComponent
4462 * @see #resolveActivity
4463 */
4464 public Intent setComponent(ComponentName component) {
4465 mComponent = component;
4466 return this;
4467 }
4468
4469 /**
4470 * Convenience for calling {@link #setComponent} with an
4471 * explicit class name.
4472 *
4473 * @param packageContext A Context of the application package implementing
4474 * this class.
4475 * @param className The name of a class inside of the application package
4476 * that will be used as the component for this Intent.
4477 *
4478 * @return Returns the same Intent object, for chaining multiple calls
4479 * into a single statement.
4480 *
4481 * @see #setComponent
4482 * @see #setClass
4483 */
4484 public Intent setClassName(Context packageContext, String className) {
4485 mComponent = new ComponentName(packageContext, className);
4486 return this;
4487 }
4488
4489 /**
4490 * Convenience for calling {@link #setComponent} with an
4491 * explicit application package name and class name.
4492 *
4493 * @param packageName The name of the package implementing the desired
4494 * component.
4495 * @param className The name of a class inside of the application package
4496 * that will be used as the component for this Intent.
4497 *
4498 * @return Returns the same Intent object, for chaining multiple calls
4499 * into a single statement.
4500 *
4501 * @see #setComponent
4502 * @see #setClass
4503 */
4504 public Intent setClassName(String packageName, String className) {
4505 mComponent = new ComponentName(packageName, className);
4506 return this;
4507 }
4508
4509 /**
4510 * Convenience for calling {@link #setComponent(ComponentName)} with the
4511 * name returned by a {@link Class} object.
4512 *
4513 * @param packageContext A Context of the application package implementing
4514 * this class.
4515 * @param cls The class name to set, equivalent to
4516 * <code>setClassName(context, cls.getName())</code>.
4517 *
4518 * @return Returns the same Intent object, for chaining multiple calls
4519 * into a single statement.
4520 *
4521 * @see #setComponent
4522 */
4523 public Intent setClass(Context packageContext, Class<?> cls) {
4524 mComponent = new ComponentName(packageContext, cls);
4525 return this;
4526 }
4527
4528 /**
4529 * Use with {@link #fillIn} to allow the current action value to be
4530 * overwritten, even if it is already set.
4531 */
4532 public static final int FILL_IN_ACTION = 1<<0;
4533
4534 /**
4535 * Use with {@link #fillIn} to allow the current data or type value
4536 * overwritten, even if it is already set.
4537 */
4538 public static final int FILL_IN_DATA = 1<<1;
4539
4540 /**
4541 * Use with {@link #fillIn} to allow the current categories to be
4542 * overwritten, even if they are already set.
4543 */
4544 public static final int FILL_IN_CATEGORIES = 1<<2;
4545
4546 /**
4547 * Use with {@link #fillIn} to allow the current component value to be
4548 * overwritten, even if it is already set.
4549 */
4550 public static final int FILL_IN_COMPONENT = 1<<3;
4551
4552 /**
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004553 * Use with {@link #fillIn} to allow the current package value to be
4554 * overwritten, even if it is already set.
4555 */
4556 public static final int FILL_IN_PACKAGE = 1<<4;
4557
4558 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004559 * Copy the contents of <var>other</var> in to this object, but only
4560 * where fields are not defined by this object. For purposes of a field
4561 * being defined, the following pieces of data in the Intent are
4562 * considered to be separate fields:
4563 *
4564 * <ul>
4565 * <li> action, as set by {@link #setAction}.
4566 * <li> data URI and MIME type, as set by {@link #setData(Uri)},
4567 * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}.
4568 * <li> categories, as set by {@link #addCategory}.
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004569 * <li> package, as set by {@link #setPackage}.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004570 * <li> component, as set by {@link #setComponent(ComponentName)} or
4571 * related methods.
4572 * <li> each top-level name in the associated extras.
4573 * </ul>
4574 *
4575 * <p>In addition, you can use the {@link #FILL_IN_ACTION},
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004576 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
4577 * and {@link #FILL_IN_COMPONENT} to override the restriction where the
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004578 * corresponding field will not be replaced if it is already set.
4579 *
Brett Chabot3e391752009-07-21 16:07:23 -07004580 * <p>Note: The component field will only be copied if {@link #FILL_IN_COMPONENT} is explicitly
4581 * specified.
4582 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004583 * <p>For example, consider Intent A with {data="foo", categories="bar"}
4584 * and Intent B with {action="gotit", data-type="some/thing",
4585 * categories="one","two"}.
4586 *
4587 * <p>Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now
4588 * containing: {action="gotit", data-type="some/thing",
4589 * categories="bar"}.
4590 *
4591 * @param other Another Intent whose values are to be used to fill in
4592 * the current one.
4593 * @param flags Options to control which fields can be filled in.
4594 *
4595 * @return Returns a bit mask of {@link #FILL_IN_ACTION},
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004596 * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE},
4597 * and {@link #FILL_IN_COMPONENT} indicating which fields were changed.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004598 */
4599 public int fillIn(Intent other, int flags) {
4600 int changes = 0;
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004601 if (other.mAction != null
4602 && (mAction == null || (flags&FILL_IN_ACTION) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004603 mAction = other.mAction;
4604 changes |= FILL_IN_ACTION;
4605 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004606 if ((other.mData != null || other.mType != null)
4607 && ((mData == null && mType == null)
4608 || (flags&FILL_IN_DATA) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004609 mData = other.mData;
4610 mType = other.mType;
4611 changes |= FILL_IN_DATA;
4612 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004613 if (other.mCategories != null
4614 && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004615 if (other.mCategories != null) {
4616 mCategories = new HashSet<String>(other.mCategories);
4617 }
4618 changes |= FILL_IN_CATEGORIES;
4619 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004620 if (other.mPackage != null
4621 && (mPackage == null || (flags&FILL_IN_PACKAGE) != 0)) {
4622 mPackage = other.mPackage;
4623 changes |= FILL_IN_PACKAGE;
4624 }
4625 // Component is special: it can -only- be set if explicitly allowed,
4626 // since otherwise the sender could force the intent somewhere the
4627 // originator didn't intend.
4628 if (other.mComponent != null && (flags&FILL_IN_COMPONENT) != 0) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004629 mComponent = other.mComponent;
4630 changes |= FILL_IN_COMPONENT;
4631 }
4632 mFlags |= other.mFlags;
4633 if (mExtras == null) {
4634 if (other.mExtras != null) {
4635 mExtras = new Bundle(other.mExtras);
4636 }
4637 } else if (other.mExtras != null) {
4638 try {
4639 Bundle newb = new Bundle(other.mExtras);
4640 newb.putAll(mExtras);
4641 mExtras = newb;
4642 } catch (RuntimeException e) {
4643 // Modifying the extras can cause us to unparcel the contents
4644 // of the bundle, and if we do this in the system process that
4645 // may fail. We really should handle this (i.e., the Bundle
4646 // impl shouldn't be on top of a plain map), but for now just
4647 // ignore it and keep the original contents. :(
4648 Log.w("Intent", "Failure filling in extras", e);
4649 }
4650 }
4651 return changes;
4652 }
4653
4654 /**
4655 * Wrapper class holding an Intent and implementing comparisons on it for
4656 * the purpose of filtering. The class implements its
4657 * {@link #equals equals()} and {@link #hashCode hashCode()} methods as
4658 * simple calls to {@link Intent#filterEquals(Intent)} filterEquals()} and
4659 * {@link android.content.Intent#filterHashCode()} filterHashCode()}
4660 * on the wrapped Intent.
4661 */
4662 public static final class FilterComparison {
4663 private final Intent mIntent;
4664 private final int mHashCode;
4665
4666 public FilterComparison(Intent intent) {
4667 mIntent = intent;
4668 mHashCode = intent.filterHashCode();
4669 }
4670
4671 /**
4672 * Return the Intent that this FilterComparison represents.
4673 * @return Returns the Intent held by the FilterComparison. Do
4674 * not modify!
4675 */
4676 public Intent getIntent() {
4677 return mIntent;
4678 }
4679
4680 @Override
4681 public boolean equals(Object obj) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 if (obj instanceof FilterComparison) {
4683 Intent other = ((FilterComparison)obj).mIntent;
4684 return mIntent.filterEquals(other);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 return false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004687 }
4688
4689 @Override
4690 public int hashCode() {
4691 return mHashCode;
4692 }
4693 }
4694
4695 /**
4696 * Determine if two intents are the same for the purposes of intent
4697 * resolution (filtering). That is, if their action, data, type,
4698 * class, and categories are the same. This does <em>not</em> compare
4699 * any extra data included in the intents.
4700 *
4701 * @param other The other Intent to compare against.
4702 *
4703 * @return Returns true if action, data, type, class, and categories
4704 * are the same.
4705 */
4706 public boolean filterEquals(Intent other) {
4707 if (other == null) {
4708 return false;
4709 }
4710 if (mAction != other.mAction) {
4711 if (mAction != null) {
4712 if (!mAction.equals(other.mAction)) {
4713 return false;
4714 }
4715 } else {
4716 if (!other.mAction.equals(mAction)) {
4717 return false;
4718 }
4719 }
4720 }
4721 if (mData != other.mData) {
4722 if (mData != null) {
4723 if (!mData.equals(other.mData)) {
4724 return false;
4725 }
4726 } else {
4727 if (!other.mData.equals(mData)) {
4728 return false;
4729 }
4730 }
4731 }
4732 if (mType != other.mType) {
4733 if (mType != null) {
4734 if (!mType.equals(other.mType)) {
4735 return false;
4736 }
4737 } else {
4738 if (!other.mType.equals(mType)) {
4739 return false;
4740 }
4741 }
4742 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004743 if (mPackage != other.mPackage) {
4744 if (mPackage != null) {
4745 if (!mPackage.equals(other.mPackage)) {
4746 return false;
4747 }
4748 } else {
4749 if (!other.mPackage.equals(mPackage)) {
4750 return false;
4751 }
4752 }
4753 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004754 if (mComponent != other.mComponent) {
4755 if (mComponent != null) {
4756 if (!mComponent.equals(other.mComponent)) {
4757 return false;
4758 }
4759 } else {
4760 if (!other.mComponent.equals(mComponent)) {
4761 return false;
4762 }
4763 }
4764 }
4765 if (mCategories != other.mCategories) {
4766 if (mCategories != null) {
4767 if (!mCategories.equals(other.mCategories)) {
4768 return false;
4769 }
4770 } else {
4771 if (!other.mCategories.equals(mCategories)) {
4772 return false;
4773 }
4774 }
4775 }
4776
4777 return true;
4778 }
4779
4780 /**
4781 * Generate hash code that matches semantics of filterEquals().
4782 *
4783 * @return Returns the hash value of the action, data, type, class, and
4784 * categories.
4785 *
4786 * @see #filterEquals
4787 */
4788 public int filterHashCode() {
4789 int code = 0;
4790 if (mAction != null) {
4791 code += mAction.hashCode();
4792 }
4793 if (mData != null) {
4794 code += mData.hashCode();
4795 }
4796 if (mType != null) {
4797 code += mType.hashCode();
4798 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004799 if (mPackage != null) {
4800 code += mPackage.hashCode();
4801 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004802 if (mComponent != null) {
4803 code += mComponent.hashCode();
4804 }
4805 if (mCategories != null) {
4806 code += mCategories.hashCode();
4807 }
4808 return code;
4809 }
4810
4811 @Override
4812 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004813 StringBuilder b = new StringBuilder(128);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004814
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004815 b.append("Intent { ");
4816 toShortString(b, true, true);
4817 b.append(" }");
4818
4819 return b.toString();
4820 }
4821
4822 /** @hide */
4823 public String toShortString(boolean comp, boolean extras) {
4824 StringBuilder b = new StringBuilder(128);
4825 toShortString(b, comp, extras);
4826 return b.toString();
4827 }
Romain Guy4969af72009-06-17 10:53:19 -07004828
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004829 /** @hide */
4830 public void toShortString(StringBuilder b, boolean comp, boolean extras) {
4831 boolean first = true;
4832 if (mAction != null) {
4833 b.append("act=").append(mAction);
4834 first = false;
4835 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004836 if (mCategories != null) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004837 if (!first) {
4838 b.append(' ');
4839 }
4840 first = false;
4841 b.append("cat=[");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004842 Iterator<String> i = mCategories.iterator();
4843 boolean didone = false;
4844 while (i.hasNext()) {
4845 if (didone) b.append(",");
4846 didone = true;
4847 b.append(i.next());
4848 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004849 b.append("]");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004850 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004851 if (mData != null) {
4852 if (!first) {
4853 b.append(' ');
4854 }
4855 first = false;
4856 b.append("dat=").append(mData);
4857 }
4858 if (mType != null) {
4859 if (!first) {
4860 b.append(' ');
4861 }
4862 first = false;
4863 b.append("typ=").append(mType);
4864 }
4865 if (mFlags != 0) {
4866 if (!first) {
4867 b.append(' ');
4868 }
4869 first = false;
4870 b.append("flg=0x").append(Integer.toHexString(mFlags));
4871 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004872 if (mPackage != null) {
4873 if (!first) {
4874 b.append(' ');
4875 }
4876 first = false;
4877 b.append("pkg=").append(mPackage);
4878 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004879 if (comp && mComponent != null) {
4880 if (!first) {
4881 b.append(' ');
4882 }
4883 first = false;
4884 b.append("cmp=").append(mComponent.flattenToShortString());
4885 }
4886 if (extras && mExtras != null) {
4887 if (!first) {
4888 b.append(' ');
4889 }
4890 first = false;
4891 b.append("(has extras)");
4892 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004893 }
4894
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004895 /**
4896 * Call {@link #toUri} with 0 flags.
4897 * @deprecated Use {@link #toUri} instead.
4898 */
4899 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004900 public String toURI() {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004901 return toUri(0);
4902 }
4903
4904 /**
4905 * Convert this Intent into a String holding a URI representation of it.
4906 * The returned URI string has been properly URI encoded, so it can be
4907 * used with {@link Uri#parse Uri.parse(String)}. The URI contains the
4908 * Intent's data as the base URI, with an additional fragment describing
4909 * the action, categories, type, flags, package, component, and extras.
4910 *
4911 * <p>You can convert the returned string back to an Intent with
4912 * {@link #getIntent}.
4913 *
4914 * @param flags Additional operating flags. Either 0 or
4915 * {@link #URI_INTENT_SCHEME}.
4916 *
4917 * @return Returns a URI encoding URI string describing the entire contents
4918 * of the Intent.
4919 */
4920 public String toUri(int flags) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004921 StringBuilder uri = new StringBuilder(128);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004922 String scheme = null;
4923 if (mData != null) {
4924 String data = mData.toString();
4925 if ((flags&URI_INTENT_SCHEME) != 0) {
4926 final int N = data.length();
4927 for (int i=0; i<N; i++) {
4928 char c = data.charAt(i);
4929 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
4930 || c == '.' || c == '-') {
4931 continue;
4932 }
4933 if (c == ':' && i > 0) {
4934 // Valid scheme.
4935 scheme = data.substring(0, i);
4936 uri.append("intent:");
4937 data = data.substring(i+1);
4938 break;
4939 }
4940
4941 // No scheme.
4942 break;
4943 }
4944 }
4945 uri.append(data);
4946
4947 } else if ((flags&URI_INTENT_SCHEME) != 0) {
4948 uri.append("intent:");
4949 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004950
4951 uri.append("#Intent;");
4952
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004953 if (scheme != null) {
4954 uri.append("scheme=").append(scheme).append(';');
4955 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004956 if (mAction != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004957 uri.append("action=").append(Uri.encode(mAction)).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004958 }
4959 if (mCategories != null) {
4960 for (String category : mCategories) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004961 uri.append("category=").append(Uri.encode(category)).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004962 }
4963 }
4964 if (mType != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004965 uri.append("type=").append(Uri.encode(mType, "/")).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004966 }
4967 if (mFlags != 0) {
4968 uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
4969 }
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004970 if (mPackage != null) {
4971 uri.append("package=").append(Uri.encode(mPackage)).append(';');
4972 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004973 if (mComponent != null) {
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07004974 uri.append("component=").append(Uri.encode(
4975 mComponent.flattenToShortString(), "/")).append(';');
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07004976 }
4977 if (mExtras != null) {
4978 for (String key : mExtras.keySet()) {
4979 final Object value = mExtras.get(key);
4980 char entryType =
4981 value instanceof String ? 'S' :
4982 value instanceof Boolean ? 'B' :
4983 value instanceof Byte ? 'b' :
4984 value instanceof Character ? 'c' :
4985 value instanceof Double ? 'd' :
4986 value instanceof Float ? 'f' :
4987 value instanceof Integer ? 'i' :
4988 value instanceof Long ? 'l' :
4989 value instanceof Short ? 's' :
4990 '\0';
4991
4992 if (entryType != '\0') {
4993 uri.append(entryType);
4994 uri.append('.');
4995 uri.append(Uri.encode(key));
4996 uri.append('=');
4997 uri.append(Uri.encode(value.toString()));
4998 uri.append(';');
4999 }
5000 }
5001 }
The Android Open Source Project10592532009-03-18 17:39:46 -07005002
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005003 uri.append("end");
5004
5005 return uri.toString();
5006 }
The Android Open Source Project10592532009-03-18 17:39:46 -07005007
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005008 public int describeContents() {
5009 return (mExtras != null) ? mExtras.describeContents() : 0;
5010 }
5011
5012 public void writeToParcel(Parcel out, int flags) {
5013 out.writeString(mAction);
5014 Uri.writeToParcel(out, mData);
5015 out.writeString(mType);
5016 out.writeInt(mFlags);
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005017 out.writeString(mPackage);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005018 ComponentName.writeToParcel(mComponent, out);
5019
5020 if (mCategories != null) {
5021 out.writeInt(mCategories.size());
5022 for (String category : mCategories) {
5023 out.writeString(category);
5024 }
5025 } else {
5026 out.writeInt(0);
5027 }
5028
5029 out.writeBundle(mExtras);
5030 }
5031
5032 public static final Parcelable.Creator<Intent> CREATOR
5033 = new Parcelable.Creator<Intent>() {
5034 public Intent createFromParcel(Parcel in) {
5035 return new Intent(in);
5036 }
5037 public Intent[] newArray(int size) {
5038 return new Intent[size];
5039 }
5040 };
5041
5042 private Intent(Parcel in) {
5043 readFromParcel(in);
5044 }
5045
5046 public void readFromParcel(Parcel in) {
5047 mAction = in.readString();
5048 mData = Uri.CREATOR.createFromParcel(in);
5049 mType = in.readString();
5050 mFlags = in.readInt();
Dianne Hackbornc14b9cc2009-06-17 18:02:12 -07005051 mPackage = in.readString();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005052 mComponent = ComponentName.readFromParcel(in);
5053
5054 int N = in.readInt();
5055 if (N > 0) {
5056 mCategories = new HashSet<String>();
5057 int i;
5058 for (i=0; i<N; i++) {
5059 mCategories.add(in.readString());
5060 }
5061 } else {
5062 mCategories = null;
5063 }
5064
5065 mExtras = in.readBundle();
5066 }
5067
5068 /**
5069 * Parses the "intent" element (and its children) from XML and instantiates
5070 * an Intent object. The given XML parser should be located at the tag
5071 * where parsing should start (often named "intent"), from which the
5072 * basic action, data, type, and package and class name will be
5073 * retrieved. The function will then parse in to any child elements,
5074 * looking for <category android:name="xxx"> tags to add categories and
5075 * <extra android:name="xxx" android:value="yyy"> to attach extra data
5076 * to the intent.
5077 *
5078 * @param resources The Resources to use when inflating resources.
5079 * @param parser The XML parser pointing at an "intent" tag.
5080 * @param attrs The AttributeSet interface for retrieving extended
5081 * attribute data at the current <var>parser</var> location.
5082 * @return An Intent object matching the XML data.
5083 * @throws XmlPullParserException If there was an XML parsing error.
5084 * @throws IOException If there was an I/O error.
5085 */
5086 public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
5087 throws XmlPullParserException, IOException {
5088 Intent intent = new Intent();
5089
5090 TypedArray sa = resources.obtainAttributes(attrs,
5091 com.android.internal.R.styleable.Intent);
5092
5093 intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action));
5094
5095 String data = sa.getString(com.android.internal.R.styleable.Intent_data);
5096 String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType);
5097 intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType);
5098
5099 String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage);
5100 String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass);
5101 if (packageName != null && className != null) {
5102 intent.setComponent(new ComponentName(packageName, className));
5103 }
5104
5105 sa.recycle();
5106
5107 int outerDepth = parser.getDepth();
5108 int type;
5109 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
5110 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
5111 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
5112 continue;
5113 }
5114
5115 String nodeName = parser.getName();
5116 if (nodeName.equals("category")) {
5117 sa = resources.obtainAttributes(attrs,
5118 com.android.internal.R.styleable.IntentCategory);
5119 String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name);
5120 sa.recycle();
5121
5122 if (cat != null) {
5123 intent.addCategory(cat);
5124 }
5125 XmlUtils.skipCurrentTag(parser);
5126
5127 } else if (nodeName.equals("extra")) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08005128 if (intent.mExtras == null) {
5129 intent.mExtras = new Bundle();
5130 }
5131 resources.parseBundleExtra("extra", attrs, intent.mExtras);
5132 XmlUtils.skipCurrentTag(parser);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005133
5134 } else {
5135 XmlUtils.skipCurrentTag(parser);
5136 }
5137 }
5138
5139 return intent;
5140 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07005141}