FileDocCategorySizeDatePackage
TvContract.javaAPI DocAndroid 5.1 API50270Thu Mar 12 22:22:30 GMT 2015android.media.tv

TvContract

public final class TvContract extends Object

The contract between the TV provider and applications. Contains definitions for the supported URIs and columns.

Overview

TvContract defines a basic database of TV content metadata such as channel and program information. The information is stored in {@link Channels} and {@link Programs} tables.

  • A row in the {@link Channels} table represents information about a TV channel. The data format can vary greatly from standard to standard or according to service provider, thus the columns here are mostly comprised of basic entities that are usually seen to users regardless of standard such as channel number and name.
  • A row in the {@link Programs} table represents a set of data describing a TV program such as program title and start time.

Fields Summary
public static final String
AUTHORITY
The authority for the TV provider.
private static final String
PATH_CHANNEL
private static final String
PATH_PROGRAM
private static final String
PATH_PASSTHROUGH
public static final String
PARAM_INPUT
An optional query, update or delete URI parameter that allows the caller to specify TV input ID to filter channels.
public static final String
PARAM_CHANNEL
An optional query, update or delete URI parameter that allows the caller to specify channel ID to filter programs.
public static final String
PARAM_START_TIME
An optional query, update or delete URI parameter that allows the caller to specify start time (in milliseconds since the epoch) to filter programs.
public static final String
PARAM_END_TIME
An optional query, update or delete URI parameter that allows the caller to specify end time (in milliseconds since the epoch) to filter programs.
public static final String
PARAM_BROWSABLE_ONLY
A query, update or delete URI parameter that allows the caller to operate on all or browsable-only channels. If set to "true", the rows that contain non-browsable channels are not affected.
public static final String
PARAM_CANONICAL_GENRE
A optional query, update or delete URI parameter that allows the caller to specify canonical genre to filter programs.
Constructors Summary
private TvContract()

Methods Summary
public static final android.net.UribuildChannelLogoUri(long channelId)
Builds a URI that points to a channel logo. See {@link Channels.Logo}.

param
channelId The ID of the channel whose logo is pointed to.

        return buildChannelLogoUri(buildChannelUri(channelId));
    
public static final android.net.UribuildChannelLogoUri(android.net.Uri channelUri)
Builds a URI that points to a channel logo. See {@link Channels.Logo}.

param
channelUri The URI of the channel whose logo is pointed to.

        if (!isChannelUriForTunerInput(channelUri)) {
            throw new IllegalArgumentException("Not a channel: " + channelUri);
        }
        return Uri.withAppendedPath(channelUri, Channels.Logo.CONTENT_DIRECTORY);
    
public static final android.net.UribuildChannelUri(long channelId)
Builds a URI that points to a specific channel.

param
channelId The ID of the channel to point to.

        return ContentUris.withAppendedId(Channels.CONTENT_URI, channelId);
    
public static final android.net.UribuildChannelUriForPassthroughInput(java.lang.String inputId)
Build a special channel URI intended to be used with pass-through inputs. (e.g. HDMI)

param
inputId The ID of the pass-through input to build a channels URI for.
see
TvInputInfo#isPassthroughInput()

        return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY)
                .appendPath(PATH_PASSTHROUGH).appendPath(inputId).build();
    
public static final android.net.UribuildChannelsUriForInput(java.lang.String inputId)
Builds a URI that points to all channels from a given TV input.

param
inputId The ID of the TV input to build a channels URI for. If {@code null}, builds a URI for all the TV inputs.

        return buildChannelsUriForInput(inputId, false);
    
public static final android.net.UribuildChannelsUriForInput(java.lang.String inputId, boolean browsableOnly)
Builds a URI that points to all or browsable-only channels from a given TV input.

param
inputId The ID of the TV input to build a channels URI for. If {@code null}, builds a URI for all the TV inputs.
param
browsableOnly If set to {@code true} the URI points to only browsable channels. If set to {@code false} the URI points to all channels regardless of whether they are browsable or not.
hide

        Uri.Builder builder = Channels.CONTENT_URI.buildUpon();
        if (inputId != null) {
            builder.appendQueryParameter(PARAM_INPUT, inputId);
        }
        return builder.appendQueryParameter(PARAM_BROWSABLE_ONLY, String.valueOf(browsableOnly))
                .build();
    
public static final android.net.UribuildChannelsUriForInput(java.lang.String inputId, java.lang.String genre, boolean browsableOnly)
Builds a URI that points to all or browsable-only channels which have programs with the given genre from the given TV input.

param
inputId The ID of the TV input to build a channels URI for. If {@code null}, builds a URI for all the TV inputs.
param
genre {@link Programs.Genres} to search. If {@code null}, builds a URI for all genres.
param
browsableOnly If set to {@code true} the URI points to only browsable channels. If set to {@code false} the URI points to all channels regardless of whether they are browsable or not.
hide

        if (genre == null) {
            return buildChannelsUriForInput(inputId, browsableOnly);
        }
        if (!Programs.Genres.isCanonical(genre)) {
            throw new IllegalArgumentException("Not a canonical genre: '" + genre + "'");
        }
        return buildChannelsUriForInput(inputId, browsableOnly).buildUpon()
                .appendQueryParameter(PARAM_CANONICAL_GENRE, genre).build();
    
public static final java.lang.StringbuildInputId(android.content.ComponentName name)
Builds an ID that uniquely identifies a TV input service.

param
name The {@link ComponentName} of the TV input service to build ID for.
return
the ID for the given TV input service.


                                          
          
        return name.flattenToShortString();
    
public static final android.net.UribuildProgramUri(long programId)
Builds a URI that points to a specific program.

param
programId The ID of the program to point to.

        return ContentUris.withAppendedId(Programs.CONTENT_URI, programId);
    
public static final android.net.UribuildProgramsUriForChannel(long channelId)
Builds a URI that points to all programs on a given channel.

param
channelId The ID of the channel to return programs for.

        return Programs.CONTENT_URI.buildUpon()
                .appendQueryParameter(PARAM_CHANNEL, String.valueOf(channelId)).build();
    
public static final android.net.UribuildProgramsUriForChannel(android.net.Uri channelUri)
Builds a URI that points to all programs on a given channel.

param
channelUri The URI of the channel to return programs for.

        if (!isChannelUriForTunerInput(channelUri)) {
            throw new IllegalArgumentException("Not a channel: " + channelUri);
        }
        return buildProgramsUriForChannel(ContentUris.parseId(channelUri));
    
public static final android.net.UribuildProgramsUriForChannel(long channelId, long startTime, long endTime)
Builds a URI that points to programs on a specific channel whose schedules overlap with the given time frame.

param
channelId The ID of the channel to return programs for.
param
startTime The start time used to filter programs. The returned programs should have {@link Programs#COLUMN_END_TIME_UTC_MILLIS} that is greater than this time.
param
endTime The end time used to filter programs. The returned programs should have {@link Programs#COLUMN_START_TIME_UTC_MILLIS} that is less than this time.

        Uri uri = buildProgramsUriForChannel(channelId);
        return uri.buildUpon().appendQueryParameter(PARAM_START_TIME, String.valueOf(startTime))
                .appendQueryParameter(PARAM_END_TIME, String.valueOf(endTime)).build();
    
public static final android.net.UribuildProgramsUriForChannel(android.net.Uri channelUri, long startTime, long endTime)
Builds a URI that points to programs on a specific channel whose schedules overlap with the given time frame.

param
channelUri The URI of the channel to return programs for.
param
startTime The start time used to filter programs. The returned programs should have {@link Programs#COLUMN_END_TIME_UTC_MILLIS} that is greater than this time.
param
endTime The end time used to filter programs. The returned programs should have {@link Programs#COLUMN_START_TIME_UTC_MILLIS} that is less than this time.

        if (!isChannelUriForTunerInput(channelUri)) {
            throw new IllegalArgumentException("Not a channel: " + channelUri);
        }
        return buildProgramsUriForChannel(ContentUris.parseId(channelUri), startTime, endTime);
    
public static final android.net.UribuildWatchedProgramUri(long watchedProgramId)
Builds a URI that points to a specific program the user watched.

param
watchedProgramId The ID of the watched program to point to.
hide

        return ContentUris.withAppendedId(WatchedPrograms.CONTENT_URI, watchedProgramId);
    
public static final booleanisChannelUri(android.net.Uri uri)
Returns true, if {@code uri} is a channel URI.

hide

        return isChannelUriForTunerInput(uri) || isChannelUriForPassthroughInput(uri);
    
public static final booleanisChannelUriForPassthroughInput(android.net.Uri uri)
Returns true, if {@code uri} is a channel URI for a passthrough input.

hide

        return isTvUri(uri) && isTwoSegmentUriStartingWith(uri, PATH_PASSTHROUGH);
    
public static final booleanisChannelUriForTunerInput(android.net.Uri uri)
Returns true, if {@code uri} is a channel URI for a tuner input.

hide

        return isTvUri(uri) && isTwoSegmentUriStartingWith(uri, PATH_CHANNEL);
    
public static final booleanisProgramUri(android.net.Uri uri)
Returns true, if {@code uri} is a program URI.

hide

        return isTvUri(uri) && isTwoSegmentUriStartingWith(uri, PATH_PROGRAM);
    
private static final booleanisTvUri(android.net.Uri uri)

        return uri != null && ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())
                && AUTHORITY.equals(uri.getAuthority());
    
private static final booleanisTwoSegmentUriStartingWith(android.net.Uri uri, java.lang.String pathSegment)

        List<String> pathSegments = uri.getPathSegments();
        return pathSegments.size() == 2 && pathSegment.equals(pathSegments.get(0));