我正在尝试从购买中获取产品 ID:
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
?这是一个错误吗?怎么解决这个问题?
正如Purchase
类中的
Android开发人员文档中所写,您应该能够从
getProducts()
方法获取产品ID。
它的返回类型是List<String>
。
我对产品库不是很熟悉,所以我假设购买可以由多个产品代表。您可能应该迭代列表并将您的
when
运算符放入某种循环中。