跪拜 Guibai
← All articles
Android

Android 8.1 Support: One Yellow Warning and Two Silent Bugs

By booboosui ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

The real cost of supporting old Android devices is not the manifest number but the missing APIs and the fallback semantics you choose. A false default in a catch-all can quietly break features for years, and the amber warning pattern is a clear way to communicate capability loss without a false red alert.

Summary

Dropping an Android app's minimum SDK from 30 to 27 is not a one-line manifest change. Andee, an agent that lives inside an Android phone using accessibility services to read and tap the screen, now runs on Android 8.1, but the downgrade forces a different answer for screen capture. takeScreenshot only exists on API 30, so on older versions the function returns null, deliberately sharing the same failure value as a denied capture. The model can't tell "system too old" from "permission revoked", but the UI layer avoids a separate code path at the cost of that ambiguity.

The self-check now opens with an amber warning that lists which features are missing (screen capture, image tap, window frosted glass) and which still work (chat, voice, notes, settings), with no fix button. To clean up the scattered API-30-only calls, twelve UI files were refactored to ask a central WindowMetricsCompat object, but the geometry rewrite introduced a bug: several metrics already exclude the status bar, and subtracting it again made the floating ball and centered cards sit one status bar too low. The other silent bug came from the exact-alarm permission check, which used runCatching with a default of false. Since canScheduleExactAlarms() is API 31, Android 11 invocations threw, and the fallback made all reminders silently allowed to be late. The fix short-circuits to true for SDK_INT below S, because that permission never existed. Neither bug crashes, so they hide in geometry and timing deviations, reproducible only on the scarcest API 27–29 devices.

Takeaways
— Lowering minSdk from 30 to 27 requires replacing API-30-only takeScreenshot with a null return on older versions; the same null covers both too-old and permission-denied failures.
— The app's self-check places an amber warning first, explaining that screen capture, image tap, and window frosted glass are unavailable, while chat, voice, notes, and settings remain functional.
— Version-gated fixes were applied to 37 API errors, including input method enter key, gesture exclusion area, notch, background blur, the three-parameter startForeground overload, ACTIVITY_RECOGNITION, and ImageDecoder falling back to BitmapFactory.
— A geometry bug came from subtracting status bar height twice: getMetrics() already excludes it, so bottomEdge() and usableSize() are one status bar off on API < 30, shifting the floating ball and centered cards.
— The original exact-alarm check used runCatching with getOrDefault(false), but because canScheduleExactAlarms() only exists on API 31, Android 11 calls threw and all reminders were silently deferred; the fix returns true for SDK_INT < S.
— Both old-system bugs do not crash, so they never appear in crash statistics, only in UI positions and reminder timing deviations, and they can only be reproduced on API 27–29 real devices.
Conclusions

Using a single null return for both 'system too old' and 'permission denied' simplifies the UI but erases a meaningful distinction for the model's debugging; the author accepts that trade-off to keep the failure path uniform.

The double subtraction of the status bar shows how a straightforward geometric formula turns into a silent bug when the coordinate spaces of two metrics APIs differ; the code was exercised only on modern devices until the minSdk drop exposed it.

The runCatching plus false default pattern is a trap: an exception from a missing API becomes a permanent wrong answer, and the only safeguard is an explicit version check that acknowledges the permission's existence across Android versions.

An amber warning that clearly separates degraded features from working ones is a more honest user-facing pattern than a red crash, because it sets expectations without blocking the parts that still function.

Concepts & terms
WindowMetricsCompat
A compatibility wrapper that centralizes screen size queries, using currentWindowMetrics and maximumWindowMetrics on API 30+ and falling back to getRealMetrics plus system-bar resource heights on older versions, so twelve UI files share one source of truth.
canScheduleExactAlarms
An API added in Android 12 (API 31) to check whether an app can schedule exact alarms. On older versions the permission does not exist, so code must short-circuit to true instead of calling a method that throws.
AccessibilityService.takeScreenshot
An API available since Android 11 (API 30) that lets an accessibility service capture the screen; on older versions it cannot be called, so the return value is deliberately set to null.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗