获取有效订阅应用内结算 Android

Get active subscriptions In-app Billing Android

我已使用应用内结算库在我的应用中添加订阅。一切正常,但我无法找到如何获得用户当前有效订阅?

根据 docs,方法 queryPurchaseHistoryAsync returns 用户为每个 SKU 进行的最近一次购买,即使该购买已过期、取消或消耗。因此,我无法知道当前订阅是否有效。

根据this post,如果我们取消订阅,当天仍将被视为有效。但是我在回复中收到了在 15 天前取消的订阅。

如有任何帮助,我们将不胜感激。提前致谢。

一个用户可以随时激活多个订阅。您可以使用 isAutoRenewing 检查订阅是否有效 method.Here 是该方法的文档

Indicates whether the subscription renews automatically. If true, the subscription is active, and will automatically renew on the next billing date. If false, indicates that the user has canceled the subscription. The user has access to subscription content until the next billing date and will lose access at that time unless they re-enable automatic renewal (or manually renew, as described in Manual Renewal). If you offer a grace period, this value remains set to true for all subscriptions, as long as the grace period has not lapsed. The next billing date is extended dynamically every day until the end of the grace period or until the user fixes their payment method.

要查询用户订阅,我使用这种方法:

public void querySubscriptions() {
    Runnable queryToExecute = () -> {
        Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);

        if (mBillingClient == null ||
                purchasesResult.getResponseCode() != BillingClient.BillingResponse.OK) {
            return;
        }
        mPurchases.clear();
        onPurchasesUpdated(BillingClient.BillingResponse.OK, purchasesResult.getPurchasesList());
    };

    executeServiceRequest(queryToExecute);
}

如果您需要更多详细信息,请询问。