我正在尝试从购买中获取productId:
private fun queryPurchases(purchases: List<Purchase>){
for (purchase in purchases) {
Log.d("pikaboo", purchase.toString())
when (purchase.purchaseState) {
Purchase.PurchaseState.PURCHASED -> {
val purchaseTime = (purchase.purchaseTime / 1000).toInt()
when (purchase.productId) {
"no_ads_in_app_month" -> {
}
"no_ads_in_app_3_months" -> {
}
}
}
}
}
}
这是日志:
Purchase. Json: {"orderId":"GPA.333.333.333","packageName":"de.bla.foo","productId":"no_ads_in_app_3_months","purchaseTime":1694810217354,"purchaseState":0,"purchaseToken":"xxxxxxxxxxxx","quantity":1,"acknowledged":true}
在是productId
_purchase.productId
Unresolved reference
其他一切都像purchase.purchaseTime
purchase.purchaseState
purchase.packageName
作品一样。
为什么不呢purchase.productId
?这是一个错误吗?怎么解决这个问题呢?
正如Android 开发者文档中关于类的内容所写
Purchase
,您应该能够从getProducts()
方法中获取产品 id。它的返回类型是List<String>
.我对计费库不是很熟悉,所以我假设购买可以由多种产品代表。您可能应该迭代列表并将
when
运算符置于某种循环中。