Courses / Mobile Application Development (CDE-315) – BS CS 5th Semester
Week 16 Theory – Challenges with Mobility and Wireless Communication; Location-Aware Applications
Week 16 – Mobility, Wireless Communication and Location-Aware Applications · 85 min read · 29 MCQs to check yourself
Location-aware Android apps – understanding geolocation APIs
GPS and the Fused Location Provider (Professor Sluiter)
1. Challenges with mobility
Mobility means users and their devices move – between rooms, cities, networks and countries – while using apps. Mobile computing faces three groups of challenges:
(a) Device (resource) constraints
| Challenge | Effect on apps |
|---|---|
| Limited battery | Radios (4G/5G, GPS, Wi-Fi) and screen consume most energy; apps must minimise wake-ups and network use |
| Limited CPU, RAM, storage | OS kills background apps; large apps uninstalled first |
| Small screens, touch input | Simple UIs, large tap targets |
| Heterogeneity / fragmentation | Many OS versions, screen sizes and hardware capabilities |
| Heat | Heavy processing triggers thermal throttling |
(b) Network (wireless) challenges
| Challenge | Explanation |
|---|---|
| Low and variable bandwidth | Speed changes from 5G to 2G or weak Wi-Fi |
| High latency | Delay of each round trip (satellite and congested networks) |
| Disconnections | Tunnels, lifts, rural areas, load-shedding affecting towers – the app must work offline |
| Handoff / handover | Moving between cells or from Wi-Fi to mobile data changes IP address; connections may drop |
| Higher error rates | Interference, fading, multipath; packet loss |
| Cost | Mobile data is metered; users avoid large downloads |
| Asymmetry | Download faster than upload |
(c) Mobility management and security challenges
- Location management – the network must track which cell the user is in to deliver calls/data (location update and paging).
- Changing context – the right content depends on where the user is (location-aware apps).
- Security and privacy – wireless signals can be eavesdropped; devices are easily lost or stolen; public Wi-Fi may be malicious ("evil twin"); location data is sensitive.
- Data consistency – data edited offline on several devices must be synchronised and conflicts resolved.
2. Wireless communication technologies
Cellular generations
| Generation | Approx. years | Key technology | Typical use |
|---|---|---|---|
| 1G | 1980s | Analog voice (AMPS) | Voice only |
| 2G | 1990s | Digital GSM, CDMA; SMS; GPRS/EDGE data (~100–200 kbps) | Voice, SMS, basic data |
| 3G | 2000s | UMTS/WCDMA, HSPA (Mbps) | Mobile internet, video calls |
| 4G | 2010s | LTE, LTE-Advanced (tens–hundreds of Mbps), all-IP, VoLTE | Streaming, apps |
| 5G | 2019+ | 5G NR: eMBB (very high speed, Gbps), URLLC (ultra-low latency ~1 ms), mMTC (massive IoT), mmWave and mid-band | AR/VR, IoT, autonomous systems |
| 6G | Research (expected ~2030) | AI-native, terahertz bands | — |
| In Pakistan, the mobile operators (Jazz, Zong, Ufone and others) provide 4G in most of the country; 5G spectrum and rollout are managed by the PTA – check pta.gov.pk for the current status. |
Short-range and local technologies
| Technology | Range | Use |
|---|---|---|
| Wi-Fi (IEEE 802.11 – Wi-Fi 5/6/6E/7) | ~30–100 m | Internet in homes, campuses; Wi-Fi Direct for device-to-device |
| Bluetooth Classic | ~10 m | Audio headsets, file transfer |
| Bluetooth Low Energy (BLE) | ~10–50 m | Wearables, beacons, health sensors – very low power |
| NFC (Near Field Communication) | ~4 cm | Contactless payments (Google Wallet), tags, pairing |
| UWB (Ultra-Wideband) | ~10 m, cm-level accuracy | Precise indoor finding, digital car keys |
| Infrared | Line of sight | TV remotes (old phones) |
| Satellite | Global | GPS positioning; emergency satellite messaging on new phones |
Android APIs
ConnectivityManager / NetworkCapabilities (connection type, metered, validated internet), WifiManager, BluetoothAdapter/BluetoothLeScanner, NfcAdapter, TelephonyManager (network operator, signal).
3. Designing for unreliable networks
| Strategy | How |
|---|---|
| Offline-first | Store data locally (Room/DataStore); show cached data immediately, then refresh from the network |
| Synchronisation | Queue changes made offline and upload with WorkManager when a connection returns; resolve conflicts (timestamp/version) |
| Caching | HTTP caching (OkHttp cache, ETags), image caching (Glide/Coil) |
| Retry with exponential backoff | Retry failed requests after 1 s, 2 s, 4 s… to avoid flooding |
| Timeouts | Sensible connect/read timeouts and clear error messages with Retry |
| Minimise data | Compress (gzip), paginate, request only needed fields, use WebP images, avoid autoplay video on mobile data |
| Detect network type | Defer big downloads until on unmetered Wi-Fi (NetworkCapabilities.NET_CAPABILITY_NOT_METERED, WorkManager constraints) |
| Batching | Group network requests to keep the radio idle longer (saves battery – week 17) |
| Push instead of polling | Use Firebase Cloud Messaging to notify of new data instead of checking every minute |
| Graceful degradation | Allow reading, drafting and queuing actions even when offline |
| Security | HTTPS everywhere; never trust public Wi-Fi |
ConnectivityManager cm = getSystemService(ConnectivityManager.class);
NetworkCapabilities caps = cm.getNetworkCapabilities(cm.getActiveNetwork());
boolean online = caps != null && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
boolean unmetered = caps != null && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
(Requires the normal permission ACCESS_NETWORK_STATE.)
4. Positioning technologies
| Technology | How it works | Accuracy | Power | Indoors? |
|---|---|---|---|---|
| GNSS / GPS | Receiver measures signals from at least 4 satellites (trilateration) – GPS (USA), GLONASS (Russia), Galileo (EU), BeiDou (China) | ~3–10 m (better with dual-frequency) | High | Poor |
| A-GPS (Assisted GPS) | Network sends satellite data to speed up the first fix (TTFF) | GPS-level, faster | High | Poor |
| Wi-Fi positioning | Matches visible Wi-Fi access points to a database | ~15–40 m | Low | Yes |
| Cell-ID / cell tower triangulation | Uses nearby cell towers | ~100 m – several km | Very low | Yes |
| Bluetooth beacons (BLE) | Proximity to known beacons | ~1–5 m | Low | Yes (malls, museums) |
| UWB | Time-of-flight between devices | ~10–30 cm | Low | Yes |
| Sensors (dead reckoning) | Accelerometer, gyroscope, compass estimate movement between fixes | Drifts over time | Low | Yes |
Fused Location Provider (Google Play services) automatically combines GPS, Wi-Fi, cell and sensors to give the best accuracy for the least power, according to the requested priority:
| Priority | Typical source | Use |
|---|---|---|
PRIORITY_HIGH_ACCURACY |
GPS | Navigation, running tracker |
PRIORITY_BALANCED_POWER_ACCURACY |
Wi-Fi/cell (~100 m) | Weather, nearby places |
PRIORITY_LOW_POWER |
Cell (~10 km) | City-level content |
PRIORITY_PASSIVE |
Only locations requested by other apps | Zero extra battery |
Other location data: altitude, bearing (direction), speed, accuracy radius, timestamp. Geocoding converts addresses ↔ coordinates. Android's platform LocationManager (GPS_PROVIDER, NETWORK_PROVIDER) also exists, but the fused provider is recommended.
5. Location-aware applications
A location-aware (location-based) application uses the device's current location to provide relevant information or services – a type of context-aware computing.
Categories and examples
| Category | Examples |
|---|---|
| Navigation and maps | Google Maps, Waze – routes, traffic |
| Ride hailing and delivery | Careem, inDrive, Yango, foodpanda, Daraz delivery tracking |
| Nearby search | Restaurants, ATMs, hospitals, mosques and prayer times by location |
| Social / check-ins | Location sharing with family (Google Maps location sharing, Life360) |
| Fitness tracking | Strava, Google Fit – distance and route of a run |
| Geofencing / alerts | Attendance when entering campus, reminders when reaching the market |
| Emergency and safety | Rescue 1122 apps, SOS location sharing, Find My Device |
| Geo-tagging | Photos, field surveys (polio teams, land records) |
| Location-based marketing | Offers when near a shop |
| Games and AR | Pokémon GO |
| Asset/fleet tracking | Vehicle trackers, logistics |
Geofencing
A geofence is a virtual boundary – a circle with a centre (lat, lng) and radius (recommended ≥ 100–150 m). The Geofencing API (Google Play services) notifies the app on ENTER, EXIT or DWELL (stays for a time), even in the background, through a PendingIntent to a BroadcastReceiver. Requires background location permission for background triggers; up to 100 geofences per app.
Geofence fence = new Geofence.Builder()
.setRequestId("campus")
.setCircularRegion(33.6844, 73.0479, 200f) // 200 m radius
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
.build();
Activity recognition and context
The Activity Recognition API detects walking, running, cycling, in vehicle, still – combined with location for smarter apps (e.g. pause tracking when still).
Privacy, permissions and ethics
- Location is highly sensitive personal data – it reveals home, workplace, religion, health visits.
- Android permissions: ACCESS_COARSE_LOCATION (approximate), ACCESS_FINE_LOCATION (precise), ACCESS_BACKGROUND_LOCATION (all the time – separate request, strict Play review), "Only this time" one-time permission (Android 11+), location indicator in the status bar (Android 12+), and the user can choose approximate only.
- Best practices: ask only when needed and explain why; prefer approximate location when sufficient; avoid background location; stop updates when not needed; store minimum location history; disclose in the privacy policy and Data safety form; secure transmission (HTTPS).
Design of a location-aware app (steps)
- Decide accuracy and frequency needed (navigation vs weather).
- Request appropriate permissions with a clear rationale.
- Check location settings are enabled (Settings Client / prompt).
- Get location (getCurrentLocation or requestLocationUpdates) with suitable priority/interval.
- Process: geocode, compute distance (
Location.distanceBetween()/distanceTo()), query nearby data from a server. - Display on a map or list; update as the user moves.
- Stop updates and handle denial gracefully.
Short and long questions
1. Discuss the challenges of mobility and wireless communication in mobile application development, and explain how developers can design apps to overcome them.
Model answer
Device challenges: limited battery (radios, GPS and screen drain power), limited CPU/RAM/storage (OS kills background apps), small touch screens, heat, and fragmentation of OS versions and hardware. Solutions: efficient code, batching work, releasing resources in lifecycle callbacks, adaptive layouts, testing across devices.
Wireless network challenges: low and fluctuating bandwidth, high latency, frequent disconnections (tunnels, rural areas, lifts), handoff between cells or Wi-Fi and mobile data changing IP addresses, higher error rates from interference and fading, asymmetric speeds and metered data costs. Solutions: offline-first design with local databases (Room), caching (HTTP and images), retries with exponential backoff and timeouts, WorkManager to sync queued changes when connectivity returns, compression and pagination, deferring big downloads to unmetered Wi-Fi, push notifications (FCM) instead of polling, and clear offline/loading/error UI.
Mobility management and context: networks must track user location for paging; apps must adapt to changing context (location, network type, activity); data edited on multiple devices requires synchronisation and conflict resolution.
Security and privacy: lost or stolen devices, eavesdropping on wireless links, rogue public Wi-Fi, and sensitive location data. Solutions: HTTPS/TLS everywhere, device and data encryption, Keystore for secrets, biometric/screen lock, remote wipe, minimal permissions and location collection, transparent privacy policies.
Designing with these constraints in mind produces apps that are responsive, battery-friendly, reliable and trustworthy as users move.
2. What is handoff?
Model answer
Handoff (handover) is the process of transferring an ongoing call or data session from one cell/base station or network to another (e.g. Wi-Fi to 4G) as the user moves, ideally without interruption.
3. List the challenges of mobile computing under device, network and mobility/security headings.
Model answer
Device: limited battery, CPU, RAM and storage, small screens, heterogeneity. Network: low and variable bandwidth, high latency, disconnections, handoff, high error rates and data cost. Mobility/security: location management, changing context, theft/loss, eavesdropping on wireless links, malicious Wi-Fi and data synchronisation.
4. Give the range and one use each of Wi-Fi, Bluetooth, BLE and NFC.
Model answer
Wi-Fi – about 30–100 m, internet access; Bluetooth Classic – about 10 m, headsets; BLE – about 10–50 m, wearables and beacons with very low power; NFC – about 4 cm, contactless payments.
5. Compare 2G, 3G, 4G and 5G.
Model answer
2G (GSM, 1990s) – digital voice, SMS and slow data (GPRS/EDGE); 3G (UMTS/HSPA, 2000s) – mobile internet in Mbps and video calls; 4G (LTE, 2010s) – all-IP broadband of tens–hundreds of Mbps, VoLTE and streaming; 5G (NR, 2019+) – Gbps speeds (eMBB), about 1 ms latency (URLLC) and massive IoT (mMTC).
6. List five strategies for building apps that work on unreliable networks.
Model answer
Offline-first local storage (Room), caching responses and images, retry with exponential backoff and timeouts, queuing changes and syncing with WorkManager when online, minimising data (compression, pagination) and deferring large downloads to unmetered Wi-Fi; also push notifications instead of polling.
7. What is the Fused Location Provider?
Model answer
A Google Play services API that intelligently combines GPS, Wi-Fi, cell signals and device sensors to deliver the best location for the requested priority (high accuracy, balanced, low power, passive) while minimising battery use.
8. Compare GPS, Wi-Fi positioning and cell-ID positioning.
Model answer
GPS uses at least four satellites, giving about 3–10 m accuracy outdoors but high power and poor indoor performance. Wi-Fi positioning matches nearby access points, giving about 15–40 m accuracy with low power and works indoors. Cell-ID uses cell towers, giving hundreds of metres to kilometres accuracy with very low power everywhere there is coverage.
9. What are location-aware applications? Explain the positioning technologies used by smartphones, the Fused Location Provider, geofencing, and the privacy considerations, with examples.
Model answer
Location-aware applications use the device's current position to deliver relevant services – navigation (Google Maps), ride hailing and delivery tracking (Careem, foodpanda), nearby search (ATMs, hospitals, mosques), fitness tracking, geofenced reminders or attendance, emergency SOS, geo-tagging, location-based marketing, AR games and fleet tracking.
Positioning technologies: GNSS/GPS (GPS, GLONASS, Galileo, BeiDou) uses at least four satellites for 3–10 m accuracy outdoors at high power; A-GPS speeds up the first fix; Wi-Fi positioning (15–40 m, indoors, low power); cell-ID (hundreds of metres–km, very low power); Bluetooth beacons and UWB for precise indoor positioning; sensors for dead reckoning.
Fused Location Provider: combines all sources to give the best location for a requested priority – HIGH_ACCURACY (GPS), BALANCED_POWER_ACCURACY (~100 m), LOW_POWER (~10 km), PASSIVE – via getCurrentLocation, getLastLocation and requestLocationUpdates with LocationRequest intervals; also provides altitude, bearing, speed and accuracy. Geocoder converts coordinates and addresses; Location.distanceBetween computes distances.
Geofencing: circular virtual boundaries (centre + radius ≥ 100–150 m) monitored by the Geofencing API; ENTER, EXIT and DWELL transitions are delivered through a PendingIntent to a BroadcastReceiver; needs background location for background triggers.
Privacy: location reveals home, work and habits. Android protects it with ACCESS_COARSE/FINE permissions (user may pick approximate), separate ACCESS_BACKGROUND_LOCATION with strict Play review, one-time permissions and status-bar indicators. Apps should request the minimum accuracy, explain the reason, avoid background tracking, stop updates when not needed, store little history, secure transmission and disclose use in the privacy policy and Data safety form.
10. What is geofencing? Give an example.
Model answer
Geofencing defines a virtual circular boundary (centre coordinates and radius); the system notifies the app when the device enters, exits or dwells in it, even in the background. Example: marking attendance automatically when a student enters the campus or reminding a user to buy items when near a market.
This lesson ends with a quiz of 29 MCQs. Open the lesson on PrepOasis to take it and save your progress.
Previous: Week 15 Lab 15 – Display the Device's Current Location Coordinates · Next: Week 16 Lab 16 – Generate an APK File and Install It on an Android Device or Emulator
All lessons in Mobile Application Development (CDE-315) – BS CS 5th Semester