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