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