getUserData
和getPurchaseUpdates
。那样行吗?这里的任何人都遇到了这个问题,请先给我您的建议。您可以看到我的以下代码:
我打电话给onCreate:
mIAPManager = new IAPManager(this, this);
PurchasingListener mPurchaseListener = new PurchasingListener(mIAPManager);
PurchasingService.registerListener(this, mPurchaseListener);
在onStart
final Set<String> productSkus = new HashSet<>();
for (final WMSku mySku : WMSku.values()) {
productSkus.add(mySku.getSku());
}
PurchasingService.getProductData(productSkus);
并在onResume中调用它:
mIAPManager.activate();
PurchasingService.getUserData();
PurchasingService.getPurchaseUpdates(false);
这是处理订阅购买的功能,我在这里遇到了例外。
public void handleSubscriptionPurchase(final Receipt receipt, final UserData userData) {
try {
if (receipt.isCanceled()) {
// Check whether this receipt is for an expired or canceled
// subscription
revokeSubscription(receipt, userData.getUserId());
} else {
// We strongly recommend that you verify the receipt on
// server-side.
if (!verifyReceiptFromYourService(receipt.getReceiptId(), userData)) {
// if the purchase cannot be verified,
// show relevant error message to the customer.
mUtils.showMessage("Purchase cannot be verified, please retry later.");
return;
}
grantSubscriptionPurchase(receipt, userData);
}
return;
} catch (final Throwable e) {
mUtils.showMessage("Purchase cannot be completed, please retry");
}
}