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