Skip to content

Commit 50e5e72

Browse files
authored
fix: override abstract methods in location listener (#178)
Some `LocationListener` methods don't have default implementations on Android 10 and older versions, and that leads to a crash. Refs: #177
1 parent 68f7a85 commit 50e5e72

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Fixed app crash when location service is disabled on Android 10 and prior ([#177])
810

911
## [1.3.0] - 2025-09-17
1012
### Changed

app/src/main/kotlin/org/fossify/camera/helpers/SimpleLocationManager.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.Manifest
44
import android.location.Location
55
import android.location.LocationListener
66
import android.location.LocationManager
7+
import android.os.Bundle
78
import androidx.annotation.RequiresPermission
89
import org.fossify.camera.extensions.checkLocationPermission
910
import org.fossify.commons.activities.BaseSimpleActivity
@@ -15,12 +16,23 @@ class SimpleLocationManager(private val activity: BaseSimpleActivity) {
1516
private const val LOCATION_UPDATE_MIN_DISTANCE_M = 10F
1617
}
1718

19+
private var location: Location? = null
20+
1821
private val locationManager = activity.getSystemService(LocationManager::class.java)!!
19-
private val locationListener = LocationListener { location ->
20-
this@SimpleLocationManager.location = location
21-
}
2222

23-
private var location: Location? = null
23+
@Suppress("EmptyFunctionBlock")
24+
private val locationListener = object: LocationListener {
25+
override fun onLocationChanged(location: Location) {
26+
this@SimpleLocationManager.location = location
27+
}
28+
29+
// No-op methods that must be overridden.
30+
// See https://github.com/FossifyOrg/Camera/issues/177
31+
@Suppress("DEPRECATION")
32+
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {}
33+
override fun onProviderEnabled(provider: String) {}
34+
override fun onProviderDisabled(provider: String) {}
35+
}
2436

2537
fun getLocation(): Location? {
2638
if (location == null) {

0 commit comments

Comments
 (0)