我目前正在使用 In App Billing Library 在 App Purchase 中实现,

使用方法消费购买的物品后:

mBillingClient.consumeAsync(purchaseToken, new ConsumeResponseListener() {
                @Override
                public void onConsumeResponse(int responseCode, String purchaseToken) {
                    if (responseCode == BillingClient.BillingResponse.OK) {
                        Toast.makeText(getApplicationContext(), "Item Consumed Successfully..." + purchaseToken, Toast.LENGTH_LONG).show();
                    }
                }
            });
            break;

当我再次打开应用程序并想使用方法检索购买列表的列表时:
mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
        @Override
        public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
            if (responseCode == BillingClient.BillingResponse.OK) {
                purchases = purchasesList;
                retrieveItemList();
            }
        }
    });

它还为我提供了我在列表中消耗的项目。所以,帮我找出我做错了什么以获得更新的采购 list 。
谢谢。

最佳答案

您只需要使用 queryPurchase 方法而不是 queryPurchaseHistoryAsync ,如下所示:

mBillingClient.queryPurchase(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
    @Override
    public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
        if (responseCode == BillingClient.BillingResponse.OK) {
            purchases = purchasesList;
            retrieveItemList();
        }
    }
});

两种方法的区别在于 queryPurchaseHistoryAync 会为你提供你一生中购买过的所有物品的列表,即使是在购买的物品被使用之后;而 queryPurchase 将为您提供当前购买的物品列表。

10-07 19:33
查看更多