How to check purchase state of subscription in all new Play Billing Library?

亡梦爱人 提交于 2019-12-03 09:07:20

Once the subscription is expired it will no longer be in the list of Purchases. Some documentation

This is an old question and you may have solved it. I've just started using the new library and I have the same question. Reading the javadoc for the Purchase class I think you have to use:

isAutoRenewing()

This will return false for any subscription that has been cancelled. It returns true for any subscription that is active or is in the grace period.

Just an update to this. This won't work in the case of a subscription that has been cancelled and has not expired.

I found it odd that the above commentators seem to be in disagreement. Further investigation reveals that the two different queries for purchases give different results - something that the javadoc doesn't seem to make clear.

queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS, listener)

will, as its javadoc explains, return everything - including all expired subscriptions. Using this there doesn't seem to be a way to differentiate between active and inactive subscriptions. This returns the history as it currently is on Google servers.

queryPurchases(BillingClient.SkuType.SUBS)

returns only the current active subscriptions. It returns a cached result immediately.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!