Created
June 18, 2018 23:56
-
-
Save slavkoder/ea0fc0c08d148ca9de6a2b85c8abc236 to your computer and use it in GitHub Desktop.
Fix crash in DebugBillingClient when billing returns error/empty result.
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
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