feat: add send location button to force immediate report
This commit is contained in:
parent
4eade880b1
commit
cd34c8bbf3
5 changed files with 92 additions and 31 deletions
|
|
@ -62,6 +62,10 @@ class BridgeModule : FlutterPlugin, MethodChannel.MethodCallHandler {
|
|||
"getStatus" -> {
|
||||
result.success(getTrackingStatus())
|
||||
}
|
||||
"reportLocation" -> {
|
||||
reportLocationNow()
|
||||
result.success(true)
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
|
@ -107,4 +111,11 @@ class BridgeModule : FlutterPlugin, MethodChannel.MethodCallHandler {
|
|||
"lastTimestamp" to prefs.getLong("last_timestamp", 0L)
|
||||
)
|
||||
}
|
||||
|
||||
private fun reportLocationNow() {
|
||||
val intent = android.content.Intent(context, LocationTrackingService::class.java).apply {
|
||||
action = LocationTrackingService.ACTION_REPORT
|
||||
}
|
||||
context?.startService(intent)
|
||||
}
|
||||
}
|
||||
|
|
@ -49,6 +49,7 @@ class LocationTrackingService : Service() {
|
|||
private var wakeLock: PowerManager.WakeLock? = null
|
||||
private var isTracking = false
|
||||
private var isNetworkAvailable = true
|
||||
private var bypassFilterOnce = false
|
||||
|
||||
private var currentConfig: TrackingConfig? = null
|
||||
|
||||
|
|
@ -77,6 +78,7 @@ class LocationTrackingService : Service() {
|
|||
when (intent?.action) {
|
||||
ACTION_START -> startTracking()
|
||||
ACTION_STOP -> stopTracking()
|
||||
ACTION_REPORT -> reportLocationNow()
|
||||
}
|
||||
return START_STICKY
|
||||
}
|
||||
|
|
@ -144,6 +146,19 @@ class LocationTrackingService : Service() {
|
|||
logEvent("INFO", "Tracking stopped")
|
||||
}
|
||||
|
||||
fun reportLocationNow() {
|
||||
if (!isTracking) {
|
||||
logEvent("ERROR", "Cannot report: tracking not active")
|
||||
return
|
||||
}
|
||||
bypassFilterOnce = true
|
||||
fusedLocationProvider.getLastLocation { location ->
|
||||
location?.let {
|
||||
onLocationReceived(it)
|
||||
} ?: logEvent("ERROR", "No location available for report")
|
||||
}
|
||||
}
|
||||
|
||||
fun updateConfig(config: TrackingConfig) {
|
||||
currentConfig = config
|
||||
if (isTracking) {
|
||||
|
|
@ -161,10 +176,11 @@ class LocationTrackingService : Service() {
|
|||
angleFilter = config.angleFilter
|
||||
)
|
||||
|
||||
if (!distanceFilterProcessor.shouldAccept(location, filterConfig)) {
|
||||
if (!bypassFilterOnce && !distanceFilterProcessor.shouldAccept(location, filterConfig)) {
|
||||
logEvent("FILTERED", "Location filtered by distance/interval/angle")
|
||||
return
|
||||
}
|
||||
bypassFilterOnce = false
|
||||
|
||||
val traccarLocation = TraccarLocation(
|
||||
timestamp = location.time,
|
||||
|
|
@ -367,6 +383,7 @@ class LocationTrackingService : Service() {
|
|||
companion object {
|
||||
const val ACTION_START = "com.traccar.traccar_client.ACTION_START"
|
||||
const val ACTION_STOP = "com.traccar.traccar_client.ACTION_STOP"
|
||||
const val ACTION_REPORT = "com.traccar.traccar_client.ACTION_REPORT"
|
||||
private const val CHANNEL_ID = "traccar_tracking_channel"
|
||||
private const val NOTIFICATION_ID = 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue