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