16/08/2026
Building a Reliable Dual-SIM Android SMS Gateway & Background Service for MFS Automation!
Over the past few days, I've been working on developing a robust Android-based Gateway app (Zelova Pay) that handles incoming MFS (bKash, Nagad, Rocket) notifications, tracks SIM slots accurately, and syncs data to a Laravel backend seamlessly.
Here are some of the key technical challenges we solved during this journey:
🔹 Accurate SIM Slot Detection: In real Android devices, standard broadcast intents often return a default slot index (0). By leveraging SubscriptionManager with subscription IDs and multi-layered fallback logic, we successfully mapped incoming SMS to the correct SIM slot (SIM 1 or SIM 2).
🔹 Beating Android's Doze Mode & Deep Sleep: Background services often get killed by aggressive system battery optimizations. We implemented AlarmManager (setExactAndAllowWhileIdle) combined with Partial WakeLock and Foreground Services to keep the gateway running 24/7 without interruption.
🔹 Robust Offline & Online Sync: Implemented a Room Database fallback mechanism to locally store SMS when internet connectivity drops and auto-sync them once back online.
🔹 Laravel Backend Automation: Configured automated cleanup tasks using Laravel's task scheduler to purge inactive devices after 2 hours of inactivity to keep the database clean and secure.
Building reliable background automation on Android requires deep understanding of system restrictions, but with the right architectural approach, it's completely achievable!