Skip to content

Instantly share code, notes, and snippets.

@giolaq
Created May 27, 2020 15:28
Show Gist options
  • Select an option

  • Save giolaq/69b8c146f10a6205b614877ebd567416 to your computer and use it in GitHub Desktop.

Select an option

Save giolaq/69b8c146f10a6205b614877ebd567416 to your computer and use it in GitHub Desktop.
object DocumentTextRecognizerService {
private fun getServiceType(context: Context) = when {
isGooglePlayServicesAvailable(
context
) -> ServiceType.GOOGLE
isHuaweiMobileServicesAvailable(
context
) -> ServiceType.HUAWEI
else -> ServiceType.GOOGLE
}
private fun isGooglePlayServicesAvailable(context: Context): Boolean {
return GoogleApiAvailability.getInstance()
.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS
}
private fun isHuaweiMobileServicesAvailable(context: Context): Boolean {
return HuaweiApiAvailability.getInstance()
.isHuaweiMobileServicesAvailable(context) == com.huawei.hms.api.ConnectionResult.SUCCESS
}
fun create(context: Context): DocumentTextRecognizer {
val type =
getServiceType(
context
)
if (type == ServiceType.HUAWEI)
return HMSDocumentTextRecognizer()
return GMSDocumentTextRecognizer()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment