【问题标题】:Managing Google Play subscriptions not working管理 Google Play 订阅不起作用
【发布时间】:2019-07-14 12:42:20
【问题描述】:

我的应用有应用内订阅购买,但我对整个实施过程感到非常困惑。

当应用程序打开时,我打电话给onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) 以检查用户是否有任何活跃的购买。如果购买列表为空,则应用假定用户没有购买任何东西。

稍后当用户决定购买应用调用的东西时:

mBillingClient = BillingClient.newBuilder(view.getContext()).setListener(new PurchasesUpdatedListener()

一旦再次购买 onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) 就会被调用,但是,一旦我重新打开应用程序就什么都没有了,一切都恢复正常(免费版),就像用户什么都没买一样。

此外,用户购买数据并未存储在云端(firebase 实时数据库)。已经有 3 位用户进行了购买,并且处于三天试用期。

【问题讨论】:

    标签: android in-app-billing android-billing


    【解决方案1】:

    你看过the sample on GitHub吗?当用户打开您的应用程序时,您应该致电queryPurchases。这是一个例子:

    fun queryPurchasesAsync() {
            Log.d(LOG_TAG, "queryPurchasesAsync called")
            val purchasesResult = HashSet<Purchase>()
            var result = playStoreBillingClient.queryPurchases(BillingClient.SkuType.INAPP)
            Log.d(LOG_TAG, "queryPurchasesAsync INAPP results: ${result?.purchasesList?.size}")
            result?.purchasesList?.apply { purchasesResult.addAll(this) }
            if (isSubscriptionSupported()) {
                result = playStoreBillingClient.queryPurchases(BillingClient.SkuType.SUBS)
                result?.purchasesList?.apply { purchasesResult.addAll(this) }
                Log.d(LOG_TAG, "queryPurchasesAsync SUBS results: ${result?.purchasesList?.size}")
            }
            processPurchases(purchasesResult)
        }
    

    您应该在与 BillingClient 服务建立连接后立即进行此调用:

    /**
         * This is the callback for when connection to the Play [BillingClient] has been successfully
         * established. It might make sense to get [SkuDetails] and [Purchases][Purchase] at this point.
         */
        override fun onBillingSetupFinished(billingResult: BillingResult) {
            when (billingResult.responseCode) {
                BillingClient.BillingResponseCode.OK -> {
                    Log.d(LOG_TAG, "onBillingSetupFinished successfully")
                    querySkuDetailsAsync(BillingClient.SkuType.INAPP, GameSku.INAPP_SKUS)
                    querySkuDetailsAsync(BillingClient.SkuType.SUBS, GameSku.SUBS_SKUS)
                    queryPurchasesAsync()
                }
                BillingClient.BillingResponseCode.BILLING_UNAVAILABLE -> {
                    //Some apps may choose to make decisions based on this knowledge.
                    Log.d(LOG_TAG, billingResult.debugMessage)
                }
                else -> {
                    //do nothing. Someone else will connect it through retry policy.
                    //May choose to send to server though
                    Log.d(LOG_TAG, billingResult.debugMessage)
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2016-04-27
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 2018-06-09
      • 2021-10-02
      • 2019-03-17
      • 1970-01-01
      相关资源
      最近更新 更多