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>
LEANBACK_LAUNCHERis what puts the app in the TV's app list. KeepingLAUNCHERtoo lets the same APK open on phones and emulators.- Touchscreen
required="false": without it the app counts as needing a touchscreen, which a TV lacks. android:banner: a 320×180 px image (drawable-xhdpi) shown on the TV home row instead of the square icon. Generate it with the icon script so it can be rebuilt; the adaptive launcher icon is still required.
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
- Remote keys: override
dispatchKeyEventin the player activity. A common mapping: OK/Enter = play/pause, left/right = seek 10 s while the controls are hidden, up/down = show the controls, Back = hide the controls first and leave on a second press. Handle the media keys too (KEYCODE_MEDIA_PLAY_PAUSE,_PLAY,_PAUSE,_FAST_FORWARD,_REWIND,_NEXT,_PREVIOUS): many remotes and HDMI-CEC send them. - Codec choice: only pick an HEVC or AV1 rendition when the device has a hardware decoder for it: scan
MediaCodecList(REGULAR_CODECS).codecInfosfor a decoder ofvideo/hevc/video/av01withisHardwareAccelerated(API 29+). Software HEVC on a TV SoC stutters. Keep an H.264 rendition that always exists and fall back to it on a decoder error. See Encoding phone clips for the web (HEVC remux, H.264 fallback). - Display rotation: a rotation stored in the catalog (applied with CSS on the web, Rotating video in CSS instead of re-encoding) becomes a rotation of a
TextureView; then aPlayerViewwithsurface_type="none"draws only the controls on top. The file's own rotation metadata is already applied by the decoder and is reflected inVideoSize, so don't apply it twice. - Signed URLs expire: if video URLs are pre-signed object-storage links (6 h in this case), refetch the catalog when fewer than half the lifetime remains, and on a playback error re-sign once before giving up.
- Resume per video (store the position by slug) and autoplay the next episode, matching what the web player does.
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
- Downloader app (free, in the TV's Play Store): enter the APK URL (e.g.
apps.jhampton.io/tv.apk), then allow Downloader to install unknown apps when asked. - adb over the network: enable Developer options on the TV (tap the build number 7 times), turn on network debugging, then
adb connect <tv-ip>andadb install app.apkfrom the desktop. - After that, an in-app updater reading the F-Droid repo delivers new versions (In-app updates for sideloaded Android apps, A self-hosted F-Droid repository and APK catalog).
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
- Forgetting
LEANBACK_LAUNCHERor the banner: the app installs but doesn't show in the TV's app list (it hides in Settings > Apps). - Encrypted videos that are decrypted by a browser service worker can't play in a native app without porting the decryption; list them as unplayable rather than failing silently.
See also
- videos.jhampton.io (private video site architecture)
- Making a Jetpack Compose app feel premium
- Android app signing keys and why losing one is permanent