Skip to content

Location

In addition to the on/off toggle, the following location modes are available on the device:

  • Device only: only the GPS is used
  • Battery saving: location is determined based on surrounding equipments such as Wi-Fi networks, GSM antennas, etc. This mode requires an Internet connection and will be referred to as Network Location.
  • High accuracy: combines the Device only and Battery saving modes (it will therefore allow use of both GPS and Network Location)

You can set the mode from the MDM by editing or adding a Profile and selecting the desired behaviour under ConnectivityLocation mode. To change it directly on the device, open the Android Settings and select LocationMode.

Location

Network location

Network location is available as part of the Enterprise bundle or as an add-on to your plan.

Battery saving and High accuracy modes both depend on a service running on the device. This service is only available on devices running an OS image version from August 2018 and later.

GPS vs Network Location

Using the GPS to get the device location is more precise than using network location and doesn't require any data connection, but the initial request (Time To First Fix) usually takes a minute or so and may not work inside or next to a building.

On the other hand, Network Location will work well indoor and the request will be executed immediately, but it requires a data connection and is less precise than GPS.

Here is a comparison of both technologies:

GPS Network Location
Indoor precision Low Depends on the provider
Outdoor precision High Depends on the provider
Needs data connection No Yes
Battery consumption High Low
First location request Slow Quick

Code sample

Add one of the following permissions in your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Fine location permission is only required if you want to use the GPS.

Now, in your Activity or Service, create a LocationManager and a LocationListener and start requesting for location as follows:

package com.famoco.locationtest;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class LocationTestActivity extends AppCompatActivity {

    private static final String TAG = LocationTestActivity.class.getSimpleName();
    private static final long MIN_UPDATE_INTERVAL_IN_MS = 10 * 1000;
    private static final float MIN_UPDATE_DISTANCE_IN_M = 10;

    private LocationManager mLocationManager;
    private LocationListener mLocationListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_location_test);

        mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        mLocationListener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                Log.d(TAG, "onLocationChanged: " + location);
                // Update location on a map, etc.
            }

            @Override
            public void onStatusChanged(String s, int i, Bundle bundle) {

            }

            @Override
            public void onProviderEnabled(String s) {

            }

            @Override
            public void onProviderDisabled(String s) {

            }
        };
    }

    @Override
    protected void onResume() {
        super.onResume();

        // Retrieve last known location
        Location lastKnownLocation = mLocationManager.getLastKnownLocation(
                LocationManager.NETWORK_PROVIDER);

        // Retrieve location every 10 seconds if the device moved more than 10
        // meters and notify the LocationListener
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                MIN_UPDATE_INTERVAL_IN_MS, MIN_UPDATE_DISTANCE_IN_M, mLocationListener);
    }

    @Override
    protected void onPause() {
        // Stop location updates while the app is in background
        mLocationManager.removeUpdates(mLocationListener);

        super.onPause();
    }
}

Test application

You can check the behaviour of GPS and network location by using this simple open source third-party application: Here GPS Location