Java Android kotlin google play on PurchaseSupdated计费不覆盖任何内容或从未使用过

Java Android kotlin google play on PurchaseSupdated计费不覆盖任何内容或从未使用过,java,android,kotlin,billing,Java,Android,Kotlin,Billing,我遵循以下文档来实现google pay: 运行此功能并购买产品后: fun buy() { val skuList = listOf("vip_small") if (billingClient.isReady) { val params = SkuDetailsParams .newBuilder() .setSkusList(skuList) .setTyp

我遵循以下文档来实现google pay:

运行此功能并购买产品后:

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")
    }
}
这很好,我想知道是否已经进行了采购,因此我从代码中添加了以下代码:

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.
    }
}
什么鬼东西??在完成purchage后如何调用这个该死的函数?

我找到了解决方案

您需要使活动/片段使用
PurchasesUpdatedListener
如下:

class VIP : AppCompatActivity(), PurchasesUpdatedListener {

}
然后覆盖将起作用

class VIP : AppCompatActivity(), PurchasesUpdatedListener {

}