我有一个带有订阅的Android应用,我使用IabHelper
来查询用户是否有有效订阅。现在我还需要知道此订阅是否自动续订。
我正在查询订阅状态:
private boolean userIsSubscribed() {
ArrayList<String> skuList = new ArrayList<>();
skuList.add(PREMIUM_SUBSCRIPTION);
// Check the subscription status
try {
Inventory inventory = iabHelper.queryInventory(true, null, skuList);
Purchase purchase = inventory.getPurchase(PREMIUM_SUBSCRIPTION);
// Is the user subscribed?
if (purchase != null && purchase.getPurchaseState() == 0) {
// User is subscribed
Log.d(TAG, "Subscribed.");
// TODO check if subscription is auto-renewing
return true;
} else {
// User is not subscribed
Log.d(TAG, "Not subscribed.");
return false;
}
} catch (IabException | NullPointerException e) {
// There was an error with the subscription process
Log.e(TAG, e.getMessage(), e);
return false;
} catch (IllegalStateException e) {
// IabHelper not set up
Log.e(TAG, e.getMessage(), e);
return false;
}
}
遗憾的是,Purchase
对象没有请求autoRenewal字段的方法。有没有其他方法可以获得这些信息?
答案 0 :(得分:2)
调用Purchase#isAutoRenewing
方法。如果缺少此方法,则可能需要更新引用的IAB文件:
if (purchase != null && purchase.getPurchaseState() == 0) {
// User is subscribed
Log.d(TAG, "Subscribed.");
if (purchase.isAutoRenewing()){
return true;
}