Procházet zdrojové kódy

Moving stuff around a bit.

Thomas Chef před 3 roky
rodič
revize
4cf402bfcb

+ 7 - 5
app/src/main/java/com/flacksta/chef/journeygpstracker/TrackingService.kt

@@ -28,8 +28,9 @@ class TrackingService : Service() {
     override fun onCreate() {
         super.onCreate()
         Log.i(mTag,"onCreate()")
-        requestLocationUpdates()
-
+        generateForegroundNotification()
+        startForeground(mNotificationId, notification)
+        Log.i(mTag,"Requested foreground service...")
     }
 
     private fun requestLocationUpdates() {
@@ -38,6 +39,7 @@ class TrackingService : Service() {
         mLocationRequest = LocationRequest.create().apply {
             interval = 2000
             fastestInterval = 2000
+            //smallestDisplacement = 2.0f
             priority = LocationRequest.PRIORITY_HIGH_ACCURACY
         }
 
@@ -46,7 +48,8 @@ class TrackingService : Service() {
                 locationResult ?: return
                 for (location in locationResult.locations){
                     counter += 1
-                    Log.i(mTag, "Got location: $counter")
+                    val acc = location.accuracy
+                    Log.i(mTag, "Got location: $counter  $acc")
 
                 }
             }
@@ -68,7 +71,7 @@ class TrackingService : Service() {
     override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
         @Suppress("UNUSED_VARIABLE") val retVal: Int = super.onStartCommand(intent, flags, startId)
         Log.i(mTag,"onStartCommand()")
-        generateForegroundNotification()
+        requestLocationUpdates()
         return START_STICKY
     }
 
@@ -113,7 +116,6 @@ class TrackingService : Service() {
         }
         builder.color = ContextCompat.getColor(this, R.color.purple_200)
         builder.build().also { notification = it }
-        startForeground(mNotificationId, notification)
     }
 
     override fun onDestroy() {