gpt4 book ai didi

java - 你应该在 `onBillingServiceDisconnected()` 里放什么?

转载 作者:行者123 更新时间:2023-12-04 23:42:20 28 4
gpt4 key购买 nike

这是我得到的方法:

public void setupBillingClient() { //connect to google play

billingClient = BillingClient.newBuilder(context)
.enablePendingPurchases()
.setListener(this)
.build();

billingClient.startConnection(new BillingClientStateListener() {

@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
//The BillingClient is setup successfully
loadAllSkus();
}
}

@Override
public void onBillingServiceDisconnected() {
//TODO: implement retry logic to handle lost connections to Google Play by calling startConnection() again
}
});
}
谷歌说我应该“实现重试逻辑”,但没有说如何。我想也许只是调用 setupBillingClient()里面 onBillingServiceDisconnected()但有人说这会导致崩溃。另外我觉得如果它是那么简单,那么谷歌会告诉我们写那个而不是模糊的指令来实现重试逻辑。

最佳答案

我也遇到了这个问题。关于这个的谷歌文档只是一团糟(好吧,就像 API 本身一样)。
所以,here谷歌说

To implement retry logic, override the onBillingServiceDisconnected()callback method, and make sure that the BillingClient calls thestartConnection() method to reconnect to Google Play before makingfurther requests.


这意味着在断开连接后我们必须调用 startConnection手动。
但是 here谷歌说

Called to notify that the connection to the billing service was lost.

Note: This does not remove the billing service connection itself -this binding to the service will remain active, and you will receive acall to onBillingSetupFinished(BillingResult) when the billing serviceis next running and setup is complete.


在我看来,这与前面的说法完全矛盾。
根据我在计费库方面的经验,我相信最后一种说法更有可能是正确的。不过,我不是 100% 确定。
但我可以确认我在 logcat 中看到了一条断开连接的消息,然后是另一条表明计费客户端已准备就绪的消息。我没有做任何重启 Action 。另外,如果我尝试 startConnection在断开回调中,我开始在每次连接/断开时在 logcat 中收到两条消息。
基于此,我可以说:
  • 你可以去here然后点击页面底部的“没有帮助”。或在 Twitter 上标记他们,或在他们的跟踪器上创建问题。
  • 我们正在讨论的重试逻辑不是连接重试。即将重试我们尝试使用计费客户端执行的操作,但由于已断开连接而无法正常工作。
  • 关于java - 你应该在 `onBillingServiceDisconnected()` 里放什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64247870/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com