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