Skip to content

Commit

Permalink
Add more granular conditions for play services validation
Browse files Browse the repository at this point in the history
  • Loading branch information
G00fY2 committed Jan 13, 2021
1 parent 17767b7 commit bcfa5d5
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
Expand Down

0 comments on commit bcfa5d5

Please sign in to comment.