Package com.kernelcrew.moodapp.data
Class LocationHandler
java.lang.Object
com.kernelcrew.moodapp.data.LocationHandler
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.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Initiates a location fetch: 1.static Location
getCurrentLocation
(Context context) Returns the current location if permission is granted.
-
Field Details
-
REQUEST_LOCATION_PERMISSION
public static final int REQUEST_LOCATION_PERMISSION- See Also:
-
-
Constructor Details
-
LocationHandler
-
-
Method Details
-
fetchLocation
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
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.
-