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