Skip to content

Instantly share code, notes, and snippets.

@imandaliya
Created January 6, 2024 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imandaliya/ff0ef24fe1cce74ccf6064d531fbb858 to your computer and use it in GitHub Desktop.
Save imandaliya/ff0ef24fe1cce74ccf6064d531fbb858 to your computer and use it in GitHub Desktop.
private fun getAdsId() {
CoroutineScope(Dispatchers.IO).launch {
var idInfo: AdvertisingIdClient.Info? = null
try {
idInfo = AdvertisingIdClient.getAdvertisingIdInfo(applicationContext)
} catch (e: GooglePlayServicesNotAvailableException) {
e.printStackTrace()
} catch (e: GooglePlayServicesRepairableException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
var advertId: String? = null
try {
advertId = idInfo?.id
} catch (e: NullPointerException) {
e.printStackTrace()
}
Log.d("_TAG_", "getAdsId:104 => $advertId")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment