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