【发布时间】:2022-10-07 08:33:10
【问题描述】:
在我的项目中,我正在尝试集成新版本(5.0)的谷歌计费库,我正在关注谷歌示例
https://codelabs.developers.google.com/play-billing-codelab#3
例如,有两个功能:
fun queryPurchases() {
if (!billingClient.isReady) {
Log.e(TAG, \"queryPurchases: BillingClient is not ready\")
}
// Query for existing subscription products that have been purchased.
billingClient.queryPurchasesAsync(
QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.SUBS).build()
) { billingResult, purchaseList ->
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
if (!purchaseList.isNullOrEmpty()) {
_purchases.value = purchaseList
} else {
_purchases.value = emptyList()
}
} else {
Log.e(TAG, billingResult.debugMessage)
}
}
}
应该返回purchases that the user has previously made,另一个函数是
fun queryProductDetails() {
val params = QueryProductDetailsParams.newBuilder()
val productList = mutableListOf<QueryProductDetailsParams.Product>()
for (product in LIST_OF_PRODUCTS) {
productList.add(
QueryProductDetailsParams.Product.newBuilder()
.setProductId(product)
.setProductType(BillingClient.ProductType.SUBS)
.build()
)
params.setProductList(productList).let { productDetailsParams ->
Log.i(TAG, \"queryProductDetailsAsync\")
billingClient.queryProductDetailsAsync(productDetailsParams.build(), this)
}
}
}
结果,我希望得到available products,但是,这两个函数返回空列表。
我知道这些产品和之前的新 lib 版本一样存在,我使用了前一个 4.x.x 并且它有效。
我在这里想念什么?任何建议表示赞赏。
-
对于
queryPurchasesAsync,您确定有订阅产品吗?您将BillingClient.ProductType.SUBS作为产品类型传入。也许这应该是BillingClient.ProductType.INAPP?
标签: android