【问题标题】:Google play billing purchase result shows empty list after a successful purchase in the google play billing library (Native android)谷歌play计费购买结果在google play计费库中购买成功后显示空列表(原生android)
【发布时间】:2021-10-07 18:29:55
【问题描述】:

Google play billing 购买结果在 google play billing library 中购买成功后显示为空列表。

购买产品时,它会按预期返回列表。导航到两个屏幕后,如果我再次检查首选购买屏幕,则同一应用的购买列表为空。

为什么导航到屏幕后购买列表为空?

 if (billingClient.isReady()) {
                Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
                List<Purchase> purchases = purchasesResult.getPurchasesList();
               
                if (purchases.size() > 0) {
                    for (Purchase pur : purchases) {
                        String thisSku = pur.getSkus().get(0);
                        if (thisSku.equals(AD_REMOVAL_SKU)) {
                            return true;
                        }
                    }
                } 

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

 private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
        @Override
        public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> list) {
            // To be implemented in a later section.
            LogUtils.LOGI(TAG, "billingResult on billingResult" + billingResult.getResponseCode());
            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && list != null) {
              
                Toast.makeText(context.getApplicationContext(), list.toString(), Toast.LENGTH_LONG).show();
                Toast.makeText(context.getApplicationContext(), billingResult.toString(), Toast.LENGTH_LONG).show();
                Purchase info = list.get(0);
              
                for (Purchase purchase : list) {
                    Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
                 
                    if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
                        if (info.getSkus().get(0).equals(AdsRemovalHelper.SKU)) {
                            ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
                            LogUtils.LOGI(TAG, "Consume params ===" + consumeParams);
                            billingClient.consumeAsync(consumeParams, new ConsumeResponseListener() {
                                @Override
                                public void onConsumeResponse(BillingResult billingResult, String s) {
                                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK ) {
                                        LogUtils.LOGI(TAG, "Consume String ===" + consumeParams);
                                        Toast.makeText(context.getApplicationContext(), purchase.getSkus().toString(), Toast.LENGTH_LONG).show();
                                    }
                                }
                            });
                          
                        }
                    } else if (purchase.getPurchaseState() == Purchase.PurchaseState.PENDING) {
                         LogUtils.LOGI(TAG, "ConsumeString ===" );
                    } else if (purchase.getPurchaseState() == Purchase.PurchaseState.UNSPECIFIED_STATE) {
                          LogUtils.LOGI(TAG, "Consume S11111tring ===" );
                    }

} }

【问题讨论】:

  • 我遇到了同样的问题,但在任何地方都找不到解决方法。您是否找到了解决方案或某种方式从这种情况中优雅地恢复?

标签: android in-app-purchase


【解决方案1】:

由于 queryPurchases 已被弃用,如果您使用的是 Billing 4.0 API,请尝试使用 queryPurchasesAsync。 https://developer.android.com/reference/com/android/billingclient/api/BillingClient#queryPurchases(java.lang.String)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    • 2021-01-17
    • 1970-01-01
    • 2021-05-06
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多