Class LocationHandler

java.lang.Object
com.kernelcrew.moodapp.data.LocationHandler

public class LocationHandler extends Object
LocationHandler - A non-UI class for requesting location updates Created by taking logic from a functional LocationFragment, so that it can be used in other functions.
  • Field Details

    • REQUEST_LOCATION_PERMISSION

      public static final int REQUEST_LOCATION_PERMISSION
      See Also:
  • Constructor Details

    • LocationHandler

      public LocationHandler(Context context)
  • Method Details

    • fetchLocation

      public void fetchLocation(LocationHandler.OnLocationObtainedListener listener)
      Initiates a location fetch: 1. Checks if location services are enabled (GPS/Network). 2. Checks if FINE_LOCATION permission is granted. 3. Attempts to retrieve the last known location. 4. If null or an error occurs, requests a new location update.
      Parameters:
      listener - callback for success/failure
    • getCurrentLocation

      public static Location getCurrentLocation(Context context)
      Returns the current location if permission is granted. If not, it requests the ACCESS_FINE_LOCATION permission from the Activity.
      Parameters:
      context - The context (should be an Activity).
      Returns:
      The last known Location, or null if not available or permission is missing.