diff --git a/CHANGELOG.md b/CHANGELOG.md index c1320635..361f1d02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fixed app crash when location service is disabled on Android 10 and prior ([#177]) ## [1.3.0] - 2025-09-17 ### Changed diff --git a/app/src/main/kotlin/org/fossify/camera/helpers/SimpleLocationManager.kt b/app/src/main/kotlin/org/fossify/camera/helpers/SimpleLocationManager.kt index 346ad5c6..edca1c15 100644 --- a/app/src/main/kotlin/org/fossify/camera/helpers/SimpleLocationManager.kt +++ b/app/src/main/kotlin/org/fossify/camera/helpers/SimpleLocationManager.kt @@ -4,6 +4,7 @@ import android.Manifest import android.location.Location import android.location.LocationListener import android.location.LocationManager +import android.os.Bundle import androidx.annotation.RequiresPermission import org.fossify.camera.extensions.checkLocationPermission import org.fossify.commons.activities.BaseSimpleActivity @@ -15,12 +16,23 @@ class SimpleLocationManager(private val activity: BaseSimpleActivity) { private const val LOCATION_UPDATE_MIN_DISTANCE_M = 10F } + private var location: Location? = null + private val locationManager = activity.getSystemService(LocationManager::class.java)!! - private val locationListener = LocationListener { location -> - this@SimpleLocationManager.location = location - } - private var location: Location? = null + @Suppress("EmptyFunctionBlock") + private val locationListener = object: LocationListener { + override fun onLocationChanged(location: Location) { + this@SimpleLocationManager.location = location + } + + // No-op methods that must be overridden. + // See https://github.com/FossifyOrg/Camera/issues/177 + @Suppress("DEPRECATION") + override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {} + override fun onProviderEnabled(provider: String) {} + override fun onProviderDisabled(provider: String) {} + } fun getLocation(): Location? { if (location == null) {