The short answer
A phone is a sensor kit, a speaker, a microphone and a small computer that can run real machine-learning models with no connection. Most apps use a fraction of it. The lessons that mattered most to me: read sensors only while a screen needs them, and smooth what they say before you act on it. Let the app's look follow the moment, but never change it under someone who's reading. With video, decode in order rather than seek for every frame, and copy streams rather than re-encode when you can. Treat "on the device" as a promise, and never quietly fall back to a server. Test on old, cheap and odd phones, because that's where native libraries and haptics break. And give every page a link, because that's how assistants and agents get in today.
One thing I'm deliberately leaving out: how CricCuts decides what counts as a shot. That's the product's own recipe. Everything below is about the Android platform around it, and the code is simplified to show the idea.
The phone is a sensor kit
Most phones carry a light sensor, an accelerometer and a gyroscope, and Android fuses them into a gravity sensor that's cleaner than the raw accelerometer. None of them needs a runtime permission. CricCuts uses them in small ways that add up:
- The light in the room. In the Auto look, the Academy's reading pages turn light in a bright room and dark in a dim one. The light sensor is read only while the app is open, and the readings never leave the phone.
- A ground with depth. On Home, the stands and the pitch slide a few pixels toward the low side as you tilt the phone, the pitch further than the stands. It's the gravity sensor, and it makes a flat drawing feel like a place.
- A science lab in your pocket. The Academy's Pocket Lab turns the phone into instruments: a Tilt test that follows the phone's angle live, and a Light meter that reads the room in lux.
- Measuring the pitch. The recorder's pitch walk, an early version for adults, finds 22 yards as you walk the pitch with the phone, using Google's ARCore. It's a rough guide, not a measuring tape.
The light sensor taught me two things. First, raw lux jumps around: a hand passing over the sensor would flip the pages back and forth. The fix is hysteresis, two thresholds at each edge, so the pages turn light at 30 lux but don't turn back until the room falls below 22. It also takes the middle of the last three seconds of readings, so a passing shadow decides nothing:
// Two thresholds per edge, so a passing hand can't make the pages flicker.
fun classify(previous: RoomLevel, lux: Float): RoomLevel = when {
lux >= 30f -> RoomLevel.BRIGHT
previous == RoomLevel.BRIGHT && lux >= 22f -> RoomLevel.BRIGHT
lux <= 15f -> RoomLevel.DIM
previous == RoomLevel.DIM && lux <= 18f -> RoomLevel.DIM
else -> RoomLevel.BETWEEN
}
Second, never change a page under someone who's reading it. Inside a lesson, CricCuts asks first ("Light pages? · Switch"). Anywhere else, a banner says why the look changed ("☀️ Bright here, so pages are light"), with a button to keep the other one.
DisposableEffect and unregister in its onDispose. A listener left running drains the
battery and keeps reporting to a screen nobody is looking at.Looks that follow the hour and the room
CricCuts has four looks: Floodlights (a night stadium), Daylight (light pages), Scoreboard and Super Over. You can pick one, get a new one each time you open the app (Surprise me), let Home follow the time of day, or choose Auto, where each part of the app wears the look that suits it:
- Home follows the sun. Dawn, day, evening and night start at the real sunrise and sunset for the city in your profile, worked out on the phone with no location permission. Without a city, it uses clock times.
- The reading pages follow the room. The Academy, the Laws and Settings turn light or dark with the light sensor, as above.
- The games keep their arcade look, Super Over's, whatever the rest of the app wears.
- Video screens are always dark. Review, Trim, the batter box, the recorder and the notes player keep the night look under every choice, as photo and video editors do: footage reads best on dark. The status bar's icons turn light while one of them is showing.
- Home can rain when it's raining in your city. It's off until you turn it on. Then one small request goes out as Home starts, for the city kept on the phone, never your location.
For the reading pages, Auto decides in a fixed order: your own choice, then a "Keep" you pressed this session, then the room if it's clearly bright or dim, then the phone's dark mode, and last the sun. Two details made that order work. A light system setting tells you nothing, because it's every phone's default, so only a dark setting counts as a choice; with the phone left on light, the sun decides. And a bright room beats the phone's dark mode, because dark pages are hard to read in the sun. When the room overrides the phone, a notice says so.
Building four looks in Compose taught me three things:
- Ask the theme for a role, never a colour. A screen asks for the chrome, the live counter, Stop or Selected, and each look answers. A colour typed into a screen is a bug waiting for the next look.
- An uncoloured
TexttakesLocalContentColor, and Compose's default is black. A transparentScaffoldorSurfacepasses down whatever sits above it. In 1.3, the profile quiz's questions were black on every phone in a night look. Now one function applies a look and sets the ink with it, and a unit test fails any other way in. - Change the look only where nothing is in progress. Surprise me and Time of day switch only as Home opens, never under another screen, so nothing shifts while you work.
Haptics: make the phone feel the ball
Face the Pace is a reaction drill against a ball bowled at 120 to 150 km/h. When you middle it, the phone answers with a crisp click and a low thud just after it: the bat's "thock". Android's composition primitives (clicks, thuds, ticks, rises) feel far better than a raw buzz, but they arrived over two releases, not every phone has them, and some tablets have no vibration motor at all. So ask the phone, don't assume:
val effect = when {
// The phone has these primitives (the thud needs Android 12): the best feel.
vibrator.areAllPrimitivesSupported(PRIMITIVE_CLICK, PRIMITIVE_THUD) ->
VibrationEffect.startComposition()
.addPrimitive(PRIMITIVE_CLICK)
.addPrimitive(PRIMITIVE_THUD, 0.8f, 30)
.compose()
// A motor with amplitude control: shape it with a waveform.
vibrator.hasAmplitudeControl() -> VibrationEffect.createWaveform(timings, amplitudes, -1)
// Anything else: one short pulse.
else -> VibrationEffect.createOneShot(30, VibrationEffect.DEFAULT_AMPLITUDE)
}
Two more rules came out of it. Check hasVibrator(), and where it's false, let a sound stand in
and say so. Our own test tablet has no motor, so there the drill says so and plays sounds instead. And never
punish: a missed ball gets no buzz at all.
Heat, battery and a screen that must stay on
The recorder films a whole net session from behind the bowler's stumps, often in the sun. Three things fight you:
- The screen. If it turns off, the activity stops, and the recording with it. So it stays on, and when nobody is touching the phone the recorder falls to a dark screen. Black pixels on an OLED panel cost next to nothing, while auto-brightness in the sun drives a lit screen to full.
- Heat.
PowerManager's thermal status (Android 10 and later) says when the phone is warming up. FromSEVERE, the system may throttle or close the camera, which ends the recording. The recorder reads it, and atMODERATEsays "The phone is getting warm. Shade it if you can." - The battery. The sticky
ACTION_BATTERY_CHANGEDbroadcast gives the level and whether the phone is plugged in, with no permission.
Starting quickly matters as much as lasting. Instant record starts a recording from a launcher shortcut, a Quick Settings tile or a home-screen widget: swipe down from any app, tap, and it's filming. On a locked phone, Android asks for the unlock first.
Video: decoding, seeking and cutting on the phone
A net session can be 2 to 5 GB of video, and everything CricCuts does with it happens on the phone: reading frames for analysis, previews you can scrub, cutting out the shots and exporting the reel with Media3. Video is where most of the speed was won, and where the strangest bugs lived.
- Decode in order; don't seek for every frame.
MediaMetadataRetriever.getFrameAtTimeis easy, but each call seeks back to a keyframe and decodes forward again: about a third of a second a frame on our footage. To read many frames from a stretch of video, aMediaExtractorfeeding oneMediaCodecdecoder reads the whole stretch in a single pass. The retriever stays as the fallback. - Open a
content://video through a file descriptor.MediaExtractor.setDataSource(context, uri)on a URI from the system picker can quietly find no video track, and then every frame drops to the slow path, with no error. Log which path ran, because the speed alone won't tell you. - Frames come out the way they're stored. A phone held upright records the picture sideways, with a rotation tag beside it. The decoder ignores the tag, so turn each frame by the track's rotation before you look inside it, or a box drawn on the upright picture reads the wrong part of the frame.
// Through a file descriptor: setDataSource(context, uri) can miss the video track.
val extractor = MediaExtractor()
context.contentResolver.openAssetFileDescriptor(uri, "r")!!.use { afd ->
extractor.setDataSource(afd.fileDescriptor, afd.startOffset, afd.length)
}
val track = (0 until extractor.trackCount).first {
extractor.getTrackFormat(it).getString(MediaFormat.KEY_MIME)!!.startsWith("video/")
}
extractor.selectTrack(track)
extractor.seekTo(windowStartUs, MediaExtractor.SEEK_TO_PREVIOUS_SYNC)
// Then feed samples to one MediaCodec decoder and keep each frame up to windowEndUs.
Seeking and cutting run into the same fact: phone and WhatsApp videos often carry a keyframe only every 5 to 8 seconds, and a frame between keyframes can't be shown on its own.
- Seek exactly inside a clipped item. Media3's
SeekParameters.CLOSEST_SYNCis fast, but on aMediaItemclipped to one shot, its tolerance is clamped to the clip. With no keyframe inside the shot, every seek lands on the shot's first frame, and a loop that seeks back keeps landing there. UseSeekParameters.EXACTon clipped items, and keep the quick sync seek for dragging through a whole video, ending the drag on an exact one. - Cut on clean frames. Media3 ends a clipped item at the first sample past its end in decode order. On footage with B-frames, a piece that ends inside a group of frames loses one to three frames, and our replays froze for a moment at every scene change. No Media3 setting fixes it, so the export reads the clean cut points from the file and moves each edge onto one.
The biggest saving wasn't time but space. After a session, Keep the shots replaces the recording with
a copy of only the shots, at full quality. It's a stream copy, a MediaExtractor into a
MediaMuxer, so nothing is decoded or re-encoded. Four things to know if you do the same:
- Keep the original timestamps. Every pick, trim and note points at a time in the original. Copy each frame at its own time, and nothing that refers to the video has to change.
- Keep the first group of frames. Both
MediaMuxerand Media3's muxer move a file's first sample to zero. Start the copy at the first shot and every time shifts by that much, silently. The copy keeps the video's opening frames, and a check reads every frame time back. - A copy with gaps misleads the encoder. Media3 sized the encoder from the frame rate it read, and the copy read as about 9 frames a second, so a reel cut from it got a quarter of the bitrate: softer video, and no error. Set the encoder's frame rate yourself.
- Never delete the user's video yourself. CricCuts offers the original to
MediaStore.createTrashRequest, so Android asks first and the video goes to the phone's trash, not straight to nothing.
And three smaller ones from the player. Let a tap anywhere on the picture play or pause:
PlayerView can swallow the touch, so draw a transparent layer over it, under the buttons, hidden
from TalkBack. Cancel the pending seek when a drag ends: a slider that debounces its seeks must drop the
last one on release, or it lands 40 ms after Play. Keep files an export reads in filesDir, not
cacheDir: Android clears the cache when the phone is nearly full, even mid-render, and an end
card's image once vanished five seconds before Media3 read it.
Edge models: small, optional and on the phone
CricCuts runs three open-source machine-learning models on the phone: a body model (Google's MediaPipe Pose Landmarker), a words model (Vosk, for offline speech recognition) and a voice-activity model (Silero VAD). Nothing is uploaded: the video, the audio and the results stay on the phone. The interactive course How CricCuts works explains each model. Here's what shipping them on Android taught me:
- Native libraries are where Android's variety bites. MediaPipe's native library needs a C function,
aligned_alloc, that Android 8 doesn't have. So version 1.3 closed on Android 8 phones at the screen where you pick the batter. Version 1.4 checks first and carries on without the body model there. An optional feature should step aside, not crash. - 16 KB memory pages. Google Play requires them for apps that target Android 15. Kotlin code is
unaffected, but every bundled
.sohas to be built for it, and two of our vendor libraries had to move to newer versions. Audit every native library in the APK, not just your own. - Heavy models should be optional. The body model costs seconds per shot, so it's opt-in, and the app is useful without it. The optional speech model downloads once, when it's first needed, instead of making every install bigger.
- Long work belongs in a foreground service of the right type. Analysis and exports run in one, so they keep going when you switch apps. Google Play asks you to declare each foreground-service type, and to show a video of it in use.
For the bigger picture, see why the future of AI is small models on the edge and many small models working together.
Speech in: voice that never leaves the phone
Every voice feature in CricCuts runs on the phone:
- Voice search. Say what you want, such as a coaching tip, a Law, a lesson or one of your sessions, and the app's search opens with it (Android 12 and later, Indian English).
- Voice review. After each clip in Check your picks, say "yes" or "no" (or "Keep" or "Remove") instead of tapping.
- The recorder's commands. "CricCuts, pause" and "CricCuts, resume", so a player at the crease doesn't have to walk back to the phone.
Android has two speech recognisers, and the difference matters. The ordinary SpeechRecognizer
may send audio to a server. From Android 12, createOnDeviceSpeechRecognizer runs on the phone. Voice
search and voice review use only the on-device one:
if (!SpeechRecognizer.isOnDeviceRecognitionAvailable(context)) {
showTypedSearchOnly() // no quiet fallback to a recogniser that may upload audio
return
}
// Every SpeechRecognizer call must be made on the main thread.
val recognizer = SpeechRecognizer.createOnDeviceSpeechRecognizer(context)
The lesson: "on-device" is a promise to users, not a preference. Where on-device recognition isn't available
(every phone below Android 12, and some above it), CricCuts has no voice, only typed search. A quiet fallback to
createSpeechRecognizer would break the promise without anyone noticing. Voice search never records,
stores or uploads what you say.
Speech out: a phone that reads to you
Text-to-speech is older and on almost every phone, but it has its own traps. CricCuts uses the phone's own voice for three things:
- Read aloud in the Academy. A listening player that keeps your place, carries on with the screen off, answers the lock screen and headphone buttons, and pauses after a question so you can think.
- The drill's bowler. Blind cricket, Face the Pace played by ear, is built on it: the bowler asks "Ready?", and the batter plays the shot on the sound.
- Coach Notes. A coach's notes on a shot can be read out.
Voices differ by phone and by language. Ask before you read: LANG_MISSING_DATA means the engine
knows the language but the phone hasn't downloaded it. CricCuts says so before reading anything, and offers Get
voice, which opens the engine's one-time download. Check every installed engine, not only the default one, since
another may already have the voice:
when (tts.isLanguageAvailable(locale)) {
TextToSpeech.LANG_MISSING_DATA -> // known, not downloaded
offerGetVoice(Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA).setPackage(enginePackage))
TextToSpeech.LANG_NOT_SUPPORTED -> tryTheNextEngine()
else -> read()
}
Two smaller lessons. UtteranceProgressListener.onRangeStart tells you which words are being
spoken, which is how you highlight the line being read. And a reader that keeps going with the screen off needs a
foreground service and a MediaSession, so the lock screen and headphones can pause it. The lessons
in Hindi, Marathi, Tamil, Kannada and Telugu sit beside the English, and Read aloud reads both. Those
translations are drafts, and corrections are welcome.
Art drawn in Kotlin
No illustration files sit behind CricCuts' backdrop scenes. Every scene is a painting drawn by code, on your phone, that moves through your clip, and in many of them the moment you hit the ball sets something off. More than 30 ship in version 1.4.
Most of it is drawn with Android's plain Canvas API, frame by frame, and Media3 lays each frame
over the video as an overlay when the reel is exported. The few effects that bend the video itself, like a colour
split, are OpenGL shaders. Home's four looks (Floodlights, Daylight, Scoreboard and Super Over) and the Science
Lab's simulators of spin, swing and power hitting are drawn with Compose's Canvas too. What it taught me:
- Keep the main thread for the main thread. Painting one scene's frames on it once froze an export for
two minutes, an ANR. Now an export prepares on a background dispatcher and touches the main thread once, to drive
Media3's
Transformer. - Two renderers, one picture. The preview and the export draw the same scene in different places, and they have to agree. AGSL, Android's runtime shaders, could share one shader between them, but it needs Android 13 and CricCuts runs from Android 8. So the copies are kept in step by hand, and every mirrored formula is written down in one list. Changing one copy and not the other is the bug to watch for.
- Measure geometry with
positionInRoot()andsize, notboundsInRoot(). The latter clips to every ancestor and returnsRect.Zerofor a zero-width node, and Home's fireworks drew nothing. - Never put white text on a colour chosen at runtime. Pick the ink from the fill with a small helper.
A hard-coded white beside a
whenthat returned four fills once shipped broken in three files at once.
Interactive courses, built in Compose
The Academy is the other half of the app. It has courses on the science of spin, swing and power hitting, on training, food, the body and the mind, on the Laws and umpiring, and on history. A Code Lab teaches algorithms (steps, loops, conditions, searching, sorting, bugs) by thinking like a scorer, without a computer. None of it is a web view. Every lesson is native Compose, so it can use the phone: simulators you drag and play with, the Pocket Lab's sensor experiments, the LBW game, a quick check at the end of each lesson, and practice mock tests in the style of JEE Main at College level (practice only, never official).
- Key translations by their source text. A lesson's English is the key to its translations, so editing the English marks every translation of it out of date, and a test lists them. A changed sentence can never keep an old translation without anyone knowing.
- Test the content like code. A unit test works out every numerical answer in the mock tests again, so a wrong answer key fails the build instead of failing a student. In the Data Lab, every number in a lesson is computed from its data set in Kotlin, never typed in.
- Mind the back-gesture strip. A drag that starts in the screen's side gesture strip is a system Back,
and
safeDrawinginsets don't include it. Pad edge-to-edge sliders in from the system-gesture insets, or the first drag on a simulator goes back a screen.
Letting agents in: a link for every page, and 15 shortcuts
Assistants and AI agents mostly can't tap through your app yet, but they can open a link. So every page of
CricCuts has one: criccuts.com/go/ plus one word, like /go/laws, /go/pace
or /go/dls. They're verified Android App Links, so on a phone with CricCuts the link opens that page
of the app. Anywhere else, it opens a web page with an "Open in CricCuts" button. Search works the same way:
/go/search?q=yorkers.
- One word per page, so an agent can guess it. Case, hyphens and a plural "s" don't matter, and a word that names no page opens search with that word typed in.
- The list is published for agents in the site's
llms.txt, a plain-text summary that AI tools read. - 15 static shortcuts, the most Android allowed for one activity on our test tablet: Instant record, Search, Face the Pace, the training plan, the DLS calculator, the Academy, the Laws, the coaching videos and more. Long-pressing the icon shows the first four or so, while launcher search and assistants see all 15. The same file declares App Actions capabilities, so "open Face the Pace in CricCuts" or "search CricCuts for yorkers" can resolve to the same links.
<capability android:name="actions.intent.OPEN_APP_FEATURE">
<intent android:action="android.intent.action.VIEW"
android:targetPackage="com.criccuts"
android:targetClass="com.criccuts.MainActivity">
<url-template android:value="https://criccuts.com/go/{feature}" />
<parameter android:name="feature" android:key="feature" />
</intent>
</capability>
What I'd tell anyone doing the same:
- A link opens a page. It never does anything. No link starts an import, an export or a recording. Every argument is checked against a short allow-list, and search text is cut to 80 characters. An exported activity is an API that anything on the phone can call, so treat it like one.
- Starting something needs a trusted path. Instant record's shortcut, tile and widget go to an unexported activity, which starts the recording inside the app's own process. No intent from outside can.
- Static shortcuts start with a cleared task. That destroys whatever the app was doing, an export in progress included. So the shortcuts land on a small activity that hands the link to the app that's already running.
- Accessibility pays twice. Blind cricket's link goes straight to the bowler's "Ready?", so a blind player who asks an assistant for it hears the game start, not a screen to swipe through.
- Be honest about where assistants are. When I tried it in October, Gemini answered "open my training plan in CricCuts" with "can't control the app", and the links it opens land in its own browser tab, one tap from the app. Links are the route that works today.
Next: App Functions
Android's own answer for agents is AppFunctions. An app declares typed functions with the Jetpack
androidx.appfunctions library, the library generates a schema that Android indexes, and an assistant
holding the EXECUTE_APP_FUNCTIONS permission can find and call them. It needs Android 16 or later.
As of Google's documentation in May 2026, Gemini's support is a private preview with trusted testers.
The plan for CricCuts is small and deliberate:
- A few typed functions, such as
openSection(page)andstartDrill(speed), so an agent can ask for "Face the Pace at 140" in one call instead of guessing a link. - Every function goes through the same resolver as the links, so an agent can reach only what a link can.
- Starting a recording is a separate question. If an assistant is ever allowed to switch the camera on, it'll be with an on-screen countdown and a Cancel button, and that decision hasn't been made.
// A sketch, not shipped: the library is in alpha and its API may change.
class CricCutsFunctions {
/** Opens one page of CricCuts, such as "laws" or "pace". */
@AppFunction
suspend fun openSection(appFunctionContext: AppFunctionContext, page: String): Boolean =
AppLinks.resolve(page)?.let { open(it); true } ?: false
}
Twelve lessons I'd pass on
- Read sensors only while a screen needs them, and smooth them with hysteresis before you act.
- Never change what someone is reading without asking.
- Ask the theme for a role, never a colour, and remember that Compose's default text colour is black.
- To read many frames, decode in order with
MediaCodec; don't seek for each one. And know where the keyframes are, because seeks and cuts land on them unless you say otherwise. - Ask the phone, don't assume from the version: the vibrator for its primitives, the recogniser for on-device mode, the speech engine for the language.
- "On-device" is a promise. Remove a feature rather than fall back to a server.
- Test on the oldest and oddest phones you support. Android 8 and a tablet with no vibration motor found more bugs than any flagship did.
- Native libraries carry the risk: 16 KB pages and missing C functions. Audit every
.so. - A big composable can fail at class load with a
VerifyErrorwhose message is misleading. Compose keeps every parameter of a restartable composable alive to the end of the function, and too many run the verifier out of registers. Group the parameters into small holder classes. - Create app-wide Compose state on the main thread, before
setContent. When an analytics call off the main thread was the first to touch the chosen look, its state was created after the first composition's snapshot, and about one cold start in four crashed. - Guard every range you build from media metadata. A shot that ran past a video's real end made an empty
range, and
coerceIn()threw. - Give every page a link. It's the cheapest way into assistants today, and the foundation App Functions will build on.
Questions
Do Android apps need a permission to read the light sensor or the accelerometer?
No. The light sensor, the accelerometer, the gravity sensor and the gyroscope need no runtime permission. The camera, the microphone and location do. From Android 12, an app that wants motion sensors faster than 200 readings a second must also declare the HIGH_SAMPLING_RATE_SENSORS permission. Either way, read a sensor only while the screen that uses it is showing.
What's the fastest way to read many frames from a video on Android?
Decode them in order. MediaMetadataRetriever.getFrameAtTime seeks back to a keyframe and decodes forward again for every frame you ask for, which took about a third of a second a frame on our footage. A MediaExtractor feeding one MediaCodec decoder reads a whole stretch of video in a single pass. Open a content:// video through an AssetFileDescriptor, and turn each frame by the track's rotation before you use it.
Can Android speech recognition work offline, on the phone?
Yes, from Android 12. SpeechRecognizer.createOnDeviceSpeechRecognizer runs on the phone, and isOnDeviceRecognitionAvailable says whether this phone can, which also depends on the language being downloaded. The ordinary recogniser may send audio to a server, so an app that promises nothing leaves the phone should turn voice off where on-device recognition is missing, rather than fall back.
How can an AI assistant open a page inside my Android app?
Today, with verified Android App Links: give each page its own https link, and an assistant or agent that opens the link lands on that page. Static shortcuts with App Actions capabilities list the most important pages for launchers and assistants. Next comes AppFunctions, on Android 16 and later, where an assistant calls typed functions your app declares. Gemini support for it is still a preview for selected testers.
See it on your own phone
CricCuts is free on Google Play, for Android phones. Tilt Home, try the Pocket Lab, ask it for the Laws.