问题描述
IabHelper的QueryInventoryFinishedListener尚未返回过期的订阅项目.
QueryInventoryFinishedListener of IabHelper has not returned the expired subscription items.
另一方面,Google Play帐单库的PurchaseHistoryResponseListener似乎收到了所有购买的物品,其中包括过期的物品.
On the other hand, PurchaseHistoryResponseListener of Google Play Billing Library seems to receive all purchased items, which is including expired items.
在Google Play结算库中,我们必须检查PurchaseHistoryResponseListener的购买日期以及商品的每个到期日期?
On Google Play Billing Library, we have to check the purchased date of PurchaseHistoryResponseListener and each expiration date of items?
推荐答案
queryPurchases与queryPurchaseHistoryAsync
通常,我们应该使用queryPurchases(String skuType)
,它不会返回过期的项目. queryPurchaseHistoryAsync返回启用和禁用的项目,如您所见,如下所示.
queryPurchases vs queryPurchaseHistoryAsync
Generally, we should use queryPurchases(String skuType)
, which does not returns expired items. queryPurchaseHistoryAsync returns enabled and disabled items, as you see the documentation like following.
关于queryPurchaseHistoryAsync
我无法显示出queryPurchaseHistoryAsync的用例.如果需要使用queryPurchaseHistoryAsync,则需要实现检查其是否过期.
About queryPurchaseHistoryAsync
I could not image the use case for queryPurchaseHistoryAsync. If we need to use queryPurchaseHistoryAsync, we need the implementation to check if it is expired or not.
private PurchaseHistoryResponseListener listener = new PurchaseHistoryResponseListener() {
@Override
public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
for (Purchase purchase : purchasesList) {
if (purchase.getSku().equals("sku_id")) {
long purchaseTime = purchase.getPurchaseTime();
// boolean expired = purchaseTime + period < now
}
}
}
};
购买对象没有期间的信息,因此上述期间必须从BillingClient.querySkuDetailsAsync获取或进行硬编码.以下是使用querySkuDetailsAsync的示例实现.
Purchase object does not have the information of period, so the above period must be acquired from BillingClient.querySkuDetailsAsync or be hard-coded. The following is sample implementation to use querySkuDetailsAsync.
List<String> skuList = new ArrayList<>();
skuList.add("sku_id");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.SUBS);
billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
if (skuDetailsList == null) {
return;
}
for (SkuDetails skuDetail : skuDetailsList) {
if (skuDetail.getSku().equals("sku_id")) {
String period = skuDetail.getSubscriptionPeriod();
}
}
}
});
这篇关于如何检查订阅项目的到期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!