onPurchasesUpdated 中的购买列表

List of purchases in onPurchasesUpdated

我是第一次实施应用内结算,所以我对新的购买有点困惑。

作为Documentation states:

When you call launchBillingFlow() the Google Play UI purchase screen displays. If the purchase order is successful, the response data from Google Play is stored in a Purchase object that is passed back to the appropriate listener. Google Play then calls the onPurchasesUpdated() method to deliver the result of a purchase order to a listener that implements the PurchasesUpdatedListener interface.

onPurchasesUpdated()方法的签名是这样的:

void onPurchasesUpdated(@BillingResponse int responseCode, @Nullable List<Purchase> purchases);

我的问题:onPurchasesUpdated() 方法是否会提供迄今为止在我的应用程序中发起的 所有 购买的列表,还是 仅最新的 发起购买?

如果它交付所有购买,我如何找出最近发起的购买?

正如您提供的文档中所述,该方法提供最新 Purchase 对象的列表,这些对象在您的应用或 Play 商店中启动。

(...) Both purchases initiated by your app and the ones initiated by Play Store will be reported here.

如果您查看 Purchase class docs, you can see that there's a method called getPurchaseTime(),您可以使用它来检查购买的时间。这些信息足以追踪哪一个是最近购买的。

但您也可以使用 class 上的其他方法来跟踪购买情况,例如 getOrderId()

但如果您想查看用户在您的应用上进行的所有购买,而不仅仅是最近的购买,请查看培训指南的 queryPurchases() method, and take a look at the Query purchased items 部分。