0

我正在使用 com.android.billingclient:billing:3.0.1 库。打开应用程序时如何检查用户是否购买了任何产品。所以我想在付款页面打开之前检查一下。

以下方法返回 null:

mBillingClient = BillingClient.newBuilder(getApplicationContext()).enablePendingPurchases().setListener(this).build();

mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
    @Override
    public void onPurchaseHistoryResponse(@NonNull BillingResult billingResult, @Nullable List<PurchaseHistoryRecord> list) {
        list.size();
    }
});
4

1 回答 1

0

您可以使用GetPurchasesHistory方法来获取购买的物品。这对我来说非常有用。所以你可以使用它:)

public void GetPurchasesHistory(String skuType){
      Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(skuType);
      List<Purchase> purchases = purchasesResult.getPurchasesList();
      List<String> listOfJsons = new ArrayList<>();
      List<String> listOfSkus = new ArrayList<>();
      List<String> orderIds = new ArrayList<>();
      if(purchasesResult.getBillingResult().getResponseCode() == BillingClient.BillingResponseCode.OK){
          if(purchases != null){
              for(Purchase purchase : purchases){
                  listOfJsons.add(purchase.getOriginalJson());
                  listOfSkus.add(purchase.getSkus().get(0));
                  orderIds.add(purchase.getOrderId());
              }
              // You got purchases history, Do what you wanted

          }else{
            // Failed as purchase is null
          }
      }else{
        // FailedToGetPurchasesHistory("Failed, ResponseCode = " + purchasesResult.getBillingResult().getResponseCode());
      }
  }
于 2021-11-23T07:41:11.320 回答