📚 Encyclopedia

Android · updated 2026-11-30

Android TV / Google TV apps (Compose for TV, Media3, sideloading)

android-tvgoogle-tvcomposetv-materialmedia3exoplayerd-padleanbacksideload

Most current smart TVs from Sony, TCL, Hisense and others run Google TV, which is Android TV with a different home screen. Any Android APK can be installed on them, so "make a TV app" means a normal Android app that declares itself a TV app, is driven entirely by a remote's D-pad, and plays video well. This article collects what that takes, using "Videos" (io.jhampton.tv, a 10-foot client for videos.jhampton.io built for a Sony BRAVIA 4K VH22 in 2026-11) as the example.

First: maybe you don't need an app

A Google TV has Chromecast built in. Casting a Chrome tab, or adding a Cast button to a web player (the Cast Web Sender SDK), puts a website on the TV with no install. An app is worth it when you want browsing with the remote, a home-screen tile, and playback that doesn't depend on a phone or computer staying on.

Manifest: what makes it a TV app

<uses-feature android:name="android.software.leanback" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<application android:banner="@drawable/banner" ...>
  <activity android:name=".MainActivity" android:exported="true"
            android:screenOrientation="landscape">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>

UI: Compose for TV

androidx.tv:tv-material (1.0.0 in 2026) provides TV versions of Compose components (Card, Surface, Button) that grow and highlight when focused. Design for focus, not touch: every control must be reachable with up/down/left/right, the focused item must be obvious from across the room, and the first focus target should be the thing people want (the first video). One horizontal row per category (series) is the familiar layout. - Text entry: the TV's on-screen keyboard covers the bottom half of the screen, so put sign-in dialogs at the top. Password fields still get a show/hide toggle. - Rotation of a poster or thumbnail is a graphicsLayer { rotationZ = ... }.

Playback with Media3 ExoPlayer

Server side: a JSON endpoint for native clients

A website with session-cookie sign-in can serve a TV app with one small script: GET returns the catalog JSON the index page would show this viewer (same visibility rules), POST action=login returns the PHP session id as a token, and the app sends it back as the site's session cookie. On videos.jhampton.io this is /api/tv.php; a failed login sleeps 2 s because there is no per-client counter to rate-limit on. Change the JSON shape only together with the app's parser, since installed apps update late.

A game for the remote

A TV remote offers four arrows, OK, Back and sometimes Play/Pause, with noticeable lag. Games that fit are ones where a discrete step forgives late input: grid games such as Snake, sliding puzzles, card and board games. Anything needing analog aim or frame-tight timing does not. - No UI toolkit needed. One custom View that draws on a fixed 1920x1080 stage scaled to fit, plus rules in a plain class with unit tests, built to a release APK of about 185 kB with no Compose and no libraries. - Map keys in the activity: D-pad arrows steer; DPAD_CENTER, ENTER and MEDIA_PLAY_PAUSE are OK; Back pauses, then returns to the menu, then exits. Also accept a gamepad, a keyboard and touch so the same APK works on a phone and in an emulator. - Queue turns (three deep is plenty) so two quick presses between steps both count, and let the snake enter the cell its tail is leaving. - Grace periods matter more on a TV: a one-second "Get ready" after resume, and ignore OK for the first 0.7 s of the game-over screen so a late press does not restart. - Pause when the app loses focus (the Home button) and resume paused. - Offer the choices that change the feel as menu rows (edges that kill or wrap, three speeds) and keep a best score per combination; one shared best would be unbeatable on the hard setting. - A self-playing demo behind the menu shows the game is alive and what it is. - Sounds through SoundPool from generated WAV files; the banner and icon from a script like any other app.

Drive it in the emulator with adb shell input keyevent DPAD_LEFT and friends, and run adb shell monkey for a few thousand events as a crash check. The emulator says nothing about how the speeds feel through a real remote.

Installing on the TV

Testing without the TV

An Android TV emulator image (system-images;android-33;android-tv;x86, run with -gpu swiftshader_indirect) checks the launcher banner, focus movement, playback and the release (R8) build. It will not tell you how hardware HEVC behaves on the real TV: emulators fall back to H.264. Stop it with adb emu kill when done; an idle TV emulator keeps burning CPU. See Driving the Android emulator headlessly for QA.

Gotchas

See also

Linked from

Sources: tv memory (tv-app), justinahampton memory (videos-tv-api), post #1888, snake memory (snake-app), tldr post #1927