我正在尝试创建一个恢复购买系统。我想要,用户可以在他/她登录的任何设备上访问其购买的产品。所以我在应用程序启动时使用“queryPurchaseHistoryAsync()”方法。我的问题从这里开始。
随着谷歌的新实现,与文档相反,queryPurchaseHistoryAsync() 参数发生了变化。现在它将 PurchaseHistoryRecord 对象列表作为参数,而不是 Purchase 对象列表。
Android studio 无法解决文档中所述的方法。使用新的 queryPurchaseHistoryAsync() 我无论如何都找不到检查购买状态。(如果它已购买、取消或待处理)。我可以使用“purchase.getPurchaseState()”方法来处理购买对象。
queryPurchaseHistoryAsync() 的文档
billingClient.queryPurchaseHistoryAsync(SkuType.INAPP,
new PurchaseHistoryResponseListener() {
@Override
public void onPurchaseHistoryResponse(BillingResult billingResult,
List<Purchase> purchasesList) {
if (billingResult.getResponseCode() == BillingResponse.OK
&& purchasesList != null) {
for (Purchase purchase : purchasesList) {
// Process the result.
}
}
}
});
我的实现
implementation 'com.android.billingclient:billing:2.0.3'
我的应用程序中的 queryPurchaseHistoryAsync() 方法
billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP,
new PurchaseHistoryResponseListener() {
@Override
public void onPurchaseHistoryResponse(BillingResult billingResult, List<PurchaseHistoryRecord> purchaseHistoryRecordList) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
&& purchaseHistoryRecordList != null) {
for (PurchaseHistoryRecord purchaseHistoryRecord : purchaseHistoryRecordList) {
HandleOldGetting(purchaseHistoryRecord.getSku());
}
}
}
谷歌发布说明(05-2019):
“为了最大程度地减少混淆,queryPurchaseHistoryAsync() 现在返回 PurchaseHistoryRecord 对象而不是 Purchase 对象。PurchaseHistoryRecord 对象与 Purchase 对象相同,只是它仅反映 queryPurchaseHistoryAsync() 返回的值并且不包含 autoRenewing、orderId , 和 packageName 字段。请注意,返回的数据没有任何变化——queryPurchaseHistoryAsync() 返回的数据与以前相同。”
但发行说明和文档都没有说明如何使用 PurchaseHistoryRecord 检查购买状态。
感谢您阅读本文,感谢您的帮助。