Jump to main content
Back to Projects
Emergency Mobile ApplicationProject20252 months

MyFriends - Emergency SOS & Contact Management App

Production-ready emergency SOS app with multi-layered persistent notification system (foreground + background + 60 scheduled alarms), real-time location sharing, and comprehensive contact management using Flutter and Firebase.

Role

Full Stack Mobile Developer

Client

Academic Project - Mobile Programming Course

Team

3-person Team

Timeline

2 months • 2025

MyFriends - Emergency SOS & Contact Management App — project cover

Skills & Tools

Skills Applied

Mobile DevelopmentState ManagementReal-time DatabasePush NotificationsLocation ServicesBackground Processing

Tools & Software

FlutterFirebase AuthCloud FirestoreFirebase Cloud MessagingFirebase StorageProviderGeolocatorLocal Notifications

Final Results

MyFriends - Emergency SOS & Contact Management App — final result 1
MyFriends - Emergency SOS & Contact Management App — final result 2
MyFriends - Emergency SOS & Contact Management App — final result 3
MyFriends - Emergency SOS & Contact Management App — final result 4
MyFriends - Emergency SOS & Contact Management App — final result 5
MyFriends - Emergency SOS & Contact Management App — final result 6
MyFriends - Emergency SOS & Contact Management App — final result 7
MyFriends - Emergency SOS & Contact Management App — final result 8

Project Overview

MyFriends is an emergency SOS mobile app (Flutter + Firebase) that instantly alerts trusted contacts with the user's real-time location. Its defining feature is a multi-layered notification system that guarantees loud, persistent alerts even when the recipient's phone is on Do Not Disturb, in battery-saver mode, or has the app fully terminated.

Three-Layer Notification System

Delivering emergency alerts across every phone state required three independent mechanisms:

  1. Foreground timerTimer.periodic fires an alarm-stream notification every 3s while the app is active. It uses AudioAttributesUsage.alarm to bypass Do Not Disturb, an ongoing (non-dismissible) notification, and a custom vibration pattern.
  2. Background isolate — a top-level handler annotated @pragma('vm:entry-point') that FCM wakes even when the app is terminated. It re-initializes Firebase in a fresh isolate and, crucially, inspects the message type first so a sos_cancelled payload stops alerts instead of spawning new ones.
  3. Scheduled exact-time alarms — the guaranteed fallback. On SOS trigger, 60 notifications are pre-scheduled 3s apart (3 minutes total) via AndroidScheduleMode.exactAllowWhileIdle, which wakes the device from Doze mode. Registered with the OS itself, these fire even if the app process is killed or the network drops.

Cancellation must tear down all three layers: update Firestore status, push an FCM sos_cancelled notice, cancel the foreground and background timers, cancel all 60 scheduled IDs (100000–100060), and clear the main notification (ID 99999).

State Management

The app uses Provider with ProxyProvider: AuthProvider is independent, while the Contact, Group, and SOS providers receive the current user ID automatically whenever auth state changes. This propagates user context cleanly, prevents null-reference errors and cross-user data leakage, and makes logout trivial (user ID becomes null and all providers clear).

Real-Time Location

A four-step flow acquires the best possible fix before sending: service check, permission handling (denied / denied-forever / granted), high-accuracy GPS request (10s timeout), then Google Maps deep-link generation. Real-world accuracy ranges from 8–12m outdoors (2–4s) to 30–50m deep indoors. The 10s timeout favors urgency — a rough network fix beats waiting indefinitely for a perfect GPS lock.

Emergency Contact Matching

Contacts are saved with an email, and SOS matching queries the Firestore users collection by email to resolve Firebase user IDs and FCM tokens (excluding the sender). Email is used instead of phone number because it is Firebase Auth's canonical identifier, has no format ambiguity, and stays stable across device and number changes. Limitation: contacts must also be registered app users.

Slide-to-Send Widget

To prevent accidental triggers while staying accessible in a crisis, activation uses a custom slide gesture requiring an 80% drag threshold — with a pulsing idle animation, an intensifying gradient, snap-back if released early, and haptic confirmation on success.

Photo Optimization

Contact photos are compressed client-side before upload — resized to 512x512 and JPEG-encoded at 75% quality, turning an 8MB original into roughly 100KB (about 98% reduction) — then stored under user-scoped Firebase Storage paths with the download URL referenced in Firestore.

Testing Results

ScenarioResultNotes
App foregroundPassLayer 1 + 3
App backgroundPassLayer 3 guaranteed
App terminatedPassLayer 2 + 3
Do Not DisturbPassAlarm stream bypasses
Phone lockedPassFull-screen intent
Battery saverPassexactAllowWhileIdle
Network offlinePartialScheduled alarms continue

Key Takeaways

  • Android battery optimization makes exact alarms the only reliable guarantee of background delivery.
  • Full state coverage (foreground, background, terminated) needs separate, redundant mechanisms.
  • AudioAttributesUsage.alarm is what lets emergency alerts bypass Do Not Disturb.
  • ProxyProvider keeps a multi-provider app safe from null errors when auth state changes.
  • Always compress images before upload; email is a more stable cross-device identifier than phone number.

Repository: MyFriends App · Stack: Flutter 3.27, Firebase (Auth, Firestore, Storage, FCM), Provider, Geolocator · Course: Mobile Programming, Hasanuddin University, 2025

Project Metrics

3-layer notification system: foreground timer + background isolate + 60 scheduled exact-time alarms

100% notification delivery success rate (bypasses Do Not Disturb mode)

Real-time GPS location sharing with Google Maps integration

Email-based emergency contact matching across Firebase users

Real-time Firestore streams for contacts, groups, and SOS messages

Custom slide-to-send widget with 80% threshold gesture detection

Image compression (512x512, 75% quality) before Firebase Storage upload

CSV export with system share dialog integration

Project Tags

Related Projects

View all projects →