MimeTypeFilter

Added in 1.1.0

public final class MimeTypeFilter


Provides utility methods for matching MIME type filters used in ContentProvider.

Wildcards are allowed only instead of the entire type or subtype with a tree prefix. Eg. image\/*, *\/* is a valid filter and will match image/jpeg, but image/j* is invalid and it will not match image/jpeg. Suffixes and parameters are not supported, and they are treated as part of the subtype during matching. Neither type nor subtype can be empty.

Note: MIME type 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 to ensure that they are converted to lower case.

MIME types can be null or ill-formatted. In such case they won't match anything.

MIME type filters must be correctly formatted, or an exception will be thrown.

Summary

Public methods

static boolean
matches(@Nullable String mimeType, @NonNull String filter)

Matches one nullable MIME type against one MIME type filter.

static @Nullable String
matches(@Nullable String mimeType, @NonNull String[] filters)

Matches one nullable MIME type against an array of MIME type filters.

static @Nullable String
matches(@Nullable String[] mimeTypes, @NonNull String filter)

Matches multiple MIME types against an array of MIME type filters.

static @NonNull String[]
matchesMany(@Nullable String[] mimeTypes, @NonNull String filter)

Matches multiple MIME types against an array of MIME type filters.

Public methods

matches

Added in 1.1.0
public static boolean matches(@Nullable String mimeType, @NonNull String filter)

Matches one nullable MIME type against one MIME type filter.

Returns
boolean

True if the mimeType matches the filter.

matches

Added in 1.1.0
public static @Nullable String matches(@Nullable String mimeType, @NonNull String[] filters)

Matches one nullable MIME type against an array of MIME type filters.

Returns
@Nullable String

The first matching filter, or null if nothing matches.

matches

Added in 1.1.0
public static @Nullable String matches(@Nullable String[] mimeTypes, @NonNull String filter)

Matches multiple MIME types against an array of MIME type filters.

Returns
@Nullable String

The first matching MIME type, or null if nothing matches.

matchesMany

Added in 1.1.0
public static @NonNull String[] matchesMany(@Nullable String[] mimeTypes, @NonNull String filter)

Matches multiple MIME types against an array of MIME type filters.

Returns
@NonNull String[]

The list of matching MIME types, or empty array if nothing matches.