android.permission.ACCESS_MOCK_LOCATION

Create mock location sources for testing.
This allows the app to override the location and/or status returned by other location sources such as GPS or location providers.
Malicious applications can use this to override the location and/or status returned by real-location sources such as GPS or Network providers.

Usage in Manifest:

1
< uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

To enable mocked locations on device go to:

1
Settings -> Developer options -> Allow mock locations

Sample code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//Initiates the method to set the phones location
private void setMockLocation() {
mLocationManager.removeTestProvider(LocationManager.GPS_PROVIDER);
mLocationManager.addTestProvider
(
LocationManager.GPS_PROVIDER,
"requiresNetwork" == "",
"requiresSatellite" == "",
"requiresCell" == "",
"hasMonetaryCost" == "",
"supportsAltitude" == "",
"supportsSpeed" == "",
"supportsBearing" == "",
android.location.Criteria.POWER_LOW,
android.location.Criteria.ACCURACY_FINE
);
Location newLocation = new Location(LocationManager.GPS_PROVIDER);
newLocation.setLatitude (55.9500);
newLocation.setLongitude(3.1833);
newLocation.setAccuracy(500);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
newLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
// Elapsed time can also be set using
// mockLocation.setElapsedRealtimeNanos(System.nanoTime());
// Elapsed time can be disregarded using
// mockLocation.makeComplete();
}
mLocationManager.setTestProviderEnabled
(
LocationManager.GPS_PROVIDER,
true
);
mLocationManager.setTestProviderStatus
(
LocationManager.GPS_PROVIDER,
LocationProvider.AVAILABLE,
null,
System.currentTimeMillis()
);
mLocationManager.setTestProviderLocation
(
LocationManager.GPS_PROVIDER,
newLocation
);
}

Added in Api Level 1.
This permission constant was removed in Api Level 23 - https://developer.android.com/sdk/api_diff/23/changes/android.Manifest.permission.html

More information: