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