diff --git a/app/build.gradle b/app/build.gradle index 305bcb4c8..83bb6634c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -219,7 +219,7 @@ dependencies { implementation 'com.github.mik3y:usb-serial-for-android:3.4.6' // location services - googleImplementation 'com.google.android.gms:play-services-location:19.0.1' + googleImplementation 'com.google.android.gms:play-services-location:21.0.1' // For Firebase Crashlytics & Analytics googleImplementation platform('com.google.firebase:firebase-bom:32.1.0') diff --git a/app/src/google/java/com/geeksville/mesh/repository/location/SharedLocationManager.kt b/app/src/google/java/com/geeksville/mesh/repository/location/SharedLocationManager.kt index a86c4ee8b..14d736dd5 100644 --- a/app/src/google/java/com/geeksville/mesh/repository/location/SharedLocationManager.kt +++ b/app/src/google/java/com/geeksville/mesh/repository/location/SharedLocationManager.kt @@ -12,6 +12,7 @@ import com.google.android.gms.location.LocationCallback import com.google.android.gms.location.LocationRequest import com.google.android.gms.location.LocationResult import com.google.android.gms.location.LocationServices +import com.google.android.gms.location.Priority import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow @@ -39,20 +40,21 @@ class SharedLocationManager constructor( // Set up the Fused Location Provider and LocationRequest private val fusedLocationClient = LocationServices.getFusedLocationProviderClient(context) - private val locationRequest = LocationRequest.create().apply { - interval = desiredInterval - fastestInterval = 30 * 1000L - maxWaitTime = 5 * 60 * 1000L - // smallestDisplacement = 30F // 30 meters - priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY - } + private val locationRequest = LocationRequest.Builder(desiredInterval) + .setMinUpdateIntervalMillis(30 * 1000L) + .setMaxUpdateDelayMillis(5 * 60 * 1000L) + // .setMinUpdateDistanceMeters(30f) // 30 meters + .setPriority(Priority.PRIORITY_BALANCED_POWER_ACCURACY) + .build() @SuppressLint("MissingPermission") private val _locationUpdates = callbackFlow { val callback = object : LocationCallback() { override fun onLocationResult(result: LocationResult) { // info("New location: ${result.lastLocation}") - trySend(result.lastLocation) + result.lastLocation?.let { lastLocation -> + trySend(lastLocation) + } } } if (!context.hasBackgroundPermission() || !isGooglePlayAvailable(context)) close()