Courtesy: GitHub

Android TV Home Screen Channel / Programs Sample

This sample is designed to run on an Android TV device that run Android Oreo (API 26) or higher. It demonstrates how to interact with the home screen to add channels and programs to increase user engagement.

Introduction

This sample shows how to use TvContractCompat to add channels and programs to the home screen. For more information about how to integrate with the home screen, read the following:

Dependencies

To integrate with the home screen, you will need to add a new dependency, support-tv-provider. The leanback support library is also required for your app's UI and playback.

If you use Android Studio as recommended, the following dependencies will automatically be installed by Gradle.

implementation 'com.android.support:leanback-v17:26.x.x'
implementation 'com.android.support:support-tv-provider:26.x.x'

Getting Started

  • Clone this repo:
git clone https://github.com/googlesamples/leanback-homescreen-channels.git
  • Open the project in Android Studio.
  • Compile and deploy to your emulator or Android TV device (such as a Nexus Player).

Need more information about getting started with Android TV? Check the official docs.

Screenshots

Screenshot

Screenshot

Screenshot

Screenshot

Support

If you need additional help, our community might be able to help.

Contributing

We love contributions! :smile: Please follow the steps in the CONTRIBUTING guide to get started. If you found a bug, please file it here.

License

Licensed under the Apache 2.0 license. See the LICENSE file for details.

compileSdkVersion 26

applicationId "com.google.android.tvhomescreenchannels"

minSdkVersion 26

targetSdkVersion 26

versionCode 1

versionName "1.0"

compile fileTree(include: ['*.jar'], dir: 'libs')

compile 'com.android.support:appcompat-v7:26.1.0'

compile 'com.android.support:leanback-v17:26.1.0'

compile 'com.android.support:support-tv-provider:26.1.0'

compile 'com.github.bumptech.glide:glide:4.1.1'

package com.google.android.tvhomescreenchannels

uses-permission

  • android.permission.INTERNET
  • android.permission.RECORD_AUDIO
  • android.permission.RECEIVE_BOOT_COMPLETED
  • com.android.providers.tv.permission.WRITE_EPG_DATA
  • com.android.providers.tv.permission.READ_EPG_DATA

MainActivity

PlaybackActivity

PlaybackActivity for video playback that loads VideoFragment

TvSearchActivity

RecommendationReceiverActivity

SynchronizeDatabaseJobService

JobScheduler task to synchronize the TV provider database with the desired list of channels and programs. This sample app runs this once at install time to publish an initial set of channels and programs, however in a real-world setting this might be run at other times to synchronize a server's database with the TV provider database. This code will ensure that the channels from "SampleClipApi.getDesiredPublishedChannelSet()" appear in the TV provider database, and that these and all other programs are synchronized with TV provider database.

Publish any default channels not already published.

AddWatchNextService

The service that's scheduled to run the task of adding a video to the watch next playlist on a background thread.

Add a video to the watch next playlist on a background thread.

DeleteWatchNextService

The service that's scheduled to run the task of deleting a video from the watch next playlist on a background thread.

Deletes a video from the watch next playlist on a background thread.

RunOnInstallReceiver

LauncherNotificationReceiver