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