From bcfa5d5bcec5c2820d132fd2d39be69ae2cec9cf Mon Sep 17 00:00:00 2001 From: Thomas Wirth Date: Wed, 13 Jan 2021 11:45:19 +0100 Subject: [PATCH] Add more granular conditions for play services validation --- .../com/g00fy2/quickie/utils/PlayServicesValidator.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/quickie/src/unbundled/kotlin/com/g00fy2/quickie/utils/PlayServicesValidator.kt b/quickie/src/unbundled/kotlin/com/g00fy2/quickie/utils/PlayServicesValidator.kt index ac6d04cd..775a51d3 100644 --- a/quickie/src/unbundled/kotlin/com/g00fy2/quickie/utils/PlayServicesValidator.kt +++ b/quickie/src/unbundled/kotlin/com/g00fy2/quickie/utils/PlayServicesValidator.kt @@ -1,6 +1,7 @@ package com.g00fy2.quickie.utils import android.app.Activity +import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.GoogleApiAvailability import com.google.mlkit.common.MlKitException @@ -11,11 +12,13 @@ internal object PlayServicesValidator { private const val REQUEST_CODE = 9000 internal fun handleGooglePlayServicesError(activity: Activity, exception: Exception): Boolean { - if (exception is MlKitException) { + if (exception is MlKitException && exception.errorCode == MlKitException.UNAVAILABLE) { // check if Google Play services is available and its version is at least MIN_SERVICES_VERSION val resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity, MIN_SERVICES_VERSION) - if (GoogleApiAvailability.getInstance().isUserResolvableError(resultCode)) { + if (resultCode != ConnectionResult.SUCCESS && + GoogleApiAvailability.getInstance().isUserResolvableError(resultCode) + ) { GoogleApiAvailability.getInstance().getErrorDialog(activity, resultCode, REQUEST_CODE)?.let { it.setOnDismissListener { activity.finish() } it.show()