AndroidTV Screensavers: Show Images from Your TV App

Sanjeev Pandey
InterviewNoodle
Published in
3 min readJan 11, 2022

--

This article explains how you can show screensavers from your own app instead of AndroidTV’s default one by provided by Chromecast.

If you are an AndroidTV developer then you know that there is not much good documentation available for developing apps for TV, and more often than not you keep running into problems or feature requirements which have bare-bone documentation from platform/OEM provider but it is hard to find a sample implementation.

When we tried to implement this feature — showing images from our TV app as the screensaver on TV instead of what is provided by default by TV’s Android OS — we actually found no reference implementations for it so, when we were able to work it out, I decided to write one if it meant that it would make others’ lives easier.

So, here goes; surprisingly the answer to it is really simple and thus this will not be a very long article. Now, either you knew already or from the context above you have deduced that AndroidTV uses the screensavers provided by Chromecast; in order for us to show our images when the user goes idle on our app’s screen, we needed to simply override this and then implement our own collection and introduce a circular loop with configurable timer for switching to next image.

Follow these steps:

  1. Disable Chromecast screensaver throughout the app by setting android:keepScreenOn=”true” in XML layout :
  2. Create our own UI and implementation for the screensaver: Set the view to full screen, with multiple images scrolling in circular manner triggered by a preset time (time can be configured from backend)
  3. Use local images to set over the screensaver screen (images can also come from your CMS)
  4. The screensaver invoke time can also be configurable from backend or we can be hardcoded same as Chromecast’s screensaver
  5. After the invoke time lapses, the screensaver invokes; the duration timer resets & starts again when any key is pressed on TV remote

Limitation:

This does not work over any 3rd party app i.e. your screensavers will show on TV when user is idle on any screen while using your app. However, if they switch to any other app on TV and go idle then, then TV will show default screensaver from Chromecast.

Recommendations:

  1. For global implementation (to display our screensaver over all apps, not just your own app), we would need a service which always runs in background and handles things like Chromecast screensaver. For this, you can consider Dream Service
  2. To use Dream Service, you would need a separate APK installed as a system app with firmware

Some questions you need to ask & answer as the architect or lead developer:

  1. How often would you fetch the new assets for the Screensavers from your CMS e.g. on every launch, every standby, or at fixed time intervals like app’s home page refresh, and what would be the impact of this on the app performance and backend load?
  2. In case of API failure (the one that returns the images from CMS), would you create a fallback of showing images from cache, considering that caching will increase the cache size on the box (storage) when loading again.
  3. In case of the API failures for a first time user, since the app will not have images in cache, what would you do? E.g. would you not show anything or pre-bundle some images as part of the app build? Considering that pre-bundling some fallback images in the app to cater this one edge case will increase the app size hence maybe this is not favourable?
  4. In case you would want to track if users are seeing your screensaver so that you can monetize this space, how would you track the trigger of screensaver and duration it was shown for per user type/ demographic or time-based distribution etc.? Also consider in this case, if tracking the screen-name they are going on idle from is useful?

And that’s it, voila! Now you know how to show screensavers from your own app and the questions you need to answer if you’re asked to build such a feature.

--

--

Co-Founder of <indvideotech> community for Video Engineers in India. Solution Architect, Full-Stack Developer, Ad Insertion Evangelist, and Think Tank.