简体   繁体   中英

Get active subscriptions In-app Billing Android

I have used the In-app billing library for adding subscriptions in my app. Everything is working properly but I am unable to find how do I get a Users current active subscription?

As per the docs , the method queryPurchaseHistoryAsync returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed. Due to this, I am unable to know whether a current subscription is active or not.

According to this post, if we cancel the subscription, it will still be considered active for that day. But I am getting the subscriptions in the response which were canceled before 15 days.

Any help will be appreciated. Thanks in advance.

To query users subscription i use this 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);
}

If you need more details, ask.

A user can have multiple subscriptions active at any moment. You can check whether the subscription is active or not using isAutoRenewing method.Here is the docs for that method

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM