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