Last active
July 15, 2021 00:04
-
-
Save maxirosson/9eb722182bb3b0950d0c18c33247b2ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object CrashlyticsHelper { | |
fun sendCustomKeys(context: Context) { | |
val builder = CustomKeysAndValues.Builder() | |
builder.putString("abi", Build.SUPPORTED_ABIS[0]) | |
builder.putString("locale", getLocale(context).toString()) | |
builder.putBoolean("isGooglePlayServicesAvailable", isGooglePlayServicesAvailable(context)) | |
getInstallSource(context)?.let { | |
builder.putString("installSource", it) | |
} | |
FirebaseCrashlytics.getInstance().setCustomKeys(builder.build()) | |
} | |
/** | |
* Retrieve the locale information for the app. | |
*/ | |
@Suppress("DEPRECATION") | |
private fun getLocale(context: Context): Locale { | |
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
context.resources.configuration.locales[0] | |
} else { | |
context.resources.configuration.locale | |
} | |
} | |
private fun isGooglePlayServicesAvailable(context: Context): Boolean { | |
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS | |
} | |
private fun getInstallSource(context: Context): String? { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | |
return context.packageManager.getInstallSourceInfo(context.packageName).initiatingPackageName | |
} | |
return null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment