android compat fix for old devices
This commit is contained in:
parent
ab92b883b6
commit
c4a7969ed7
6 changed files with 39 additions and 15 deletions
|
@ -56,13 +56,7 @@ fun Geocoder.getFromLocationCompat(
|
|||
onError: (errorCode: String, errorMessage: String?, errorDetails: Any?) -> Unit,
|
||||
) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
getFromLocation(latitude, longitude, maxResults, object : Geocoder.GeocodeListener {
|
||||
override fun onGeocode(addresses: List<Address?>) = processAddresses(addresses.filterNotNull())
|
||||
|
||||
override fun onError(errorMessage: String?) {
|
||||
onError("getAddress-asyncerror", "failed to get address", errorMessage)
|
||||
}
|
||||
})
|
||||
Compat33.geocoderGetFromLocation(this, latitude, longitude, maxResults, processAddresses, onError)
|
||||
} else {
|
||||
try {
|
||||
@Suppress("deprecation")
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package deckers.thibault.aves.utils
|
||||
|
||||
import android.location.Address
|
||||
import android.location.Geocoder
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
|
||||
/**
|
||||
* Compatibility layer in a separate object to avoid class loading issues on older Android versions.
|
||||
* e.g. `ClassNotFoundException` for `android.location.Geocoder$GeocodeListener`
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||
object Compat33 {
|
||||
fun geocoderGetFromLocation(
|
||||
geocoder: Geocoder,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
maxResults: Int,
|
||||
processAddresses: (addresses: List<Address>) -> Unit,
|
||||
onError: (errorCode: String, errorMessage: String?, errorDetails: Any?) -> Unit,
|
||||
) {
|
||||
geocoder.getFromLocation(latitude, longitude, maxResults, object : Geocoder.GeocodeListener {
|
||||
override fun onGeocode(addresses: List<Address?>) = processAddresses(addresses.filterNotNull())
|
||||
|
||||
override fun onError(errorMessage: String?) {
|
||||
onError("getAddress-asyncerror", "failed to get address", errorMessage)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
buildscript {
|
||||
ext {
|
||||
agp_version = '8.4.0' // same as `settings.ext.agp_version` in `/android/settings.gradle`
|
||||
agp_version = '8.4.1' // same as `settings.ext.agp_version` in `/android/settings.gradle`
|
||||
glide_version = '4.16.0'
|
||||
// AppGallery Connect plugin versions: https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-sdk-changenotes-0000001058732550
|
||||
huawei_agconnect_version = '1.9.1.300'
|
||||
|
|
|
@ -8,9 +8,9 @@ pluginManagement {
|
|||
}
|
||||
settings.ext.flutterSdkPath = flutterSdkPath()
|
||||
|
||||
settings.ext.kotlin_version = '1.9.21'
|
||||
settings.ext.ksp_version = "$kotlin_version-1.0.15"
|
||||
settings.ext.agp_version = '8.4.0'
|
||||
settings.ext.kotlin_version = '1.9.24'
|
||||
settings.ext.ksp_version = "$kotlin_version-1.0.20"
|
||||
settings.ext.agp_version = '8.4.1'
|
||||
|
||||
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ version '1.0-SNAPSHOT'
|
|||
|
||||
buildscript {
|
||||
ext {
|
||||
kotlin_version = '1.8.21'
|
||||
agp_version = '8.3.1'
|
||||
kotlin_version = '1.9.24'
|
||||
agp_version = '8.4.1'
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
|
@ -3,8 +3,8 @@ version '1.0-SNAPSHOT'
|
|||
|
||||
buildscript {
|
||||
ext {
|
||||
kotlin_version = '1.9.22'
|
||||
agp_version = '8.4.0'
|
||||
kotlin_version = '1.9.24'
|
||||
agp_version = '8.4.1'
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
Loading…
Reference in a new issue