Class LocationTrackingHelper


  • public class LocationTrackingHelper
    extends java.lang.Object
    Helper class for accessing and modifying location related data
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getLocation​(android.content.Context context)
      Returns the most recent location.
      static boolean isAppLocationPermissionEnabled​(android.content.Context context)
      Returns the status of location permission in the app device settings
      static boolean isLocationServiceEnabled​(android.content.Context context)
      Returns the status of location services in the OS level
      static boolean isUserPermissionEnabled​(android.content.Context context)
      Returns the status of user permission in the app level
      static void saveLocation​(android.content.Context context, android.location.Location location)
      Stores the location in preferences The latitude and longitude are saved in the preferences in the following format: { “lat”: 40.759211, “lon”: -73.984638} If the location is null or empty, an empty string will be stored in the preferences
      static void setUserPermission​(android.content.Context context, boolean isEnabled)
      Sets the status of user permission in the app level
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocationTrackingHelper

        public LocationTrackingHelper()
    • Method Detail

      • getLocation

        public static java.lang.String getLocation​(android.content.Context context)
        Returns the most recent location. If the location services and app location permission are disabled, an empty string will be returned
        Parameters:
        context - The context to use for getting location
        Returns:
        String which contains the latitude and longitude in the following format: { “lat”: 40.759211, “lon”: -73.984638}
      • saveLocation

        public static void saveLocation​(android.content.Context context,
                                        android.location.Location location)
        Stores the location in preferences The latitude and longitude are saved in the preferences in the following format: { “lat”: 40.759211, “lon”: -73.984638} If the location is null or empty, an empty string will be stored in the preferences
        Parameters:
        context - The context to use to store the location
        location - data to be stored
      • isUserPermissionEnabled

        public static boolean isUserPermissionEnabled​(android.content.Context context)
        Returns the status of user permission in the app level
        Parameters:
        context - used to get resources
        Returns:
        true - user allows tracking of location, false - user does not allow tracking of location
      • setUserPermission

        public static void setUserPermission​(android.content.Context context,
                                             boolean isEnabled)
        Sets the status of user permission in the app level
        Parameters:
        context - used to get resources
        isEnabled - true - user allows tracking of location, false - user does not allow tracking of location
      • isAppLocationPermissionEnabled

        public static boolean isAppLocationPermissionEnabled​(android.content.Context context)
        Returns the status of location permission in the app device settings
        Parameters:
        context - used to get resources
        Returns:
        true - the application is allowed to retrieve user's current location, false - the application does not allow the user to retrieve the user's current location
      • isLocationServiceEnabled

        public static boolean isLocationServiceEnabled​(android.content.Context context)
        Returns the status of location services in the OS level
        Parameters:
        context - used to get resources
        Returns:
        true - allows retrieving of location, false - does not allow retrieving location