|
@@ -7,13 +7,18 @@ import android.content.Intent
|
|
import android.content.pm.PackageManager
|
|
import android.content.pm.PackageManager
|
|
import android.graphics.Bitmap
|
|
import android.graphics.Bitmap
|
|
import android.graphics.BitmapFactory
|
|
import android.graphics.BitmapFactory
|
|
|
|
+import android.location.Location
|
|
import android.os.IBinder
|
|
import android.os.IBinder
|
|
import android.os.Looper
|
|
import android.os.Looper
|
|
import android.util.Log
|
|
import android.util.Log
|
|
import androidx.core.app.ActivityCompat
|
|
import androidx.core.app.ActivityCompat
|
|
import androidx.core.app.NotificationCompat
|
|
import androidx.core.app.NotificationCompat
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.core.content.ContextCompat
|
|
|
|
+import com.flacksta.chef.journeygpstracker.database.GpsData
|
|
|
|
+import com.flacksta.chef.journeygpstracker.database.GpsPosRepository
|
|
import com.google.android.gms.location.*
|
|
import com.google.android.gms.location.*
|
|
|
|
+import kotlinx.coroutines.launch
|
|
|
|
+import kotlinx.coroutines.runBlocking
|
|
|
|
|
|
class TrackingService : Service() {
|
|
class TrackingService : Service() {
|
|
|
|
|
|
@@ -24,18 +29,25 @@ class TrackingService : Service() {
|
|
private lateinit var mLocationRequest: LocationRequest
|
|
private lateinit var mLocationRequest: LocationRequest
|
|
private lateinit var mLocationCallback: LocationCallback
|
|
private lateinit var mLocationCallback: LocationCallback
|
|
|
|
|
|
- //val database by lazy { GpsPosRoomDatabase.getDatabase(this) }
|
|
|
|
- //val database by lazy { GpsPosRoomDatabase.getDatabase(this) }
|
|
|
|
- //val repository by lazy { GpsPosRepository(database.gpsDataDao()) }
|
|
|
|
|
|
+ private lateinit var trackApp : JourneyGpsTrackerApplication
|
|
|
|
|
|
override fun onCreate() {
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
super.onCreate()
|
|
Log.i(mTag,"onCreate()")
|
|
Log.i(mTag,"onCreate()")
|
|
generateForegroundNotification()
|
|
generateForegroundNotification()
|
|
|
|
+ trackApp = JourneyGpsTrackerApplication()
|
|
startForeground(mNotificationId, notification)
|
|
startForeground(mNotificationId, notification)
|
|
Log.i(mTag,"Requested foreground service...")
|
|
Log.i(mTag,"Requested foreground service...")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun insertPos(pos: Location) = runBlocking {
|
|
|
|
+ launch {
|
|
|
|
+ var d = GpsData(0, System.currentTimeMillis(), pos.latitude, pos.longitude, pos.accuracy)
|
|
|
|
+ val repo: GpsPosRepository = trackApp.repository
|
|
|
|
+ repo.insert(d)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private fun requestLocationUpdates() {
|
|
private fun requestLocationUpdates() {
|
|
|
|
|
|
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
|
|
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
|
|
@@ -53,8 +65,7 @@ class TrackingService : Service() {
|
|
counter += 1
|
|
counter += 1
|
|
val acc = location.accuracy
|
|
val acc = location.accuracy
|
|
Log.i(mTag, "Got location: $counter $acc")
|
|
Log.i(mTag, "Got location: $counter $acc")
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ insertPos(location)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|