Projects >> android-frameworks-base >>bd3e0ce5a288d75e5e420f52da31c34be59063f4

Chunk
Conflicting content
            "android.intent.action.CHECK_TTS_DATA";

    /**
<<<<<<< HEAD
     * Broadcast Action: a remote intent is to be broadcasted.
     *
     * A remote intent is used for remote RPC between devices. The remote intent
     * is serialized and sent from one device to another device. The receiving
     * device parses the remote intent and broadcasts it. Note that anyone can
     * broadcast a remote intent. However, if the intent receiver of the remote intent
     * does not trust intent broadcasts from arbitrary intent senders, it should require
     * the sender to hold certain permissions so only trusted sender's broadcast will be
     * let through.
     */
    public static final String ACTION_REMOTE_INTENT =
            "android.intent.action.REMOTE_INTENT";

    /**
     * @hide
     * TODO: This will be unhidden in a later CL.
=======
>>>>>>> 3e522c45b2fad6ae0256e00ae54ac1e68e29e508
     * Broadcast Action: The TextToSpeech synthesizer has completed processing 
     * all of the text in the speech queue.
     */
Solution content
            "android.intent.action.CHECK_TTS_DATA";

    /**
     * Broadcast Action: The TextToSpeech synthesizer has completed processing 
     * all of the text in the speech queue.
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_TTS_QUEUE_PROCESSING_COMPLETED =
            "android.intent.action.TTS_QUEUE_PROCESSING_COMPLETED";

    /**
     * Broadcast Action: a remote intent is to be broadcasted.
     *
     * A remote intent is used for remote RPC between devices. The remote intent
     * is serialized and sent from one device to another device. The receiving
     * device parses the remote intent and broadcasts it. Note that anyone can
     * broadcast a remote intent. However, if the intent receiver of the remote intent
     * does not trust intent broadcasts from arbitrary intent senders, it should require
     * the sender to hold certain permissions so only trusted sender's broadcast will be
     * let through.
     */
    public static final String ACTION_REMOTE_INTENT =
            "android.intent.action.REMOTE_INTENT";

    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // Standard intent categories (see addCategory()).

    /**
     * Set if the activity should be an option for the default action
     * (center press) to perform on a piece of data.  Setting this will
     * hide from the user any activities without it set when performing an
     * action on some data.  Note that this is normal -not- set in the
     * Intent when initiating an action -- it is for use in intent filters
     * specified in packages.
     */
    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
    public static final String CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
    /**
     * Activities that can be safely invoked from a browser must support this
     * category.  For example, if the user is viewing a web page or an e-mail
     * and clicks on a link in the text, the Intent generated execute that
     * link will require the BROWSABLE category, so that only activities
     * supporting this category will be considered as possible actions.  By
     * supporting this category, you are promising that there is nothing
     * damaging (without user intervention) that can happen by invoking any
     * matching Intent.
     */
    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
    public static final String CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
    /**
     * Set if the activity should be considered as an alternative action to
     * the data the user is currently viewing.  See also
     * {@link #CATEGORY_SELECTED_ALTERNATIVE} for an alternative action that
     * applies to the selection in a list of items.
     *
     * 

Supporting this category means that you would like your activity to be * displayed in the set of alternative things the user can do, usually as * part of the current activity's options menu. You will usually want to * include a specific label in the <intent-filter> of this action * describing to the user what it does. * *

The action of IntentFilter with this category is important in that it * describes the specific action the target will perform. This generally * should not be a generic action (such as {@link #ACTION_VIEW}, but rather * a specific name such as "com.android.camera.action.CROP. Only one * alternative of any particular action will be shown to the user, so using * a specific action like this makes sure that your alternative will be * displayed while also allowing other applications to provide their own * overrides of that particular action. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE"; /** * Set if the activity should be considered as an alternative selection * action to the data the user has currently selected. This is like * {@link #CATEGORY_ALTERNATIVE}, but is used in activities showing a list * of items from which the user can select, giving them alternatives to the * default action that will be performed on it. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE"; /** * Intended to be used as a tab inside of an containing TabActivity. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_TAB = "android.intent.category.TAB"; /** * Should be displayed in the top-level launcher. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER"; /** * Provides information about the package it is in; typically used if * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide * a front-door to the user without having to be shown in the all apps list. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_INFO = "android.intent.category.INFO"; /** * This is the home activity, that is the first activity that is displayed * when the device boots. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_HOME = "android.intent.category.HOME"; /** * This activity is a preference panel. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE"; /** * This activity is a development preference panel. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE"; /** * Capable of running inside a parent activity container. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_EMBED = "android.intent.category.EMBED"; /** * This activity may be exercised by the monkey or other automated test tools. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_MONKEY = "android.intent.category.MONKEY"; /** * To be used as a test (not part of the normal user experience). */ public static final String CATEGORY_TEST = "android.intent.category.TEST"; /** * To be used as a unit test (run through the Test Harness). */ public static final String CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST"; /** * To be used as an sample code example (not part of the normal user * experience). */ public static final String CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE"; /** * Used to indicate that a GET_CONTENT intent only wants URIs that can be opened with * ContentResolver.openInputStream. Openable URIs must support the columns in OpenableColumns * when queried, though it is allowable for those columns to be blank. */ @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_OPENABLE = "android.intent.category.OPENABLE"; /** * To be used as code under test for framework instrumentation tests. */ public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST = "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST"; // --------------------------------------------------------------------- // --------------------------------------------------------------------- // Standard extra data keys. /** * The initial data to place in a newly created record. Use with * {@link #ACTION_INSERT}. The data here is a Map containing the same * fields as would be given to the underlying ContentProvider.insert() * call. */ public static final String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE"; /** * A constant CharSequence that is associated with the Intent, used with * {@link #ACTION_SEND} to supply the literal data to be sent. Note that * this may be a styled CharSequence, so you must use * {@link Bundle#getCharSequence(String) Bundle.getCharSequence()} to * retrieve it. */ public static final String EXTRA_TEXT = "android.intent.extra.TEXT"; /** * A content: URI holding a stream of data associated with the Intent, * used with {@link #ACTION_SEND} to supply the data being sent. */ public static final String EXTRA_STREAM = "android.intent.extra.STREAM"; /** * A String[] holding e-mail addresses that should be delivered to. */ public static final String EXTRA_EMAIL = "android.intent.extra.EMAIL"; /** * A String[] holding e-mail addresses that should be carbon copied. */ public static final String EXTRA_CC = "android.intent.extra.CC"; /** * A String[] holding e-mail addresses that should be blind carbon copied. */ public static final String EXTRA_BCC = "android.intent.extra.BCC"; /** * A constant string holding the desired subject line of a message. */ public static final String EXTRA_SUBJECT = "android.intent.extra.SUBJECT"; /** * An Intent describing the choices you would like shown with * {@link #ACTION_PICK_ACTIVITY}. */ public static final String EXTRA_INTENT = "android.intent.extra.INTENT"; /** * A CharSequence dialog title to provide to the user when used with a * {@link #ACTION_CHOOSER}. */ public static final String EXTRA_TITLE = "android.intent.extra.TITLE"; /** * A {@link android.view.KeyEvent} object containing the event that * triggered the creation of the Intent it is in. */ public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT"; /** * Used as an boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action * of restarting the application. */ public static final String EXTRA_DONT_KILL_APP = "android.intent.extra.DONT_KILL_APP"; /** * A String holding the phone number originally entered in * {@link android.content.Intent#ACTION_NEW_OUTGOING_CALL}, or the actual * number to call in a {@link android.content.Intent#ACTION_CALL}. */ public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER"; /** * Used as an int extra field in {@link android.content.Intent#ACTION_UID_REMOVED} * intents to supply the uid the package had been assigned. Also an optional * extra in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} for the same * purpose. */ public static final String EXTRA_UID = "android.intent.extra.UID"; /** * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} * intents to indicate whether this represents a full uninstall (removing * both the code and its data) or a partial uninstall (leaving its data, * implying that this is an update). */ public static final String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED"; /** * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} * intents to indicate that this is a replacement of the package, so this * broadcast will immediately be followed by an add broadcast for a * different version of the same package. */ public static final String EXTRA_REPLACING = "android.intent.extra.REPLACING"; /** * Used as an int extra field in {@link android.app.AlarmManager} intents * to tell the application being invoked how many pending alarms are being * delievered with the intent. For one-shot alarms this will always be 1. * For recurring alarms, this might be greater than 1 if the device was * asleep or powered off at the time an earlier alarm would have been * delivered. */ public static final String EXTRA_ALARM_COUNT = "android.intent.extra.ALARM_COUNT"; /** * Used as a parcelable extra field in {@link #ACTION_APP_ERROR}, containing * the bug report. * * @hide */ public static final String EXTRA_BUG_REPORT = "android.intent.extra.BUG_REPORT"; /** * Used as a string extra field when sending an intent to PackageInstaller to install a * package. Specifies the installer package name; this package will receive the * {@link #ACTION_APP_ERROR} intent. * * @hide */ public static final String EXTRA_INSTALLER_PACKAGE_NAME = "android.intent.extra.INSTALLER_PACKAGE_NAME"; /** * Used in the extra field in the remote intent. It's astring token passed with the * remote intent. */ public static final String EXTRA_REMOTE_INTENT_TOKEN = "android.intent.extra.remote_intent_token"; // --------------------------------------------------------------------- // --------------------------------------------------------------------- // Intent flags (see mFlags variable). /** * If set, the recipient of this Intent will be granted permission to * perform read operations on the Uri in the Intent's data. */ public static final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001; /** * If set, the recipient of this Intent will be granted permission to * perform write operations on the Uri in the Intent's data. */ public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002; /** * Can be set by the caller to indicate that this Intent is coming from * a background operation, not from direct user interaction. */ public static final int FLAG_FROM_BACKGROUND = 0x00000004; /** * A flag you can enable for debugging: when set, log messages will be * printed during the resolution of this intent to show you what has * been found to create the final resolved list. */ public static final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008; /** * If set, the new activity is not kept in the history stack. As soon as * the user navigates away from it, the activity is finished. This may also * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory * noHistory} attribute. */ public static final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000; /** * If set, the activity will not be launched if it is already running * at the top of the history stack. */ public static final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000; /** * If set, this activity will become the start of a new task on this * history stack. A task (from the activity that started it to the * next task activity) defines an atomic group of activities that the * user can move to. Tasks can be moved to the foreground and background; * all of the activities inside of a particular task always remain in * the same order. See * Application Fundamentals: * Activities and Tasks for more details on tasks. * *

This flag is generally used by activities that want * to present a "launcher" style behavior: they give the user a list of * separate things that can be done, which otherwise run completely * independently of the activity launching them. * *

When using this flag, if a task is already running for the activity * you are now starting, then a new activity will not be started; instead, * the current task will simply be brought to the front of the screen with * the state it was last in. See {@link #FLAG_ACTIVITY_MULTIPLE_TASK} for a flag * to disable this behavior. * *

This flag can not be used when the caller is requesting a result from * the activity being launched. */ public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000; /** * Do not use this flag unless you are implementing your own * top-level application launcher. Used in conjunction with * {@link #FLAG_ACTIVITY_NEW_TASK} to disable the * behavior of bringing an existing task to the foreground. When set, * a new task is always started to host the Activity for the * Intent, regardless of whether there is already an existing task running * the same thing. * *

Because the default system does not include graphical task management, * you should not use this flag unless you provide some way for a user to * return back to the tasks you have launched. * *

This flag is ignored if * {@link #FLAG_ACTIVITY_NEW_TASK} is not set. * *

See Application Fundamentals: * Activities and Tasks for more details on tasks. */ public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000; /** * If set, and the activity being launched is already running in the * current task, then instead of launching a new instance of that activity, * all of the other activities on top of it will be closed and this Intent * will be delivered to the (now on top) old activity as a new Intent. * *

For example, consider a task consisting of the activities: A, B, C, D. * If D calls startActivity() with an Intent that resolves to the component * of activity B, then C and D will be finished and B receive the given * Intent, resulting in the stack now being: A, B. * *

The currently running instance of task B in the above example will * either receive the new intent you are starting here in its * onNewIntent() method, or be itself finished and restarted with the * new intent. If it has declared its launch mode to be "multiple" (the * default) it will be finished and re-created; for all other launch modes * it will receive the Intent in the current instance. * *

This launch mode can also be used to good effect in conjunction with * {@link #FLAG_ACTIVITY_NEW_TASK}: if used to start the root activity * of a task, it will bring any currently running instance of that task * to the foreground, and then clear it to its root state. This is * especially useful, for example, when launching an activity from the * notification manager. * *

See Application Fundamentals: * Activities and Tasks for more details on tasks. */ public static final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000; /** * If set and this intent is being used to launch a new activity from an * existing one, then the reply target of the existing activity will be * transfered to the new activity. This way the new activity can call * {@link android.app.Activity#setResult} and have that result sent back to * the reply target of the original activity. */ public static final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000; /** * If set and this intent is being used to launch a new activity from an * existing one, the current activity will not be counted as the top * activity for deciding whether the new intent should be delivered to * the top instead of starting a new one. The previous activity will * be used as the top, with the assumption being that the current activity * will finish itself immediately. */ public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000; /** * If set, the new activity is not kept in the list of recently launched * activities. */ public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000; /** * This flag is not normally set by application code, but set for you by * the system as described in the * {@link android.R.styleable#AndroidManifestActivity_launchMode * launchMode} documentation for the singleTask mode. */ public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000; /** * If set, and this activity is either being started in a new task or * bringing to the top an existing task, then it will be launched as * the front door of the task. This will result in the application of * any affinities needed to have that task in the proper state (either * moving activities to or from it), or simply resetting that task to * its initial state if needed. */ public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000; /** * This flag is not normally set by application code, but set for you by * the system if this activity is being launched from history * (longpress home key). */ public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000; /** * If set, this marks a point in the task's activity stack that should * be cleared when the task is reset. That is, the next time the task * is brought to the foreground with * {@link #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED} (typically as a result of * the user re-launching it from home), this activity and all on top of * it will be finished so that the user does not return to them, but * instead returns to whatever activity preceeded it. * *

This is useful for cases where you have a logical break in your * application. For example, an e-mail application may have a command * to view an attachment, which launches an image view activity to private HashSet mCategories; * display it. This activity should be part of the e-mail application's * task, since it is a part of the task the user is involved in. However, * if the user leaves that task, and later selects the e-mail app from * home, we may like them to return to the conversation they were * viewing, not the picture attachment, since that is confusing. By * setting this flag when launching the image viewer, that viewer and * any activities it starts will be removed the next time the user returns * to mail. */ public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000; /** * If set, this flag will prevent the normal {@link android.app.Activity#onUserLeaveHint} * callback from occurring on the current frontmost activity before it is * paused as the newly-started activity is brought to the front. * *

Typically, an activity can rely on that callback to indicate that an * explicit user action has caused their activity to be moved out of the * foreground. The callback marks an appropriate point in the activity's * lifecycle for it to dismiss any notifications that it intends to display * "until the user has seen them," such as a blinking LED. * *

If an activity is ever started via any non-user-driven events such as * phone-call receipt or an alarm handler, this flag should be passed to {@link * Context#startActivity Context.startActivity}, ensuring that the pausing * activity does not think the user has acknowledged its notification. */ public static final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000; /** * If set in an Intent passed to {@link Context#startActivity Context.startActivity()}, * this flag will cause the launched activity to be brought to the front of its * task's history stack if it is already running. * *

For example, consider a task consisting of four activities: A, B, C, D. * If D calls startActivity() with an Intent that resolves to the component * of activity B, then B will be brought to the front of the history stack, * with this resulting order: A, C, D, B. * * This flag will be ignored if {@link #FLAG_ACTIVITY_CLEAR_TOP} is also * specified. */ public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000; /** * If set, when sending a broadcast only registered receivers will be * called -- no BroadcastReceiver components will be launched. */ public static final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000; /** * If set, when sending a broadcast before boot has completed only * registered receivers will be called -- no BroadcastReceiver components * will be launched. Sticky intent state will be recorded properly even * if no receivers wind up being called. If {@link #FLAG_RECEIVER_REGISTERED_ONLY} * is specified in the broadcast intent, this flag is unnecessary. * *

This flag is only for use by system sevices as a convenience to * avoid having to implement a more complex mechanism around detection * of boot completion. * * @hide */ public static final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x20000000; // --------------------------------------------------------------------- // --------------------------------------------------------------------- // toUri() and parseUri() options. /** * Flag for use with {@link #toUri} and {@link #parseUri}: the URI string * always has the "intent:" scheme. This syntax can be used when you want * to later disambiguate between URIs that are intended to describe an * Intent vs. all others that should be treated as raw URIs. When used * with {@link #parseUri}, any other scheme will result in a generic * VIEW action for that raw URI. */ public static final int URI_INTENT_SCHEME = 1<<0; // --------------------------------------------------------------------- private String mAction; private Uri mData; private String mType; private String mPackage; private ComponentName mComponent; private int mFlags; * @see #setClass private Bundle mExtras; // --------------------------------------------------------------------- /** * Create an empty intent. */ public Intent() { } /** * Copy constructor. */ public Intent(Intent o) { this.mAction = o.mAction; this.mData = o.mData; this.mType = o.mType; this.mPackage = o.mPackage; this.mComponent = o.mComponent; this.mFlags = o.mFlags; if (o.mCategories != null) { this.mCategories = new HashSet(o.mCategories); } if (o.mExtras != null) { this.mExtras = new Bundle(o.mExtras); } } @Override public Object clone() { return new Intent(this); } private Intent(Intent o, boolean all) { this.mAction = o.mAction; this.mData = o.mData; this.mType = o.mType; this.mPackage = o.mPackage; this.mComponent = o.mComponent; if (o.mCategories != null) { this.mCategories = new HashSet(o.mCategories); } } /** * Make a clone of only the parts of the Intent that are relevant for * filter matching: the action, data, type, component, and categories. */ public Intent cloneFilter() { return new Intent(this, false); } /** * Create an intent with a given action. All other fields (data, type, * class) are null. Note that the action must be in a * namespace because Intents are used globally in the system -- for * example the system VIEW action is android.intent.action.VIEW; an * application's custom action would be something like * com.google.app.myapp.CUSTOM_ACTION. * * @param action The Intent action, such as ACTION_VIEW. */ public Intent(String action) { mAction = action; } /** * Create an intent with a given action and for a given data url. Note * that the action must be in a namespace because Intents are * used globally in the system -- for example the system VIEW action is * android.intent.action.VIEW; an application's custom action would be * something like com.google.app.myapp.CUSTOM_ACTION. * *

Note: scheme and host name matching in the Android framework is * case-sensitive, unlike the formal RFC. As a result, * you should always ensure that you write your Uri with these elements * using lower case letters, and normalize any Uris you receive from * outside of Android to ensure the scheme and host is lower case.

* * @param action The Intent action, such as ACTION_VIEW. * @param uri The Intent data URI. */ public Intent(String action, Uri uri) { mAction = action; mData = uri; } /** * Create an intent for a specific component. All other fields (action, data, * type, class) are null, though they can be modified later with explicit * calls. This provides a convenient way to create an intent that is * intended to execute a hard-coded class name, rather than relying on the * system to find an appropriate class for you; see {@link #setComponent} * for more information on the repercussions of this. * * @param packageContext A Context of the application package implementing * this class. * @param cls The component class that is to be used for the intent. * * @see #setComponent * @see #Intent(String, android.net.Uri , Context, Class) */ public Intent(Context packageContext, Class cls) { mComponent = new ComponentName(packageContext, cls); } /** * Create an intent for a specific component with a specified action and data. * This is equivalent using {@link #Intent(String, android.net.Uri)} to * construct the Intent and then calling {@link #setClass} to set its * class. * *

Note: scheme and host name matching in the Android framework is * case-sensitive, unlike the formal RFC. As a result, * you should always ensure that you write your Uri with these elements * using lower case letters, and normalize any Uris you receive from * outside of Android to ensure the scheme and host is lower case.

* * @param action The Intent action, such as ACTION_VIEW. * @param uri The Intent data URI. * @param packageContext A Context of the application package implementing * this class. * @param cls The component class that is to be used for the intent. * * @see #Intent(String, android.net.Uri) * @see #Intent(Context, Class) * @see #setClass * @see #setComponent */ public Intent(String action, Uri uri, Context packageContext, Class cls) { mAction = action; mData = uri; mComponent = new ComponentName(packageContext, cls); } /** * Call {@link #parseUri} with 0 flags. * @deprecated Use {@link #parseUri} instead. */ @Deprecated public static Intent getIntent(String uri) throws URISyntaxException { return parseUri(uri, 0); } /** * Create an intent from a URI. This URI may encode the action, * category, and other intent fields, if it was returned by * {@link #toUri}.. If the Intent was not generate by toUri(), its data * will be the entire URI and its action will be ACTION_VIEW. * *

The URI given here must not be relative -- that is, it must include * the scheme and full path. * * @param uri The URI to turn into an Intent. * @param flags Additional processing flags. Either 0 or * * @return Intent The newly created Intent object. * * @throws URISyntaxException Throws URISyntaxError if the basic URI syntax * it bad (as parsed by the Uri class) or the Intent data within the * URI is invalid. * * @see #toUri */ public static Intent parseUri(String uri, int flags) throws URISyntaxException { int i = 0; try { // Validate intent scheme for if requested. if ((flags&URI_INTENT_SCHEME) != 0) { if (!uri.startsWith("intent:")) { Intent intent = new Intent(ACTION_VIEW); try { intent.setData(Uri.parse(uri)); } catch (IllegalArgumentException e) { throw new URISyntaxException(uri, e.getMessage()); } return intent; } } // simple case i = uri.lastIndexOf("#"); if (i == -1) return new Intent(ACTION_VIEW, Uri.parse(uri)); // old format Intent URI if (!uri.startsWith("#Intent;", i)) return getIntentOld(uri); // new format Intent intent = new Intent(ACTION_VIEW); // fetch data part, if present String data = i >= 0 ? uri.substring(0, i) : null; String scheme = null; i += "#Intent;".length(); // loop over contents of Intent, all name=value; while (!uri.startsWith("end", i)) { int eq = uri.indexOf('=', i); int semi = uri.indexOf(';', eq); String value = Uri.decode(uri.substring(eq + 1, semi)); // action if (uri.startsWith("action=", i)) { intent.mAction = value; } // categories else if (uri.startsWith("category=", i)) { intent.addCategory(value); } // type else if (uri.startsWith("type=", i)) { intent.mType = value; } // launch flags else if (uri.startsWith("launchFlags=", i)) { intent.mFlags = Integer.decode(value).intValue(); } // package else if (uri.startsWith("package=", i)) { intent.mPackage = value; } // component else if (uri.startsWith("component=", i)) { intent.mComponent = ComponentName.unflattenFromString(value); } // scheme else if (uri.startsWith("scheme=", i)) { scheme = value; } // extra else { String key = Uri.decode(uri.substring(i + 2, eq)); // create Bundle if it doesn't already exist if (intent.mExtras == null) intent.mExtras = new Bundle(); Bundle b = intent.mExtras; // add EXTRA if (uri.startsWith("S.", i)) b.putString(key, value); else if (uri.startsWith("B.", i)) b.putBoolean(key, Boolean.parseBoolean(value)); else if (uri.startsWith("b.", i)) b.putByte(key, Byte.parseByte(value)); else if (uri.startsWith("c.", i)) b.putChar(key, value.charAt(0)); else if (uri.startsWith("d.", i)) b.putDouble(key, Double.parseDouble(value)); else if (uri.startsWith("f.", i)) b.putFloat(key, Float.parseFloat(value)); else if (uri.startsWith("i.", i)) b.putInt(key, Integer.parseInt(value)); else if (uri.startsWith("l.", i)) b.putLong(key, Long.parseLong(value)); else if (uri.startsWith("s.", i)) b.putShort(key, Short.parseShort(value)); else throw new URISyntaxException(uri, "unknown EXTRA type", i); } // move to the next item i = semi + 1; } if (data != null) { if (data.startsWith("intent:")) { data = data.substring(7); if (scheme != null) { data = scheme + ':' + data; } } if (data.length() > 0) { try { intent.mData = Uri.parse(data); } catch (IllegalArgumentException e) { throw new URISyntaxException(uri, e.getMessage()); } } } return intent; } catch (IndexOutOfBoundsException e) { throw new URISyntaxException(uri, "illegal Intent URI format", i); } } public static Intent getIntentOld(String uri) throws URISyntaxException { Intent intent; int i = uri.lastIndexOf('#'); if (i >= 0) { Uri data = null; String action = null; if (i > 0) { data = Uri.parse(uri.substring(0, i)); } i++; if (uri.regionMatches(i, "action(", 0, 7)) { i += 7; int j = uri.indexOf(')', i); action = uri.substring(i, j); i = j + 1; } intent = new Intent(action, data); if (uri.regionMatches(i, "categories(", 0, 11)) { i += 11; int j = uri.indexOf(')', i); while (i < j) { int sep = uri.indexOf('!', i); if (sep < 0) sep = j; if (i < sep) { intent.addCategory(uri.substring(i, sep)); } i = sep + 1; } i = j + 1; } if (uri.regionMatches(i, "type(", 0, 5)) { i += 5; int j = uri.indexOf(')', i); intent.mType = uri.substring(i, j); i = j + 1; } if (uri.regionMatches(i, "launchFlags(", 0, 12)) { i += 12; int j = uri.indexOf(')', i); intent.mFlags = Integer.decode(uri.substring(i, j)).intValue(); i = j + 1; } if (uri.regionMatches(i, "component(", 0, 10)) { i += 10; int j = uri.indexOf(')', i); int sep = uri.indexOf('!', i); if (sep >= 0 && sep < j) { String pkg = uri.substring(i, sep); String cls = uri.substring(sep + 1, j); intent.mComponent = new ComponentName(pkg, cls); } i = j + 1; } if (uri.regionMatches(i, "extras(", 0, 7)) { i += 7; final int closeParen = uri.indexOf(')', i); if (closeParen == -1) throw new URISyntaxException(uri, "EXTRA missing trailing ')'", i); while (i < closeParen) { // fetch the key value int j = uri.indexOf('=', i); if (j <= i + 1 || i >= closeParen) { throw new URISyntaxException(uri, "EXTRA missing '='", i); } char type = uri.charAt(i); i++; String key = uri.substring(i, j); i = j + 1; // get type-value j = uri.indexOf('!', i); if (j == -1 || j >= closeParen) j = closeParen; if (i >= j) throw new URISyntaxException(uri, "EXTRA missing '!'", i); String value = uri.substring(i, j); i = j; // create Bundle if it doesn't already exist if (intent.mExtras == null) intent.mExtras = new Bundle(); // add item to bundle try { switch (type) { case 'S': intent.mExtras.putString(key, Uri.decode(value)); break; case 'B': intent.mExtras.putBoolean(key, Boolean.parseBoolean(value)); break; return mType; case 'b': intent.mExtras.putByte(key, Byte.parseByte(value)); break; case 'c': intent.mExtras.putChar(key, Uri.decode(value).charAt(0)); break; case 'd': intent.mExtras.putDouble(key, Double.parseDouble(value)); break; case 'f': public String getType() { intent.mExtras.putFloat(key, Float.parseFloat(value)); break; case 'i': intent.mExtras.putInt(key, Integer.parseInt(value)); break; case 'l': intent.mExtras.putLong(key, Long.parseLong(value)); break; case 's': intent.mExtras.putShort(key, Short.parseShort(value)); break; default: throw new URISyntaxException(uri, "EXTRA has unknown type", i); } } catch (NumberFormatException e) { throw new URISyntaxException(uri, "EXTRA value can't be parsed", i); } char ch = uri.charAt(i); if (ch == ')') break; if (ch != '!') throw new URISyntaxException(uri, "EXTRA missing '!'", i); i++; } } if (intent.mAction == null) { // By default, if no action is specified, then use VIEW. intent.mAction = ACTION_VIEW; } } else { intent = new Intent(ACTION_VIEW, Uri.parse(uri)); } return intent; } /** * Retrieve the general action to be performed, such as * {@link #ACTION_VIEW}. The action describes the general way the rest of * the information in the intent should be interpreted -- most importantly, * what to do with the data returned by {@link #getData}. * * @return The action of this intent or null if none is specified. * * @see #setAction */ public String getAction() { return mAction; } /** * Retrieve data this intent is operating on. This URI specifies the name * of the data; often it uses the content: scheme, specifying data in a * content provider. Other schemes may be handled by specific activities, * such as http: by the web browser. * * @return The URI of the data this intent is targeting or null. * * @see #getScheme * @see #setData */ public Uri getData() { return mData; } /** * The same as {@link #getData()}, but returns the URI as an encoded * String. */ public String getDataString() { return mData != null ? mData.toString() : null; } /** * Return the scheme portion of the intent's data. If the data is null or * does not include a scheme, null is returned. Otherwise, the scheme * prefix without the final ':' is returned, i.e. "http". * *

This is the same as calling getData().getScheme() (and checking for * null data). * * @return The scheme of this intent. * * @see #getData */ public String getScheme() { return mData != null ? mData.getScheme() : null; } /** * Retrieve any explicit MIME type included in the intent. This is usually * null, as the type is determined by the intent data. * * @return If a type was manually set, it is returned; else null is * returned. * * @see #resolveType(ContentResolver) * @see #setType */ } /** * Return the MIME data type of this intent. If the type field is * explicitly set, that is simply returned. Otherwise, if the data is set, * the type of that data is returned. If neither fields are set, a null is * returned. * * @return The MIME type of this intent. * * @see #getType * @see #resolveType(ContentResolver) */ public String resolveType(Context context) { return resolveType(context.getContentResolver()); } /** * Return the MIME data type of this intent. If the type field is * explicitly set, that is simply returned. Otherwise, if the data is set, * the type of that data is returned. If neither fields are set, a null is * returned. * * @param resolver A ContentResolver that can be used to determine the MIME * type of the intent's data. * * @return The MIME type of this intent. * * @see #getType * @see #resolveType(Context) */ public String resolveType(ContentResolver resolver) { if (mType != null) { return mType; } if (mData != null) { if ("content".equals(mData.getScheme())) { return resolver.getType(mData); } } return null; } /** * Return the MIME data type of this intent, only if it will be needed for * intent resolution. This is not generally useful for application code; * it is used by the frameworks for communicating with back-end system * services. * * @param resolver A ContentResolver that can be used to determine the MIME * type of the intent's data. * * @return The MIME type of this intent, or null if it is unknown or not * needed. */ public String resolveTypeIfNeeded(ContentResolver resolver) { if (mComponent != null) { return mType; } return resolveType(resolver); } /** * Check if an category exists in the intent. * * @param category The category to check. * * @return boolean True if the intent contains the category, else false. * * @see #getCategories * @see #addCategory */ public boolean hasCategory(String category) { return mCategories != null && mCategories.contains(category); } /** * Return the set of all categories in the intent. If there are no categories, * returns NULL. * * @return Set The set of categories you can examine. Do not modify! * * @see #hasCategory * @see #addCategory */ public Set getCategories() { return mCategories; } /** * Sets the ClassLoader that will be used when unmarshalling * any Parcelable values from the extras of this Intent. * * @param loader a ClassLoader, or null to use the default loader * at the time of unmarshalling. */ public void setExtrasClassLoader(ClassLoader loader) { if (mExtras != null) { mExtras.setClassLoader(loader); } } /** * Returns true if an extra value is associated with the given name. * @param name the extra's name * @return true if the given extra is present. */ public boolean hasExtra(String name) { return mExtras != null && mExtras.containsKey(name); } /** * Returns true if the Intent's extras contain a parcelled file descriptor. * @return true if the Intent contains a parcelled file descriptor. */ public boolean hasFileDescriptors() { return mExtras != null && mExtras.hasFileDescriptors(); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if none was found. * * @deprecated * @hide */ @Deprecated public Object getExtra(String name) { return getExtra(name, null); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue the value to be returned if no value of the desired * type is stored with the given name. * * @return the value of an item that previously added with putExtra() * or the default value if none was found. * * @see #putExtra(String, boolean) */ public boolean getBooleanExtra(String name, boolean defaultValue) { return mExtras == null ? defaultValue : mExtras.getBoolean(name, defaultValue); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue the value to be returned if no value of the desired * type is stored with the given name. * * @return the value of an item that previously added with putExtra() * or the default value if none was found. * * @see #putExtra(String, byte) */ public byte getByteExtra(String name, byte defaultValue) { return mExtras == null ? defaultValue : mExtras.getByte(name, defaultValue); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue the value to be returned if no value of the desired * type is stored with the given name. * * @return the value of an item that previously added with putExtra() * or the default value if none was found. * * @see #putExtra(String, short) */ public short getShortExtra(String name, short defaultValue) { return mExtras == null ? defaultValue : mExtras.getShort(name, defaultValue); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue the value to be returned if no value of the desired * type is stored with the given name. * * @return the value of an item that previously added with putExtra() * or the default value if none was found. * * @see #putExtra(String, char) */ public char getCharExtra(String name, char defaultValue) { return mExtras == null ? defaultValue : mExtras.getChar(name, defaultValue); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue the value to be returned if no value of the desired * type is stored with the given name. * * @return the value of an item that previously added with putExtra() * or the default value if none was found. * * @see #putExtra(String, int) */ public int getIntExtra(String name, int defaultValue) { return mExtras == null ? defaultValue : mExtras.getInt(name, defaultValue); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue the value to be returned if no value of the desired * type is stored with the given name. * * @return the value of an item that previously added with putExtra() * or the default value if none was found. * * @see #putExtra(String, long) */ public long getLongExtra(String name, long defaultValue) { return mExtras == null ? defaultValue : mExtras.getLong(name, defaultValue); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue the value to be returned if no value of the desired * type is stored with the given name. * * @return the value of an item that previously added with putExtra(), * or the default value if no such item is present * * @see #putExtra(String, float) */ public float getFloatExtra(String name, float defaultValue) { return mExtras == null ? defaultValue : mExtras.getFloat(name, defaultValue); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue the value to be returned if no value of the desired * type is stored with the given name. * * @return the value of an item that previously added with putExtra() * or the default value if none was found. * * @see #putExtra(String, double) */ public double getDoubleExtra(String name, double defaultValue) { return mExtras == null ? defaultValue : mExtras.getDouble(name, defaultValue); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no String value was found. * * @see #putExtra(String, String) */ public String getStringExtra(String name) { return mExtras == null ? null : mExtras.getString(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no CharSequence value was found. * * @see #putExtra(String, CharSequence) */ /** public CharSequence getCharSequenceExtra(String name) { return mExtras == null ? null : mExtras.getCharSequence(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no Parcelable value was found. * * @see #putExtra(String, Parcelable) */ public T getParcelableExtra(String name) { return mExtras == null ? null : mExtras.getParcelable(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no Parcelable[] value was found. * * @see #putExtra(String, Parcelable[]) */ public Parcelable[] getParcelableArrayExtra(String name) { return mExtras == null ? null : mExtras.getParcelableArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no ArrayList value was found. * * @see #putParcelableArrayListExtra(String, ArrayList) */ public ArrayList getParcelableArrayListExtra(String name) { return mExtras == null ? null : mExtras.getParcelableArrayList(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no Serializable value was found. * * @see #putExtra(String, Serializable) */ public Serializable getSerializableExtra(String name) { return mExtras == null ? null : mExtras.getSerializable(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no ArrayList value was found. * * @see #putIntegerArrayListExtra(String, ArrayList) */ public ArrayList getIntegerArrayListExtra(String name) { return mExtras == null ? null : mExtras.getIntegerArrayList(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no ArrayList value was found. * * @see #putStringArrayListExtra(String, ArrayList) */ public ArrayList getStringArrayListExtra(String name) { return mExtras == null ? null : mExtras.getStringArrayList(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no boolean array value was found. * * @see #putExtra(String, boolean[]) */ public boolean[] getBooleanArrayExtra(String name) { return mExtras == null ? null : mExtras.getBooleanArray(name); } * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no byte array value was found. * * @see #putExtra(String, byte[]) */ public byte[] getByteArrayExtra(String name) { return mExtras == null ? null : mExtras.getByteArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no short array value was found. * * @see #putExtra(String, short[]) */ public short[] getShortArrayExtra(String name) { return mExtras == null ? null : mExtras.getShortArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no char array value was found. * * @see #putExtra(String, char[]) */ public char[] getCharArrayExtra(String name) { return mExtras == null ? null : mExtras.getCharArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no int array value was found. * * @see #putExtra(String, int[]) */ public int[] getIntArrayExtra(String name) { return mExtras == null ? null : mExtras.getIntArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no long array value was found. * * @see #putExtra(String, long[]) */ public long[] getLongArrayExtra(String name) { return mExtras == null ? null : mExtras.getLongArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no float array value was found. * * @see #putExtra(String, float[]) */ public float[] getFloatArrayExtra(String name) { return mExtras == null ? null : mExtras.getFloatArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no double array value was found. * * @see #putExtra(String, double[]) */ public double[] getDoubleArrayExtra(String name) { return mExtras == null ? null : mExtras.getDoubleArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no String array value was found. * * @see #putExtra(String, String[]) */ public String[] getStringArrayExtra(String name) { return mExtras == null ? null : mExtras.getStringArray(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no Bundle value was found. * * @see #putExtra(String, Bundle) */ public Bundle getBundleExtra(String name) { return mExtras == null ? null : mExtras.getBundle(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * * @return the value of an item that previously added with putExtra() * or null if no IBinder value was found. * * @see #putExtra(String, IBinder) * * @deprecated * @hide */ @Deprecated public IBinder getIBinderExtra(String name) { return mExtras == null ? null : mExtras.getIBinder(name); } /** * Retrieve extended data from the intent. * * @param name The name of the desired item. * @param defaultValue The default value to return in case no item is * associated with the key 'name' * * @return the value of an item that previously added with putExtra() * or defaultValue if none was found. * * @see #putExtra * * @deprecated * @hide */ @Deprecated public Object getExtra(String name, Object defaultValue) { Object result = defaultValue; if (mExtras != null) { Object result2 = mExtras.get(name); if (result2 != null) { result = result2; } } return result; } /** * Retrieves a map of extended data from the intent. * * @return the map of all extras previously added with putExtra(), * or null if none have been added. */ public Bundle getExtras() { return (mExtras != null) ? new Bundle(mExtras) : null; } /** * Retrieve any special flags associated with this intent. You will * normally just set them with {@link #setFlags} and let the system * take the appropriate action with them. * * @return int The currently set flags. * * @see #setFlags */ public int getFlags() { return mFlags; } /** * Retrieve the application package name this Intent is limited to. When * resolving an Intent, if non-null this limits the resolution to only * components in the given application package. * * @return The name of the application package for the Intent. * * @see #resolveActivity * @see #setPackage */ public String getPackage() { return mPackage; } /** * Retrieve the concrete component associated with the intent. When receiving * an intent, this is the component that was found to best handle it (that is, * yourself) and will always be non-null; in all other cases it will be * null unless explicitly set. * * @return The name of the application component to handle the intent. * * @see #resolveActivity * @see #setComponent */ public ComponentName getComponent() { return mComponent; } /** * Return the Activity component that should be used to handle this intent. * The appropriate component is determined based on the information in the * intent, evaluated as follows: * *

If {@link #getComponent} returns an explicit class, that is returned * without any further consideration. * *

The activity must handle the {@link Intent#CATEGORY_DEFAULT} Intent * category to be considered. * *

If {@link #getAction} is non-NULL, the activity must handle this * action. * *

If {@link #resolveType} returns non-NULL, the activity must handle * this type. * *

If {@link #addCategory} has added any categories, the activity must * handle ALL of the categories specified. * *

If {@link #getPackage} is non-NULL, only activity components in * that application package will be considered. * *

If there are no activities that satisfy all of these conditions, a * null string is returned. * *

If multiple activities are found to satisfy the intent, the one with * the highest priority will be used. If there are multiple activities * with the same priority, the system will either pick the best activity * based on user preference, or resolve to a system class that will allow * the user to pick an activity and forward from there. * *

This method is implemented simply by calling * {@link PackageManager#resolveActivity} with the "defaultOnly" parameter * true.

*

This API is called for you as part of starting an activity from an * intent. You do not normally need to call it yourself.

* * @param pm The package manager with which to resolve the Intent. * * @return Name of the component implementing an activity that can * display the intent. * * @see #setComponent * @see #getComponent * @see #resolveActivityInfo */ public ComponentName resolveActivity(PackageManager pm) { if (mComponent != null) { return mComponent; } ResolveInfo info = pm.resolveActivity( this, PackageManager.MATCH_DEFAULT_ONLY); if (info != null) { return new ComponentName( info.activityInfo.applicationInfo.packageName, info.activityInfo.name); } return null; } /** * Resolve the Intent into an {@link ActivityInfo} * describing the activity that should execute the intent. Resolution * follows the same rules as described for {@link #resolveActivity}, but * you get back the completely information about the resolved activity * instead of just its class name. * * @param pm The package manager with which to resolve the Intent. * @param flags Addition information to retrieve as per * {@link PackageManager#getActivityInfo(ComponentName, int) * PackageManager.getActivityInfo()}. * * @return PackageManager.ActivityInfo * * @see #resolveActivity */ public ActivityInfo resolveActivityInfo(PackageManager pm, int flags) { ActivityInfo ai = null; if (mComponent != null) { try { ai = pm.getActivityInfo(mComponent, flags); } catch (PackageManager.NameNotFoundException e) { // ignore } } else { ResolveInfo info = pm.resolveActivity( this, PackageManager.MATCH_DEFAULT_ONLY); if (info != null) { ai = info.activityInfo; } } return ai; } /** * Set the general action to be performed. * * @param action An action name, such as ACTION_VIEW. Application-specific * actions should be prefixed with the vendor's package name. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #getAction */ public Intent setAction(String action) { mAction = action; return this; } /** * Set the data this intent is operating on. This method automatically * clears any type that was previously set by {@link #setType}. * *

Note: scheme and host name matching in the Android framework is * case-sensitive, unlike the formal RFC. As a result, * you should always ensure that you write your Uri with these elements * using lower case letters, and normalize any Uris you receive from * outside of Android to ensure the scheme and host is lower case.

* * @param data The URI of the data this intent is now targeting. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #getData * @see #setType * @see #setDataAndType */ public Intent setData(Uri data) { mData = data; mType = null; return this; } /** * Set an explicit MIME data type. This is used to create intents that * only specify a type and not data, for example to indicate the type of * data to return. This method automatically clears any data that was * previously set by {@link #setData}. * *

Note: MIME type matching in the Android framework is * case-sensitive, unlike formal RFC MIME types. As a result, * you should always write your MIME types with lower case letters, * and any MIME types you receive from outside of Android should be * converted to lower case before supplying them here.

* * @param type The MIME type of the data being handled by this intent. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #getType * @see #setData * @see #setDataAndType */ public Intent setType(String type) { mData = null; mType = type; return this; } /** * (Usually optional) Set the data for the intent along with an explicit * MIME data type. This method should very rarely be used -- it allows you * to override the MIME type that would ordinarily be inferred from the * data with your own type given here. * *

Note: MIME type, Uri scheme, and host name matching in the * Android framework is case-sensitive, unlike the formal RFC definitions. * As a result, you should always write these elements with lower case letters, * and normalize any MIME types or Uris you receive from * outside of Android to ensure these elements are lower case before * supplying them here.

* * @param data The URI of the data this intent is now targeting. * @param type The MIME type of the data being handled by this intent. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #setData * @see #setType */ public Intent setDataAndType(Uri data, String type) { mData = data; mType = type; return this; } /** * Add a new category to the intent. Categories provide additional detail * about the action the intent is perform. When resolving an intent, only * activities that provide all of the requested categories will be * used. * * @param category The desired category. This can be either one of the * predefined Intent categories, or a custom category in your own * namespace. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #hasCategory * @see #removeCategory */ public Intent addCategory(String category) { if (mCategories == null) { mCategories = new HashSet(); } mCategories.add(category); return this; } /** * Remove an category from an intent. * * @param category The category to remove. * * @see #addCategory */ public void removeCategory(String category) { if (mCategories != null) { mCategories.remove(category); if (mCategories.size() == 0) { mCategories = null; } } } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The boolean data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getBooleanExtra(String, boolean) */ public Intent putExtra(String name, boolean value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putBoolean(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The byte data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getByteExtra(String, byte) */ public Intent putExtra(String name, byte value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putByte(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The char data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getCharExtra(String, char) */ public Intent putExtra(String name, char value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putChar(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The short data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getShortExtra(String, short) */ public Intent putExtra(String name, short value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putShort(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The integer data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getIntExtra(String, int) */ public Intent putExtra(String name, int value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putInt(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The long data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getLongExtra(String, long) */ public Intent putExtra(String name, long value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putLong(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The float data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getFloatExtra(String, float) */ public Intent putExtra(String name, float value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putFloat(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The double data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getDoubleExtra(String, double) */ public Intent putExtra(String name, double value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putDouble(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The String data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getStringExtra(String) */ public Intent putExtra(String name, String value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putString(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The CharSequence data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getCharSequenceExtra(String) */ public Intent putExtra(String name, CharSequence value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putCharSequence(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The Parcelable data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getParcelableExtra(String) */ public Intent putExtra(String name, Parcelable value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putParcelable(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The Parcelable[] data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getParcelableArrayExtra(String) */ public Intent putExtra(String name, Parcelable[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putParcelableArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The ArrayList data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getParcelableArrayListExtra(String) */ public Intent putParcelableArrayListExtra(String name, ArrayList value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putParcelableArrayList(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The ArrayList data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getIntegerArrayListExtra(String) */ public Intent putIntegerArrayListExtra(String name, ArrayList value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putIntegerArrayList(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The ArrayList data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getStringArrayListExtra(String) */ public Intent putStringArrayListExtra(String name, ArrayList value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putStringArrayList(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The Serializable data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getSerializableExtra(String) */ public Intent putExtra(String name, Serializable value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putSerializable(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The boolean array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getBooleanArrayExtra(String) */ public Intent putExtra(String name, boolean[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putBooleanArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The byte array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getByteArrayExtra(String) */ public Intent putExtra(String name, byte[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putByteArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The short array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getShortArrayExtra(String) */ public Intent putExtra(String name, short[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putShortArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The char array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getCharArrayExtra(String) */ public Intent putExtra(String name, char[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putCharArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The int array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getIntArrayExtra(String) */ public Intent putExtra(String name, int[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putIntArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The byte array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getLongArrayExtra(String) */ public Intent putExtra(String name, long[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putLongArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The float array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getFloatArrayExtra(String) */ public Intent putExtra(String name, float[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putFloatArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The double array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getDoubleArrayExtra(String) */ public Intent putExtra(String name, double[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putDoubleArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The String array data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getStringArrayExtra(String) */ public Intent putExtra(String name, String[] value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putStringArray(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The Bundle data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getBundleExtra(String) */ public Intent putExtra(String name, Bundle value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putBundle(name, value); return this; } /** * Add extended data to the intent. The name must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param name The name of the extra data, with package prefix. * @param value The IBinder data value. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #putExtras * @see #removeExtra * @see #getIBinderExtra(String) * * @deprecated * @hide */ @Deprecated public Intent putExtra(String name, IBinder value) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putIBinder(name, value); return this; } /** * Copy all extras in 'src' in to this intent. * * @param src Contains the extras to copy. * * @see #putExtra */ public Intent putExtras(Intent src) { if (src.mExtras != null) { if (mExtras == null) { mExtras = new Bundle(src.mExtras); } else { mExtras.putAll(src.mExtras); } } return this; } /** * Add a set of extended data to the intent. The keys must include a package * prefix, for example the app com.android.contacts would use names * like "com.android.contacts.ShowAll". * * @param extras The Bundle of extras to add to this intent. * * @see #putExtra * @see #removeExtra */ public Intent putExtras(Bundle extras) { if (mExtras == null) { mExtras = new Bundle(); } mExtras.putAll(extras); return this; } /** * Completely replace the extras in the Intent with the extras in the * given Intent. * * @param src The exact extras contained in this Intent are copied * into the target intent, replacing any that were previously there. */ public Intent replaceExtras(Intent src) { mExtras = src.mExtras != null ? new Bundle(src.mExtras) : null; return this; } /** * Completely replace the extras in the Intent with the given Bundle of * extras. * * @param extras The new set of extras in the Intent, or null to erase * all extras. */ public Intent replaceExtras(Bundle extras) { mExtras = extras != null ? new Bundle(extras) : null; return this; } /** * Remove extended data from the intent. * * @see #putExtra */ public void removeExtra(String name) { if (mExtras != null) { mExtras.remove(name); if (mExtras.size() == 0) { mExtras = null; } } } /** * Set special flags controlling how this intent is handled. Most values * here depend on the type of component being executed by the Intent, * specifically the FLAG_ACTIVITY_* flags are all for use with * {@link Context#startActivity Context.startActivity()} and the * FLAG_RECEIVER_* flags are all for use with * {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}. * *

See the Application Fundamentals: * Activities and Tasks documentation for important information on how some of these options impact * the behavior of your application. * * @param flags The desired flags. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #getFlags * @see #addFlags * * @see #FLAG_GRANT_READ_URI_PERMISSION * @see #FLAG_GRANT_WRITE_URI_PERMISSION * @see #FLAG_DEBUG_LOG_RESOLUTION * @see #FLAG_FROM_BACKGROUND * @see #FLAG_ACTIVITY_BROUGHT_TO_FRONT * @see #FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET * @see #FLAG_ACTIVITY_CLEAR_TOP * @see #FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS * @see #FLAG_ACTIVITY_FORWARD_RESULT * @see #FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY * @see #FLAG_ACTIVITY_MULTIPLE_TASK * @see #FLAG_ACTIVITY_NEW_TASK * @see #FLAG_ACTIVITY_NO_HISTORY * @see #FLAG_ACTIVITY_NO_USER_ACTION * @see #FLAG_ACTIVITY_PREVIOUS_IS_TOP * @see #FLAG_ACTIVITY_RESET_TASK_IF_NEEDED * @see #FLAG_ACTIVITY_SINGLE_TOP * @see #FLAG_RECEIVER_REGISTERED_ONLY */ public Intent setFlags(int flags) { mFlags = flags; return this; } /** * Add additional flags to the intent (or with existing flags * value). * * @param flags The new flags to set. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #setFlags */ public Intent addFlags(int flags) { mFlags |= flags; return this; } /** * (Usually optional) Set an explicit application package name that limits * the components this Intent will resolve to. If left to the default * value of null, all components in all applications will considered. * If non-null, the Intent can only match the components in the given * application package. * * @param packageName The name of the application package to handle the * intent, or null to allow any application package. * /** * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #getPackage * @see #resolveActivity */ public Intent setPackage(String packageName) { mPackage = packageName; return this; } /** * (Usually optional) Explicitly set the component to handle the intent. * If left with the default value of null, the system will determine the * appropriate class to use based on the other fields (action, data, * type, categories) in the Intent. If this class is defined, the * specified class will always be used regardless of the other fields. You * should only set this value when you know you absolutely want a specific * class to be used; otherwise it is better to let the system find the * appropriate class so that you will respect the installed applications * and user preferences. * * @param component The name of the application component to handle the * intent, or null to let the system find one for you. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #setClass * @see #setClassName(Context, String) * @see #setClassName(String, String) * @see #getComponent * @see #resolveActivity */ public Intent setComponent(ComponentName component) { mComponent = component; return this; } /** * Convenience for calling {@link #setComponent} with an * explicit class name. * * @param packageContext A Context of the application package implementing * this class. * @param className The name of a class inside of the application package * that will be used as the component for this Intent. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #setComponent * @see #setClass */ public Intent setClassName(Context packageContext, String className) { mComponent = new ComponentName(packageContext, className); return this; } /** * Convenience for calling {@link #setComponent} with an * explicit application package name and class name. * * @param packageName The name of the package implementing the desired * component. * @param className The name of a class inside of the application package * that will be used as the component for this Intent. * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #setComponent * @see #setClass */ public Intent setClassName(String packageName, String className) { mComponent = new ComponentName(packageName, className); return this; } /** * Convenience for calling {@link #setComponent(ComponentName)} with the * name returned by a {@link Class} object. * * @param packageContext A Context of the application package implementing * this class. * @param cls The class name to set, equivalent to * setClassName(context, cls.getName()). * * @return Returns the same Intent object, for chaining multiple calls * into a single statement. * * @see #setComponent */ public Intent setClass(Context packageContext, Class cls) { mComponent = new ComponentName(packageContext, cls); return this; } * Use with {@link #fillIn} to allow the current action value to be * overwritten, even if it is already set. */ public static final int FILL_IN_ACTION = 1<<0; /** * Use with {@link #fillIn} to allow the current data or type value * overwritten, even if it is already set. */ public static final int FILL_IN_DATA = 1<<1; /** * Use with {@link #fillIn} to allow the current categories to be * overwritten, even if they are already set. */ public static final int FILL_IN_CATEGORIES = 1<<2; /** * Use with {@link #fillIn} to allow the current component value to be * overwritten, even if it is already set. */ public static final int FILL_IN_COMPONENT = 1<<3; /** * Use with {@link #fillIn} to allow the current package value to be * overwritten, even if it is already set. */ public static final int FILL_IN_PACKAGE = 1<<4; /** * Copy the contents of other in to this object, but only * where fields are not defined by this object. For purposes of a field * being defined, the following pieces of data in the Intent are * considered to be separate fields: * *

    *
  • action, as set by {@link #setAction}. *
  • data URI and MIME type, as set by {@link #setData(Uri)}, * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}. *
  • categories, as set by {@link #addCategory}. *
  • package, as set by {@link #setPackage}. *
  • component, as set by {@link #setComponent(ComponentName)} or * related methods. *
  • each top-level name in the associated extras. *
* *

In addition, you can use the {@link #FILL_IN_ACTION}, * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE}, * and {@link #FILL_IN_COMPONENT} to override the restriction where the * corresponding field will not be replaced if it is already set. * *

For example, consider Intent A with {data="foo", categories="bar"} * and Intent B with {action="gotit", data-type="some/thing", * categories="one","two"}. * *

Calling A.fillIn(B, Intent.FILL_IN_DATA) will result in A now * containing: {action="gotit", data-type="some/thing", * categories="bar"}. * * @param other Another Intent whose values are to be used to fill in * the current one. * @param flags Options to control which fields can be filled in. * * @return Returns a bit mask of {@link #FILL_IN_ACTION}, * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE}, * and {@link #FILL_IN_COMPONENT} indicating which fields were changed. */ public int fillIn(Intent other, int flags) { int changes = 0; if (other.mAction != null && (mAction == null || (flags&FILL_IN_ACTION) != 0)) { mAction = other.mAction; changes |= FILL_IN_ACTION; } if ((other.mData != null || other.mType != null) && ((mData == null && mType == null) || (flags&FILL_IN_DATA) != 0)) { mData = other.mData; mType = other.mType; changes |= FILL_IN_DATA; } if (other.mCategories != null && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) { if (other.mCategories != null) { mCategories = new HashSet(other.mCategories); } changes |= FILL_IN_CATEGORIES; } if (other.mPackage != null && (mPackage == null || (flags&FILL_IN_PACKAGE) != 0)) { mPackage = other.mPackage; changes |= FILL_IN_PACKAGE; } // Component is special: it can -only- be set if explicitly allowed, // since otherwise the sender could force the intent somewhere the // originator didn't intend. if (other.mComponent != null && (flags&FILL_IN_COMPONENT) != 0) { mComponent = other.mComponent; changes |= FILL_IN_COMPONENT; } mFlags |= other.mFlags; if (mExtras == null) { if (other.mExtras != null) { mExtras = new Bundle(other.mExtras); } } else if (other.mExtras != null) { try { Bundle newb = new Bundle(other.mExtras); newb.putAll(mExtras); mExtras = newb; } catch (RuntimeException e) { // Modifying the extras can cause us to unparcel the contents // of the bundle, and if we do this in the system process that // may fail. We really should handle this (i.e., the Bundle // impl shouldn't be on top of a plain map), but for now just // ignore it and keep the original contents. :( Log.w("Intent", "Failure filling in extras", e); } } return changes; } /** * Wrapper class holding an Intent and implementing comparisons on it for * the purpose of filtering. The class implements its * {@link #equals equals()} and {@link #hashCode hashCode()} methods as * simple calls to {@link Intent#filterEquals(Intent)} filterEquals()} and * {@link android.content.Intent#filterHashCode()} filterHashCode()} * on the wrapped Intent. */ public static final class FilterComparison { private final Intent mIntent; private final int mHashCode; public FilterComparison(Intent intent) { mIntent = intent; mHashCode = intent.filterHashCode(); } /** * Return the Intent that this FilterComparison represents. * @return Returns the Intent held by the FilterComparison. Do * not modify! */ public Intent getIntent() { return mIntent; } @Override public boolean equals(Object obj) { if (obj instanceof FilterComparison) { Intent other = ((FilterComparison)obj).mIntent; return mIntent.filterEquals(other); } return false; } @Override public int hashCode() { return mHashCode; } } /** * Determine if two intents are the same for the purposes of intent * resolution (filtering). That is, if their action, data, type, * class, and categories are the same. This does not compare * any extra data included in the intents. * * @param other The other Intent to compare against. * * @return Returns true if action, data, type, class, and categories * are the same. */ public boolean filterEquals(Intent other) { if (other == null) { return false; } if (mAction != other.mAction) { if (mAction != null) { if (!mAction.equals(other.mAction)) { return false; } } else { if (!other.mAction.equals(mAction)) { return false; } } } if (mData != other.mData) { if (mData != null) { if (!mData.equals(other.mData)) { return false; } } else { if (!other.mData.equals(mData)) { return false; } } } if (mType != other.mType) { if (mType != null) { if (!mType.equals(other.mType)) { return false; } } else { if (!other.mType.equals(mType)) { return false; } } } if (mPackage != other.mPackage) { if (mPackage != null) { if (!mPackage.equals(other.mPackage)) { return false; } } else { if (!other.mPackage.equals(mPackage)) { return false; } } } if (mComponent != other.mComponent) { if (mComponent != null) { if (!mComponent.equals(other.mComponent)) { return false; } } else { if (!other.mComponent.equals(mComponent)) { return false; } } } if (mCategories != other.mCategories) { if (mCategories != null) { if (!mCategories.equals(other.mCategories)) { return false; } } else { if (!other.mCategories.equals(mCategories)) { return false; } } } return true; } /** * Generate hash code that matches semantics of filterEquals(). * * @return Returns the hash value of the action, data, type, class, and * categories. * * @see #filterEquals */ public int filterHashCode() { int code = 0; if (mAction != null) { code += mAction.hashCode(); } if (mData != null) { code += mData.hashCode(); } if (mType != null) { code += mType.hashCode(); } if (mPackage != null) { code += mPackage.hashCode(); } if (mComponent != null) { code += mComponent.hashCode(); } if (mCategories != null) { code += mCategories.hashCode(); } return code; } @Override public String toString() { StringBuilder b = new StringBuilder(128); b.append("Intent { "); toShortString(b, true, true); b.append(" }"); return b.toString(); } /** @hide */ public String toShortString(boolean comp, boolean extras) { StringBuilder b = new StringBuilder(128); toShortString(b, comp, extras); return b.toString(); } /** @hide */ public void toShortString(StringBuilder b, boolean comp, boolean extras) { boolean first = true; if (mAction != null) { b.append("act=").append(mAction); first = false; } if (mCategories != null) { if (!first) { b.append(' '); } first = false; b.append("cat=["); Iterator i = mCategories.iterator(); boolean didone = false; while (i.hasNext()) { if (didone) b.append(","); didone = true; b.append(i.next()); } b.append("]"); } if (mData != null) { if (!first) { b.append(' '); } first = false; b.append("dat=").append(mData); } if (mType != null) { if (!first) { b.append(' '); } first = false; b.append("typ=").append(mType); } if (mFlags != 0) { if (!first) { b.append(' '); } first = false; b.append("flg=0x").append(Integer.toHexString(mFlags)); } if (mPackage != null) { if (!first) { b.append(' '); } first = false; b.append("pkg=").append(mPackage); } if (comp && mComponent != null) { if (!first) { b.append(' '); } first = false; b.append("cmp=").append(mComponent.flattenToShortString()); } if (extras && mExtras != null) { if (!first) { b.append(' '); } first = false; b.append("(has extras)"); } } /** * Call {@link #toUri} with 0 flags. * @deprecated Use {@link #toUri} instead. */ @Deprecated public String toURI() { return toUri(0); } /** * Convert this Intent into a String holding a URI representation of it. * The returned URI string has been properly URI encoded, so it can be * used with {@link Uri#parse Uri.parse(String)}. The URI contains the * Intent's data as the base URI, with an additional fragment describing * the action, categories, type, flags, package, component, and extras. * *

You can convert the returned string back to an Intent with * {@link #getIntent}. * * @param flags Additional operating flags. Either 0 or * {@link #URI_INTENT_SCHEME}. * * @return Returns a URI encoding URI string describing the entire contents * of the Intent. */ public String toUri(int flags) { StringBuilder uri = new StringBuilder(128); String scheme = null; if (mData != null) { String data = mData.toString(); if ((flags&URI_INTENT_SCHEME) != 0) { final int N = data.length(); for (int i=0; i= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '.' || c == '-') { continue; } if (c == ':' && i > 0) { // Valid scheme. scheme = data.substring(0, i); uri.append("intent:"); data = data.substring(i+1); break; } // No scheme. break; } } uri.append(data); } else if ((flags&URI_INTENT_SCHEME) != 0) { uri.append("intent:"); } uri.append("#Intent;"); if (scheme != null) { uri.append("scheme=").append(scheme).append(';'); } if (mAction != null) { uri.append("action=").append(Uri.encode(mAction)).append(';'); } if (mCategories != null) { for (String category : mCategories) { uri.append("category=").append(Uri.encode(category)).append(';'); } } if (mType != null) { uri.append("type=").append(Uri.encode(mType, "/")).append(';'); } if (mFlags != 0) { uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';'); } if (mPackage != null) { uri.append("package=").append(Uri.encode(mPackage)).append(';'); } if (mComponent != null) { uri.append("component=").append(Uri.encode( mComponent.flattenToShortString(), "/")).append(';'); } if (mExtras != null) { for (String key : mExtras.keySet()) { final Object value = mExtras.get(key); char entryType = value instanceof String ? 'S' : value instanceof Boolean ? 'B' : value instanceof Byte ? 'b' : value instanceof Character ? 'c' : value instanceof Double ? 'd' : value instanceof Float ? 'f' : value instanceof Integer ? 'i' : value instanceof Long ? 'l' : value instanceof Short ? 's' : '\0'; if (entryType != '\0') { uri.append(entryType); uri.append('.'); uri.append(Uri.encode(key)); uri.append('='); uri.append(Uri.encode(value.toString())); uri.append(';'); } } } uri.append("end"); return uri.toString(); } public int describeContents() { return (mExtras != null) ? mExtras.describeContents() : 0; } public void writeToParcel(Parcel out, int flags) { out.writeString(mAction); Uri.writeToParcel(out, mData); out.writeString(mType); out.writeInt(mFlags); out.writeString(mPackage); ComponentName.writeToParcel(mComponent, out); if (mCategories != null) { out.writeInt(mCategories.size()); for (String category : mCategories) { out.writeString(category); } } else { out.writeInt(0); } out.writeBundle(mExtras); } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public Intent createFromParcel(Parcel in) { return new Intent(in); } public Intent[] newArray(int size) { return new Intent[size]; } }; private Intent(Parcel in) { readFromParcel(in); } public void readFromParcel(Parcel in) { mAction = in.readString(); mData = Uri.CREATOR.createFromParcel(in); mType = in.readString(); mFlags = in.readInt(); mPackage = in.readString(); mComponent = ComponentName.readFromParcel(in); int N = in.readInt(); if (N > 0) { mCategories = new HashSet(); int i; for (i=0; i tags to add categories and * to attach extra data * to the intent. * * @param resources The Resources to use when inflating resources. * @param parser The XML parser pointing at an "intent" tag. * @param attrs The AttributeSet interface for retrieving extended * attribute data at the current parser location. * @return An Intent object matching the XML data. * @throws XmlPullParserException If there was an XML parsing error. * @throws IOException If there was an I/O error. */ public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { Intent intent = new Intent(); TypedArray sa = resources.obtainAttributes(attrs, com.android.internal.R.styleable.Intent); intent.setAction(sa.getString(com.android.internal.R.styleable.Intent_action)); String data = sa.getString(com.android.internal.R.styleable.Intent_data); String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType); intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType); String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage); String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass); if (packageName != null && className != null) { intent.setComponent(new ComponentName(packageName, className)); } sa.recycle(); int outerDepth = parser.getDepth(); int type; while ((type=parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } String nodeName = parser.getName(); if (nodeName.equals("category")) { sa = resources.obtainAttributes(attrs, com.android.internal.R.styleable.IntentCategory); String cat = sa.getString(com.android.internal.R.styleable.IntentCategory_name); sa.recycle(); if (cat != null) { intent.addCategory(cat); } XmlUtils.skipCurrentTag(parser); } else if (nodeName.equals("extra")) { if (intent.mExtras == null) { intent.mExtras = new Bundle(); } resources.parseBundleExtra("extra", attrs, intent.mExtras); XmlUtils.skipCurrentTag(parser); } else { XmlUtils.skipCurrentTag(parser); } } return intent; } }

File
Intent.java
Developer's decision
Manual
Kind of conflict
Attribute
Comment