• gps background update

    From Jakub@21:1/5 to All on Sun Jan 14 13:10:43 2024
    I have this fun to get gps location


    fun getLocation11(context: Context) {

    val fusedLocationClient =
    LocationServices.getFusedLocationProviderClient(context)

    if ( ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
    != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context,
    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED ) {

    return
    }

    fusedLocationClient.getCurrentLocation(PRIORITY_HIGH_ACCURACY,
    object : CancellationToken() {
    override fun onCanceledRequested(p0:
    OnTokenCanceledListener): CancellationToken
    = CancellationTokenSource().token

    override fun isCancellationRequested(): Boolean = false
    }).addOnSuccessListener {location: Location? ->
    if ( location != null ) {
    getAddressFromPosittion(context, location.latitude, location.longitude)
    }
    }

    }



    and this function to start

    private fun startService() : Boolean {
    if ( !ACCESS_FINE_LOCATION_permision ) {
    showAlert03(aThis, "permision", "gps not granted",
    fontTextSize)
    return false
    }

    if ( !gpsPositionActual02.isGPS(aThis) ) {
    showAlert03(aThis, "GPS", "gps is disabled", fontTextSize)
    return false
    }

    myTimer = Timer()
    val delay = 0 // delay for 30 sec.

    val period = 10000 // repeat every 10 sec.
    //val period = 60000 // repeat every 60 sec.

    doThis = object : TimerTask() {
    override fun run() {
    readGPSPosittion()
    }
    }

    myTimer.scheduleAtFixedRate(doThis, delay.toLong(), period.toLong())

    return true
    }


    and android manifest

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission
    android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission
    android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission
    android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

    fun work fine but when i minimize app this function dont show actual
    possition

    how to fix this?

    how to get actual gps locattion when app is minimize?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)