gpt4 book ai didi

android - 如何处理 BillingClient.onBillingServiceDisconnected()?

转载 作者:行者123 更新时间:2023-12-03 09:32:49 28 4
gpt4 key购买 nike

最近,我将我的一个应用程序迁移到了 Google Play In-App Billing v3。自发布以来,我收到了一些关于 的崩溃报告。仅限三星设备 ,都与BillingClient.onBillingServiceDisconnected()相关被调用。
当前代码如下所示:

val billingClient = BillingClient.newBuilder(context)
.setListener(updatedListener)
.enablePendingPurchases()
.build()

billingClient.startConnection(
object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
// The billing client is ready. You can query purchases here.
querySkuDetails()
}
}

override fun onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
initBilling() // all code here is wrapped in this method
}
}
)
我显然重新初始化了 BillingClient并调用 startConnection()再次在错误情况下。那么崩溃是
java.lang.IllegalStateException: 
at android.os.Parcel.createException (Parcel.java:2096)
at android.os.Parcel.readException (Parcel.java:2056)
at android.os.Parcel.readException (Parcel.java:2004)
at android.app.IActivityManager$Stub$Proxy.registerReceiver (IActivityManager.java:5557)
at android.app.ContextImpl.registerReceiverInternal (ContextImpl.java:1589)
at android.app.ContextImpl.registerReceiver (ContextImpl.java:1550)
at android.app.ContextImpl.registerReceiver (ContextImpl.java:1538)
at android.content.ContextWrapper.registerReceiver (ContextWrapper.java:641)
at com.android.billingclient.api.zze.zza (zze.java:5)
at com.android.billingclient.api.zzd.zza (zzd.java:5)
at com.android.billingclient.api.BillingClientImpl.startConnection (BillingClientImpl.java:58)
at de.memorian.gzg.presentation.base.IAPHelper.initBilling (IAPHelper.java:40)
at de.memorian.gzg.presentation.base.IAPHelper$initBilling$1.onBillingServiceDisconnected (IAPHelper.java:53)
at com.android.billingclient.api.BillingClientImpl$zza.onServiceDisconnected (BillingClientImpl.java:11)
at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:2060)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:2099)
at android.os.Handler.handleCallback (Handler.java:883)
at android.os.Handler.dispatchMessage (Handler.java:100)
at android.os.Looper.loop (Looper.java:237)
at android.app.ActivityThread.main (ActivityThread.java:7857)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1076)
Caused by: android.os.RemoteException:
at com.android.server.am.ActivityManagerService.registerReceiver (ActivityManagerService.java:16726)
at android.app.IActivityManager$Stub.onTransact (IActivityManager.java:2250)
at com.android.server.am.ActivityManagerService.onTransact (ActivityManagerService.java:3357)
at android.os.Binder.execTransactInternal (Binder.java:1021)
at android.os.Binder.execTransact (Binder.java:994)
我想知道我在 onBillingServiceDisconnected() 中做错了什么,所以我用谷歌搜索了一段时间,但没有找到任何明确的建议,但 // implement your own retry logic .那是例如什么 Google说。这里的重试逻辑到底是什么?正如您在调用 startConnection() 的堆栈跟踪中看到的那样正如谷歌评论所建议的那样,再次导致崩溃。 Here Google 说我应该忽略它,因为 Play Services 会调用 onBillingSetupFinished()最终,后来。
你如何处理这个案子?

最佳答案

没有找到关于如何处理失败案例的问题的具体答案。我重构了我的代码,所以我基本上忽略了对 onBillingServiceDisconnected() 的调用并且只向用户显示错误消息。
现在,每次尝试购买的电话都会检查是否

  • BillingClient已初始化
  • BilligClientready
  • Sku详情不为空

  • 只有在这些成功之后才尝试进行购买。
    以前我在应用程序初始化上完成了上述所有操作。如果连接失败,现在,我将在用户再次单击购买项目时重试(使用 try catch)。这可能无法解决崩溃问题,但至少可以为用户提供更好的体验和控制。

    关于android - 如何处理 BillingClient.onBillingServiceDisconnected()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63313049/

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