Skip to content

Instantly share code, notes, and snippets.

@slavkoder
Created June 18, 2018 23:56
Show Gist options
  • Save slavkoder/ea0fc0c08d148ca9de6a2b85c8abc236 to your computer and use it in GitHub Desktop.
Save slavkoder/ea0fc0c08d148ca9de6a2b85c8abc236 to your computer and use it in GitHub Desktop.
Fix crash in DebugBillingClient when billing returns error/empty result.
private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
// Receiving the result from local broadcast and triggering a callback on listener.
@BillingResponse
val responseCode = intent?.getIntExtra(DebugBillingActivity.RESPONSE_CODE, BillingResponse.ERROR)
?: BillingResponse.ERROR
var purchases: List<Purchase>? = null
if (responseCode == BillingResponse.OK) {
val resultData = intent?.getBundleExtra(DebugBillingActivity.RESPONSE_BUNDLE)
purchases = BillingHelper.extractPurchases(resultData)
// save the purchase
purchases.forEach { billingStore.addPurchase(it) }
}
// save the result
purchasesUpdatedListener.onPurchasesUpdated(responseCode, purchases)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment