代码之家  ›  专栏  ›  技术社区  ›  Schadenfreude

检查用户是否可以通过PlayStore进行应用内计费

  •  1
  • Schadenfreude  · 技术社区  · 8 年前

    因此,我们希望通过谷歌的计费API和支付宝为中国提供应用内计费支持。我已经写了一个方法,它应该返回一个GooglePlay或者一个支付宝计费客户端(以可用的为准)。我需要一种方法来确定谷歌的计费服务是否对用户可用,这样我就知道该返回哪个客户端。

    1. 创建 ServiceConnection IInAppBillingService.Stub.asInterface(service) .isBillingSupported(3, context.packageName, "inapp")

    https://gist.github.com/first087/9088162

    这有点乏味,因为我需要等待服务连接,获得异步结果,然后返回正确的计费管理器,但乍一看似乎正是我需要的。

    1. 使用 GoogleApiAvailability isGooglePlayServicesAvailable(context)

    com.google.android.gms:play-services-base 库到我的项目。

    1. 检查设备上是否安装了GooglePlay应用程序。


    有没有人有过类似的经历?如何正确确定用户是否可以通过PlayStore进行购买?

    1 回复  |  直到 8 年前
        1
  •  4
  •   Schadenfreude    8 年前

    因此,在中国测试了这些方法之后,我们发现一款手机安装了和未安装PlayStore应用程序的手机:

    与 应用程序已安装并 没有 虚拟专用网

    • GoogleApiAvailability.isGooglePlayServicesAvailable() 2 - ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED
    • IInAppBillingService.isBillingSupported() 返回代码 三 - BillingResponse.BILLING_UNAVAILABLE

    没有 游戏商店 应用程序已安装并 虚拟专用网

    • GooglePayAvailability.isGooglePlayServicesAvailable() 返回代码 ConnectionResult.SERVICE_INVALID
    • IInAppBillingService.isBillingSupported() 三 BillingResponse.BILLING\u不可用

    与 游戏商店 应用程序已安装并 虚拟专用网

    • 返回代码 0 - ConnectionResult.SUCCESS
    • 返回代码 三 BillingResponse.BILLING\u不可用

    结论 :最安全的方法是通过 isBillingSupported() BillingClient 等待它的 startConnection()

    gist 我写的coroutine提供了BillingManager的两种实现之一,这取决于是否可以通过PlayStore进行应用内计费。

    推荐文章