Skip to main content

Posts

Programmatically Requesting 'Autostart' Permissions in MIUI

  You have likely encountered this scenario: Your Android application relies on   WorkManager   for critical background synchronization or   AlarmManager   for time-sensitive notifications. You test it on a Google Pixel or an emulator, and it functions perfectly. Then, your crash analytics or support tickets start filling up with reports from users with Xiaomi (Redmi/Poco) devices. The app isn't crashing, but background tasks simply vanish when the app is swiped away from the "Recents" menu. The culprit is not your code; it is MIUI’s aggressive battery optimization logic, specifically the proprietary  "Autostart"  permission. By default, Xiaomi restricts apps from restarting in the background unless the user explicitly grants this permission. Since there is no standard Android API to grant this automatically, we must engineer a programmatic solution to navigate the user to the correct settings page. The Root Cause: AOSP vs. MIUI To solve this, we must ...

Flutter on Xiaomi: Solving the Keyboard Overlay & Bottom Inset Bug

  There is a distinct sinking feeling known only to mobile developers: your Flutter app works perfectly on the emulator, runs smoothly on a Pixel, and performs flawlessly on a Samsung Galaxy. Then, a user reports a bug from a Xiaomi Redmi Note or a Poco device. "When I tap the password field, the keyboard covers it. I can't see what I'm typing." On many Xiaomi devices running MIUI or the newer HyperOS, standard Flutter layout behaviors fail. The viewport doesn't resize, the  Scaffold  ignores the keyboard, and your input fields remain buried. This is not a simple layout error; it is a conflict between Flutter’s rendering engine and Xiaomi’s non-standard implementation of Android’s Window Insets. This guide provides the technical root cause and a production-grade solution to fix keyboard occlusion on Xiaomi devices. The Root Cause: Why MIUI Breaks Flutter Layouts To fix the problem, we must understand the disconnect between the Operating System and the Flutter Fram...