Build an Android TV app using Contentstack’s Android SDK
This demo Android TV app is built using Contentstack’s Android SDK. It uses Contentstack to store and deliver the content of the TV app.
Warning: This sample app is no longer maintained. It remains available for reference. If you have questions regarding this, please reach out to our support team and we will do our best to help!
Here’s a quick guide on how to create an Android TV app using Contentstack’s Android SDK.
- Android Studio account
- Contentstack Account
Note: For this tutorial, we have assumed that you are familiar with Contentstack and Android. If not, then please refer to the Contentstack docs for more details.
In this tutorial, we will first go through the steps involved in configuring Contentstack, and then look at the steps required to customize and use the presentation layer.
Set Up Your App
Here is an overview of the steps involved in creating our app:
- Create a Stack
- Add a Publishing Environment
- Import Content Types
- Adding Content
- Set up Android Studio and Initialize Android SDK
- Clone and Configure the Application
- Build and run your news app
Create a stack
Add a publishing environment
To add an environment in Contentstack, navigate to ‘Settings' -> 'Environment', and click on the '+ New Environment’ tab. Provide a suitable name for your environment, say ‘staging’. Specify the base URL (e.g., ‘http://YourDomainName.com’), and select the language (e.g., English - United States). Then, click on 'Save'. Read more about environments.
Import content types
A content type is like the structure or blueprint of a page or a section of your web or mobile property. Read more about Content Types.
For this website, four basic content types are required: New Release, Most Watched, TV Shows, and Top Rated. For quick integration, we have already created these content types. You simply need to import them to your stack. Refer to our Create a Content Type documentation to learn how to create your own content types.
To import these content types, first save the zipped folder of the JSON files given below on your local machine. Extract the files from the folder. Then, go to your stack in Contentstack. The next screen prompts you to either create a new content type or import one into your stack. Click the ‘import’ link, and select the JSON file saved on your machine.
Here’s a brief overview of the content types required for this project.
- New Release: The 'New Release' content type lets you add content for the New Release section of the app.
- Most Watched: The 'Most Watched' content type lets you add content for the Most Watched section of the app.
- TV Shows: The 'TV Shows' content type lets you add content for the TV Shows section of the app.
- Top Rated: The 'Top Rated' content type lets you add content for the Top Rated section of the app.
Now that all the content types are ready, let’s add some content for your Android TV app.
Create and publish entries for the ‘New Release’, ‘Most Watched’, ‘TV Shows’, and ‘Top Rated’ content types
With this step, you have created sample data for your app. Now, it’s time to use and configure the presentation layer.
Set up Android Studio and initialize Android SDK
To set up Android Studio and initialize Android SDK, refer to our Get Started with Android SDK documentation.
Clone and configure the application
To get your app up and running quickly, we have created a sample Android app for this project. You need to download it and change the configuration. Download the app using the command given below:
$ git clone https://github.com/contentstack/contentstack-android-tv.git
Once you have downloaded the project, add your Contentstack API Key, Delivery Token, and Environment to the project during the SDK initialization step. (Learn how to find your Stack's API Key and Delivery Token.)
Stack stack = Contentstack.stack(context, "API_key","delivery_token","environment_name");
This will initiate your project.
Build and run your news app
Now that we have a working project, you can build and run it.
Additional Resource: We have used the Contentstack Android SDK to build an example news app. To learn more, read our guide on how to build an Android news app using Contentstack’s Android SDK.