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

我是研究僧i 提交于 2019-12-04 15:47:01

问题


Hi am using new Play Billing Library for in app subscriptions. https://developer.android.com/google/play/billing/billing_library.html

Everthing works perfect and am able to subscribe the product. But i didn't find any ways to check the purchase state of subscription. I mean whether it is active or expired.

In the documentation it says : You can then call a variety of methods on the Purchase object to view relevant information about the item, such as its purchase state or time.

But there is no purchase state method in Purchase Object, check link below https://developer.android.com/reference/com/android/billingclient/api/Purchase.html

Take a look at this video too : https://www.youtube.com/watch?v=9chvh1WYCvw&feature=youtu.be&t=301

How is it possible to check the purchase state?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/48041120/how-to-check-purchase-state-of-subscription-in-all-new-play-billing-library

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