简体   繁体   English

在 Android 中检查应用内订阅的状态

[英]Check the status of In-App Subscription in Android

I have created an application in which there is in-app purchases which has monthly auto renewal.. on first time successful payment i have called a web-service in which i have made the user to premium class.我创建了一个应用程序,其中有应用程序内购买,每月自动续订.. 在第一次成功付款时,我调用了一个网络服务,我已经让用户进入高级课程。

Now if the user has cancelled the payment manually from the google server, how could i know that user has cancelled his/her subscription.现在如果用户从谷歌服务器手动取消付款,我怎么知道用户已经取消了他/她的订阅。

Is there is some PHP code query or from android i have to called something in background to check the status??是否有一些 PHP 代码查询或来自 android 我必须在后台调用一些东西来检查状态?

Thank you in advace提前谢谢你

I haven't tested this, but could you use the autoRenewing field in INAPP_PURCHASE_DATA?我还没有测试过这个,但是你可以使用autoRenewing中的autoRenewing字段吗?

If true, the subscription is active, and will automatically renew on the next billing date.如果为 true,则订阅处于活动状态,并将在下一个计费日期自动续订。 If false, indicates that the user has canceled the subscription .如果为 false,则表示用户已取消订阅

http://developer.android.com/google/play/billing/billing_reference.html#getBuyIntent http://developer.android.com/google/play/billing/billing_reference.html#getBuyIntent

Apparently, the autoRenewing field was added or at least documented in the beginning of 2015 .显然,在2015 年初添加或至少记录了autoRenewing字段。

You can check the purchased subscriptions inside the app via您可以通过以下方式检查应用程序内购买的订阅

Edit: For subscriptions use "subs", for inapp-purchases use "inapp" eg:编辑:对于订阅使用“subs”,对于 inapp-purchase 使用“inapp”,例如:

Inapp-Purchases: mService.getPurchases(3, getPackageName(), "inapp", null); Inapp-Purchases: mService.getPurchases(3, getPackageName(), "inapp", null);

Subscriptions: mService.getPurchases(3, getPackageName(), "subs", null);订阅: mService.getPurchases(3, getPackageName(), "subs", null);

See also Querying for Purchased Items at http://developer.android.com/google/play/billing/billing_integrate.html另请参阅在http://developer.android.com/google/play/billing/billing_integrate.html Querying for Purchased Items

So you can implement a task in your app where you check if the user still has a subscription.因此,您可以在您的应用程序中实施一项任务,您可以在其中检查用户是否仍有订阅。 If not, you can remove the premium status.如果没有,您可以删除高级状态。 Moreover this information could be useful for you:此外,这些信息可能对您有用:

When the user cancels a subscription, Google Play does not offer a refund for the current billing cycle.当用户取消订阅时,Google Play 不会提供当前计费周期的退款。 Instead, it allows the user to have access to the canceled subscription until the end of the current billing cycle, at which time it terminates the subscription.相反,它允许用户在当前计费周期结束之前访问已取消的订阅,届时它会终止订阅。 For example, if a user purchases a monthly subscription and cancels it on the 15th day of the cycle, Google Play will consider the subscription valid until the end of the 30th day (or other day, depending on the month).例如,如果用户购买了月度订阅并在周期的第 15 天取消,Google Play 会认为订阅有效期至第 30 天(或其他日期,取决于月份)。

source: http://developer.android.com/google/play/billing/billing_subscriptions.html under subscription cancelled来源: http : //developer.android.com/google/play/billing/billing_subscriptions.html subscription cancelled

Hope this could help you希望这可以帮助你

Edit2: Because the AIDL library which is mentioned in my answer is deprecated and deactivated in the future, it is recommended to switch to the new Google Play Billing Library . Edit2:因为我的回答中提到的AIDL库在以后被弃用和停用,建议切换到新的Google Play Billing Library

Check the getPurchases() method here .此处检查 getPurchases() 方法。 Or if you use Android Studio and have the source code downloaded just press Ctrl + Q on IInAppBillingService.getPurchases method或者,如果您使用 Android Studio 并下载了源代码,只需在IInAppBillingService.getPurchases方法上按Ctrl + Q

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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