Flagship Educational Guide

How to Mock GPS Location on Android: The Definitive Guide

Simulating GPS coordinates on Android is an official, built-in feature of the operating system designed specifically for software engineers and QA testers. This guide explains how Android's test provider mechanism works, why Developer Options are required, and how coordinates flow from an app like Mockery into the system.

1. What is an Android Mock Location?

An Android mock location is a synthetic geographic coordinate (latitude, longitude, altitude, speed, bearing, accuracy) injected directly into Android's core LocationManager service.

Under normal circumstances, Android gathers location data from physical hardware: the internal GNSS satellite receiver, Wi-Fi access point BSSID trilateration, and cellular tower IDs. When a mock location provider is active, the operating system intercepts requests for location updates and delivers the simulated coordinates to all listening applications as if they originated from physical satellites.

2. Why Does Android Provide Mock Locations?

Google designed the mock location subsystem for two primary reasons:

Developer Testing Allows engineers building navigation, ridesharing, fitness, and delivery apps to test geofencing triggers, route navigation, and speed calculations from an office desk without physically traveling.
External Hardware Interfacing Allows specialized field applications (surveying, maritime, agriculture, aviation) to feed coordinates from high-precision external RTK GNSS receivers or Bluetooth receivers into standard consumer Android tablets.

3. Why Developer Options Are Mandatory

If any ordinary application could secretly mock locations, rogue apps could forge user locations without consent, bypassing fraud detection, geo-restricted media licensing, or parental controls.

🔒 Android Security Sandbox Android strictly isolates mock location authorization inside Developer Options. Only one application at a time can be explicitly selected by the device owner as the designated mock location app.

4. How to Enable Mock Locations on Android

Universal setup steps valid for stock Android 8.0 through Android 15.

1
Unlock Developer Options

Go to Settings > About phone. Tap Build number 7 times rapidly until the prompt confirms: "You are now a developer!"

2
Open Developer Options

Navigate to Settings > System > Developer options (or Settings > Additional settings > Developer options on Samsung/Xiaomi).

3
Select Mock Location App

Scroll down to the Location subheader, tap Select mock location app, and choose Mockery from the list.

Under the Hood

How Mockery Injects Locations

Once Mockery is selected, its native Kotlin foreground service executes the standard test provider registration:

// 1. Register test provider on LocationManager.GPS_PROVIDER
locationManager.addTestProvider(
LocationManager.GPS_PROVIDER, false, false, false, false, true, true, true, 1, 1
)
locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true)
// 2. Inject coordinate with current local Android timestamp
val mockLocation = Location(LocationManager.GPS_PROVIDER).apply {
latitude = currentLat
longitude = currentLon
time = System.currentTimeMillis()
elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
}
locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, mockLocation)

Crucially, Mockery generates the timestamp using local Android hardware clocks (elapsedRealtimeNanos), ensuring remote network transmission latency never causes the location to appear stale.

6. How Applications Consume and Detect Mock Locations

When an app calls FusedLocationProviderClient.getLastLocation(), Android packages the injected coordinate and passes it directly to the app.

However, Android transparently marks the coordinate. Applications can query:

  • Android 12+ (API 31+): location.isMock() returns true.
  • Android 6.0 to 11: location.isFromMockProvider() returns true.

Mockery is designed for testing and development. It operates strictly within Android’s supported architecture and does not alter these system flags.

Start Simulating Android Locations

Follow our 5-minute setup walkthrough to install Mockery and simulate your first route.