简体   繁体   English

在我的应用程序运行时收听 PURCHASES_UPDATED 以获取兑换促销代码

[英]Listen for PURCHASES_UPDATED for redeem promo codes while my app is running

I'm reading in-app promotions documentation to allow users to redeem promo codes.我正在阅读应用内促销文档以允许用户兑换促销代码。 The docs say we need to cover the case when a user redeems a promo code in Play Store app while our app is running. 文档说我们需要涵盖用户在我们的应用程序运行时在 Play 商店应用程序中兑换促销代码的情况。 This is done by listening for PURCHASES_UPDATED intent.这是通过侦听 PURCHASES_UPDATED 意图来完成的。

The docs say we have to register the broadcast receiver (for PURCHASES_UPDATED) in activity's onResume() method. 文档说我们必须在活动的 onResume() 方法中注册广播接收器(用于 PURCHASES_UPDATED)。 And unregister it in onPause().并在 onPause() 中注销它。

But, if my app is open, and the user opens Play Store app, my app activity's onPause method will be executed, so the broadcast receiver will be unregistered, and my app won't be notified...但是,如果我的应用程序打开,并且用户打开 Play Store 应用程序,我的应用程序活动的 onPause 方法将被执行,因此广播接收器将被取消注册,我的应用程序将不会收到通知......

Are the docs incorrect?文档不正确吗? Or am I missing something?或者我错过了什么?

Several cases may apply here.这里可能适用几种情况。

First, there are Android devices that can run multiple activities in the foreground, or you may be buying the content on a separate device with the same account.首先,有些 Android 设备可以在前台运行多个活动,或者您可能会在具有相同帐户的单独设备上购买内容。 In these cases, your receiver will do just what it's supposed to do.在这些情况下,您的接收器会做它应该做的事情。

Second, in the more usual case, yes, you will have a problem and have to check for purchases in onResume() additionally, as your receiver will not fire while the app was closed.其次,在更常见的情况下,是的,您会遇到问题,并且必须另外检查 onResume() 中的购买情况,因为在应用程序关闭时您的接收器不会触发。 Since you should already be checking this in onStart(), because your app wants to know what the pruchased items are on startup, you may want to consider just moving that check.由于您应该已经在 onStart() 中检查了这一点,因为您的应用程序想知道启动时购买的项目是什么,您可能需要考虑只移动该检查。

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

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