Google TV

Channel Listing Provider

  1. Channel listing provider
  2. Programmatic channel control
  3. String constants
  4. Application permission element
  5. Example: querying the provider

The Google TV Channel Listing content provider contains a list of channel callsigns and channel numbers for the current TV provider. Please remember that the "Channel Listing" is a static list of subscribed channels available on the device. This does not give information about the currently playing shows or a "program guide" type information. The list is automatically loaded into the content provider whenever the user connects the Google TV device to a TV provider for the first time. Once the data is loaded, any Android application can read the data using Android's content provider framework. The provider itself is not an add-on, but a standard part of Google TV.

Note: Channel Listing Provider will not return channels on Google TV devices paired with DISH DVRs.

Based on data from the provider, your application can switch to a particular channel. To learn more about this, please read the section on Channel Changing.

Channel Listing Provider

The channel listing content provider contains a single table in which each row represents a channel listing and each column represents a different piece of information about the channel. Table 1 "Channel listing provider" describes the table's organization:

Table 1. Channel listing provider
Column name Data type Description
_id Integer Unique identifier for the row (note the underscore at the beginning of the column name).
channel_uri String A string representation of a URI for this channel. To switch to the channel associated with this row, pass the URI to the TV player app in an Action_View intent.
callsign String The station call sign for this channel. You can use this column as a unique identifier for the row, but parts of the value may appear multiple times in the provider's table. For example, "ESPN" and "ESPN Classic" are different call signs although they both contain "ESPN".
channel_name String The channel name for this channel. This is usually a longer and more descriptive string than the call sign.
channel_number String The TV provider's channel number for this channel. This value may not be unique within the provider, and its format is controlled by individual TV providers.

Programmatic channel control

You can use a URI from the channel listing content provider to programmatically change channels. To learn how to do this, please read the section "Programmatic channel control" in the topic Features Specific to Google TV.

String constants

The following string values are used with the provider:

  • provider authority: "com.google.android.tv.provider"
  • channel listing table path: "channel_listing"
  • table column names (same as those listed in table 1):
    • row identifier: "_id" (note the underscore)
    • URI string representation: "channel_uri"
    • channel's callsign: "callsign"
    • channel's name: "channel_name"
    • channel's number: "channel_number"

Application permission element

To use the provider, your application must specify a <uses-permission> element for reading data from the provider. The element goes in your manifest (AndroidManifest.xml). During installation, users are notified that your application wants to read the "channel lineup". The form of this element is:

    <uses-permission android:name="com.google.android.tv.permission.READ_CHANNELS" />

The <uses-permission> element is a child of the <manifest> element.

Example: querying the provider

Here is a code snippet that uses these constants to make a query against the channel listing provider:


import android.content.ContentResolver;
import android.net.Uri;
import android.database.Cursor;

/*
 * Variables
 */

/*
 * creates a content URI that points to the channel listing content provider, and
 * within it the channel listing table.
 */
Uri mProviderUri = Uri.parse("content://" + "com.google.android.tv.provider" + "/" + "channel_listing");

// Defines a string array containing the columns to retrieve (the projection)
String[] mProjection = {"channel_uri", "callsign", "channel_number"};

/* Defines a string to hold the 'where' clause for the query. This definition
 * queries the 'callsign' column for a value that is provided in a separate argument
 */
String mWhere = "callsign = ?";

// Defines a string array to hold the value to compare to the 'callsign' column
String[] mCriteria = {"CNBC"};

/*
 * Makes the query
 */

Cursor mCursor = getContentResolver().query(mProviderUri,               // the content URI of the provider
                                            mProjection,                // the columns to return
                                            mWhere,                     // the column to match against
                                            mCriteria,                  // the matching value
                                            "channel_number" + " ASC"   // the sort order
                  );

/*
 * Demonstrates how to use the column name to retrieve a value from a row in
 * the cursor.
 */

// Tests for an internal error.
if (null == mCursor) {

    // an internal error occurred
    log.e("Sample","internal error");
    return;
 }

// Tests that the cursor is not empty
if (0 == mCursor.getCount()) {

    // display a message
    Toast.makeText(this,"no callsign found that matches CNBC",Toast.LENGTH_LONG).show();
    return;
}

// Moves to the first row
mCursor.moveToFirst();

/* Displays a channel number for call sign 'CNBC'. Remember that the provider may contain
 * multiple rows for the same call sign. This call displays the channel number with the lowest
 * string value
 */
Toast.makeText(this,
               "For call sign CNBC, the first channel number is " + mCursor.getString(mCursor.getColumnIndex("channel_number")),
               Toast.LENGTH_LONG).show();

Note: Remember to add the <uses-permission> element to your app's manifest, as described previously.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.