android - 我可以通过 Android App 中的 Google Play 一次购买多件商品吗?
问题描述
在我看来,我一次只能在 Google App 中购买一件商品。
代码 A 来自项目 play-billing-samples,您可以在此处查看。
purchases: MutableList<Purchase>
可能存在多个项目,我似乎可以通过Google Play同时购买这些项目,对吧?
代码 A
override fun onPurchasesUpdated(
billingResult: BillingResult,
purchases: MutableList<Purchase>?
) {
when (billingResult.responseCode) {
BillingClient.BillingResponseCode.OK -> {
// will handle server verification, consumables, and updating the local cache
purchases?.apply { processPurchases(this.toSet()) }
}
BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> {
// item already owned? call queryPurchasesAsync to verify and process all such items
Log.d(LOG_TAG, billingResult.debugMessage)
queryPurchasesAsync()
}
BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> {
connectToPlayBillingService()
}
else -> {
Log.i(LOG_TAG, billingResult.debugMessage)
}
}
}
解决方案
用户只能拥有相同的应用内商品一次,但他可以同时拥有不同的商品。
其他解决方案是将物品视为消耗品:
如果billingClient.consumeAsync()
在购买过程结束时被调用,那么他可以再次购买相同的物品,但是您必须通过自己的方式(可能通过后端服务器)跟踪他购买了多少次。
推荐阅读
- c# - 在 Net5 Api 中返回 HttpResponseMessage
- docker - 如何在不杀死 GitLab 运行器的情况下杀死进程?
- javascript - 如何使用 jQuery 按字母顺序对 HTML 中的列表进行排序?
- apache - Apache 2.4 将不带斜杠的目录 URL 重写为 https://default_site/dir/ 而不是保留域
- android - Kotlin Flow - 有什么类似于 LiveData 的 emitSource 的吗?
- c++ - 我的 if 语句没有正确执行(跳过 if)
- reactjs - 如何绑定到挂钩中引发的事件?
- css - 使用转换时结合旋转和翻译时的 Safari 错误
- python - 如何将 Pandas qcut 或类似函数应用于二维数组
- angular - 如何处理 RxJs websocket 连接关闭?在服务器关闭时重试,在客户端关闭时不执行任何操作