You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Billing Library 7版本enablePendingPurchases方法弃用问题咨询

Google Billing Library 7.x 中替代过时的 enablePendingPurchases() 方法的正确方式

首先明确:在 Billing Library 7.x 版本中,无参的 enablePendingPurchases() 方法已被标记为过时,官方推荐使用 enablePurchases(PendingPurchasesParams) 方法来替代。你提供的代码里有个小问题——应该调用 enablePurchases 而非 enablePendingPurchases 来传入参数。

关于 PendingPurchasesParams 的使用

你直接通过 PendingPurchasesParams.newBuilder().build() 创建参数对象的做法是完全可行的:

  • PendingPurchasesParams.Builder 没有强制要求配置的参数,调用 build() 会生成一个使用默认配置的实例,足以覆盖绝大多数常规的应用内购买场景。
  • 如果你的业务需要自定义未决购买的处理逻辑(比如是否自动解析未决购买),可以在 Builder 上添加对应配置,例如:
    PendingPurchasesParams params = PendingPurchasesParams.newBuilder()
        .setAutoResolvePendingPurchases(true)
        .build();
    
    不过默认配置通常已经符合通用需求,无需额外修改。

正确的代码示例

billingClient = BillingClient.newBuilder(Settings.this)
                .setListener(purchasesUpdatedListener)
                .enablePurchases(PendingPurchasesParams.newBuilder().build())
                .build();

额外注意事项

  • 确认你的项目依赖的 Billing Library 版本是 7.0.0 及以上,避免出现方法不存在的编译错误。
  • 替换方法后,原有的购买流程逻辑无需大幅调整,这个改动只是参数传递方式的更新,不会影响核心购买逻辑。

内容的提问来源于stack exchange,提问作者JP711

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 09:42:33