gpt4 book ai didi

java - Android kotlin google play billing onPurchasesUpdated 不覆盖任何内容或从未使用过

转载 作者:行者123 更新时间:2023-11-30 10:06:52 24 4
gpt4 key购买 nike

我正在按照此文档来实现 Google Pay:

https://developer.android.com/google/play/billing/billing_library_overview

运行此函数并购买产品后:

fun buy() {

val skuList = listOf("vip_small")

if (billingClient.isReady) {
val params = SkuDetailsParams
.newBuilder()
.setSkusList(skuList)
.setType(BillingClient.SkuType.INAPP)
.build()
billingClient.querySkuDetailsAsync(params) { responseCode, skuDetailsList ->

if (responseCode == BillingClient.BillingResponse.OK) {

Log.d("lets", "querySkuDetailsAsync, responseCode: $responseCode")


val flowParams = BillingFlowParams.newBuilder()
.setSku("vip_small")
.setType(BillingClient.SkuType.INAPP) // SkuType.SUB for subscription
.build()

val responseCodee = billingClient.launchBillingFlow(this, flowParams)

Log.d("lets", "launchBillingFlow responseCode: $responseCodee")

} else {
Log.d("lets", "Can't querySkuDetailsAsync, responseCode: $responseCode")
}
}
} else {
Log.d("lets", "Billing Client not ready")
}
}

效果很好,我想知道是否已购买,因此我从 cods 添加了以下代码:

override fun onPurchasesUpdated(@BillingResponse responseCode: Int, purchases: List<Purchase>?) {
if (responseCode == BillingResponse.OK && purchases != null) {
for (purchase in purchases) {
handlePurchase(purchase)
}
} else if (responseCode == BillingResponse.USER_CANCELED) {
// Handle an error caused by a user cancelling the purchase flow.
} else {
// Handle any other error codes.
}
}

但我收到错误'onPurchasesUpdated' 不覆盖任何内容

所以我删除了覆盖并得到了这个“错误”

Function "onPurchasesUpdated" is never used

什么鬼?购买完成后如何调用这个该死的函数?

最佳答案

我找到了解决方案。

您需要使 Activity/fragment 使用 PurchasesUpdatedListener,例如:

class VIP : AppCompatActivity(), PurchasesUpdatedListener {

}

然后覆盖就会起作用

关于java - Android kotlin google play billing onPurchasesUpdated 不覆盖任何内容或从未使用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54471188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com