Android 的坑:Intent setData and setType

public Intent setData (Uri data)

Added in API level 1
Set the data this intent is operating on. This method automatically clears any type that was previously set by setType(String) or setTypeAndNormalize(String).

Note: scheme matching in the Android framework is case-sensitive, unlike the formal RFC. As a result, you should always write your Uri with a lower case scheme, or use normalizeScheme() or setDataAndNormalize(Uri) to ensure that the scheme is converted to lower case.

Parameters
data	The Uri of the data this intent is now targeting.
Returns
Returns the same Intent object, for chaining multiple calls into a single statement.

public Intent setType (String type)

Added in API level 1
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 (for example by setData(Uri)).

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, or use normalizeMimeType(String) or setTypeAndNormalize(String) to ensure that it is converted to lower case.

Parameters
type	The MIME type of the data being handled by this intent.
Returns
Returns the same Intent object, for chaining multiple calls into a single statement.

public Intent setDataAndType (Uri data, String type)

Added in API level 1
(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 and Uri scheme 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, or use normalizeMimeType(String) or normalizeScheme() or setDataAndTypeAndNormalize(Uri, String) to ensure that they are converted to lower case.

Parameters
data	The Uri of the data this intent is now targeting.
type	The MIME type of the data being handled by this intent.
Returns
Returns the same Intent object, for chaining multiple calls into a single statement.

看下源码:

public Intent setData(Uri data) {
    mData = data;
    mType = null;
    return this;
}

public Intent setType(String type) {
    mData = null;
    mType = type;
    return this;
}

public Intent setDataAndType(Uri data, String type) {
    mData = data;
    mType = type;
    return this;
}

真是坑啊。