【问题标题】:IabHelper: check if subscription is auto renewingIabHelper:检查订阅是否自动续订
【发布时间】:2017-01-04 15:28:10
【问题描述】:

我有一个带有订阅的 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 对象没有请求自动更新字段的方法。有没有其他方法可以获得这些信息?

【问题讨论】:

    标签: android in-app-billing android-billing


    【解决方案1】:

    调用Purchase#isAutoRenewing 方法。如果缺少此方法,您可能需要更新您的参考 IAB 文件:

        if (purchase != null && purchase.getPurchaseState() == 0) {
            // User is subscribed
            Log.d(TAG, "Subscribed.");
            if (purchase.isAutoRenewing()){
                return true;
            }
    

    https://github.com/googlesamples/android-play-billing/blob/master/TrivialDrive/app/src/main/java/com/example/android/trivialdrivesample/util/Purchase.java

    【讨论】:

      猜你喜欢
      • 2017-09-10
      • 2021-12-12
      • 1970-01-01
      • 2016-08-04
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 2011-07-04
      相关资源
      最近更新 更多