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