diff --git a/gradle.properties b/gradle.properties index f4a3872a..79d49aac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx2048m org.gradle.configureondemand=false android.useAndroidX=true libGroup=com.adevinta.android -libVersion=10.0.0 +libVersion=10.0.1 diff --git a/leku/src/main/java/com/adevinta/leku/utils/ReactiveLocationProvider.kt b/leku/src/main/java/com/adevinta/leku/utils/ReactiveLocationProvider.kt index 0fbb8442..72e16f37 100644 --- a/leku/src/main/java/com/adevinta/leku/utils/ReactiveLocationProvider.kt +++ b/leku/src/main/java/com/adevinta/leku/utils/ReactiveLocationProvider.kt @@ -1,8 +1,11 @@ package com.adevinta.leku.utils +import android.Manifest import android.content.Context +import android.content.pm.PackageManager import android.location.Location import androidx.annotation.RequiresPermission +import androidx.core.content.ContextCompat import com.google.android.gms.location.LocationServices import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine @@ -15,16 +18,22 @@ class ReactiveLocationProvider( anyOf = ["android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"] ) suspend fun getLastKnownLocation(): Location? = suspendCoroutine { task -> - LocationServices.getFusedLocationProviderClient(context) - .lastLocation - .addOnCompleteListener { locTask -> - task.resume(locTask.result) - } - .addOnCanceledListener { - task.resume(null) - } - .addOnFailureListener { - task.resume(null) - } + if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED || + ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED + ) { + LocationServices.getFusedLocationProviderClient(context) + .lastLocation + .addOnCompleteListener { locTask -> + task.resume(locTask.result) + } + .addOnCanceledListener { + task.resume(null) + } + .addOnFailureListener { + task.resume(null) + } + } else { + task.resume(null) + } } }